calendar

package
v1.9.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 7, 2024 License: MPL-2.0 Imports: 7 Imported by: 2

Documentation

Overview

Package calendar provides a customizable calendar for roleplaying games.

Index

Constants

View Source
const (
	FullFormat   = "%W, %M %D, %Y"
	LongFormat   = "%M %D, %Y"
	MediumFormat = "%m %D, %Y"
	ShortFormat  = "%N/%D/%Y"
)

Predefined formats.

Variables

View Source
var (
	// Default is the default calendar that will be used by Date.UnmarshalText() if the date was not initialized.
	Default = Gregorian()
)

Functions

This section is empty.

Types

type Calendar

type Calendar struct {
	DayZeroWeekDay int       `json:"day_zero_weekday" yaml:"day_zero_weekday"`
	WeekDays       []string  `json:"weekdays"`
	Months         []Month   `json:"months"`
	Seasons        []Season  `json:"seasons"`
	Era            string    `json:"era,omitempty" yaml:",omitempty"`
	PreviousEra    string    `json:"previous_era,omitempty" yaml:"previous_era,omitempty"`
	LeapYear       *LeapYear `json:"leapyear,omitempty" yaml:",omitempty"`
}

Calendar holds the data for the calendar.

func Gregorian

func Gregorian() *Calendar

Gregorian returns a new calendar which mimics the Gregorian calendar, although not precisely, as the real-world calendar has a lot of irregularities to it prior to the 1600's. If you want a more precise real-world calendar, use Go's time.Time instead.

func (*Calendar) Days

func (cal *Calendar) Days(year int) int

Days returns the number of days contained in a specific year.

func (*Calendar) IsLeapMonth

func (cal *Calendar) IsLeapMonth(month int) bool

IsLeapMonth returns true if the month is the leap month.

func (*Calendar) IsLeapYear

func (cal *Calendar) IsLeapYear(year int) bool

IsLeapYear returns true if the year is a leap year.

func (*Calendar) MinDaysPerYear

func (cal *Calendar) MinDaysPerYear() int

MinDaysPerYear returns the minimum number of days in a year.

func (*Calendar) MustNewDate

func (cal *Calendar) MustNewDate(month, day, year int) Date

MustNewDate creates a new date from the specified month, day and year. Panics if the values are invalid.

func (*Calendar) NewDate

func (cal *Calendar) NewDate(month, day, year int) (Date, error)

NewDate creates a new date from the specified month, day and year.

func (*Calendar) NewDateByDays

func (cal *Calendar) NewDateByDays(days int) Date

NewDateByDays creates a new date from a number of days, with 0 representing the date 1/1/1.

func (*Calendar) ParseDate

func (cal *Calendar) ParseDate(in string) (Date, error)

ParseDate creates a new date from the specified text.

func (*Calendar) Text

func (cal *Calendar) Text(year int, w io.Writer)

Text writes a text representation of the year.

func (*Calendar) Valid

func (cal *Calendar) Valid() error

Valid returns nil if the calendar data is usable.

type Date

type Date struct {
	Days int
	// contains filtered or unexported fields
}

Date holds a calendar date. This is the number of days since 1/1/1 in the calendar. Note that the value -1 refers to the last day of the year -1, not year 0, as there is no year 0.

func (Date) DayInMonth

func (date Date) DayInMonth() int

DayInMonth returns the day within the month of the date. Note that the first day is represented by a 1, not 0.

func (Date) DayInYear

func (date Date) DayInYear() int

DayInYear returns the day within the year of the date. Note that the first day is represented by a 1, not 0.

func (Date) DaysInMonth

func (date Date) DaysInMonth() int

DaysInMonth returns the number of days in the month of the date.

func (Date) Era

func (date Date) Era() string

Era returns the era suffix for the year.

func (Date) Format

func (date Date) Format(layout string) string

Format returns a formatted version of the date. The layout is parsed as in WriteFormat().

func (Date) MarshalText

func (date Date) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler.

func (Date) Month

func (date Date) Month() int

Month returns the month of the date. Note that the first month is represented by 1, not 0.

func (Date) MonthName

func (date Date) MonthName() string

MonthName returns the name of the month of the date.

func (Date) String

func (date Date) String() string

String returns a date in the ShortFormat.

func (Date) TextCalendarMonth

func (date Date) TextCalendarMonth(w io.Writer)

TextCalendarMonth writes a text representation of the month.

func (*Date) UnmarshalText

func (date *Date) UnmarshalText(text []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

func (Date) WeekDay

func (date Date) WeekDay() int

WeekDay returns the weekday of the date.

func (Date) WeekDayName

func (date Date) WeekDayName() string

WeekDayName returns the name of the weekday of the date.

func (Date) WriteFormat

func (date Date) WriteFormat(w io.Writer, layout string)

WriteFormat writes a formatted version of the date to the writer. The layout is parsed for directives and anything that is not a directive is passed through unchanged. Valid directives:

%W  Full weekday, e.g. 'Friday'
%w  Short weekday, e.g. 'Fri'
%M  Full month name, e.g. 'September'
%m  Short month name, e.g. 'Sep'
%N  Month, e.g. '9'
%n  Month padded with zeroes, e.g. '09'
%D  Day, e.g. '2'
%d  Day padded with zeroes, e.g. '02'
%Y  Year, e.g. '2017' if positive, '2017 BC' if negative; however, if the eras aren't empty and match each other,
    then this will behave the same as %y
%y  Year with era, e.g. '2017 AD'; however, if the eras are empty or they match each other, then negative years
    will result in '-2017 AD'
%z  Year without the era, e.g. '2017' or '-2017'
%%  %

func (Date) Year

func (date Date) Year() int

Year returns the year of the date.

type LeapYear

type LeapYear struct {
	Month  int `json:"month"`
	Every  int `json:"every"`
	Except int `json:"except,omitempty" yaml:",omitempty"`
	Unless int `json:"unless,omitempty" yaml:",omitempty"`
}

LeapYear holds parameters for determining leap years.

func (*LeapYear) Is

func (leapYear *LeapYear) Is(year int) bool

Is returns true if the year is a leap year.

func (*LeapYear) Since

func (leapYear *LeapYear) Since(year int) int

Since returns the number of leap years that have occurred between year 1 and the specified year, exclusive.

func (*LeapYear) Valid

func (leapYear *LeapYear) Valid(cal *Calendar) error

Valid returns nil if the leap year data is usable.

type Month

type Month struct {
	Name string `json:"name"`
	Days int    `json:"days"`
}

Month holds information about a month within the calendar.

func (*Month) Valid

func (month *Month) Valid() error

Valid returns nil if the month data is usable.

type Season

type Season struct {
	Name       string `json:"name"`
	StartMonth int    `json:"start_month" yaml:"start_month"`
	StartDay   int    `json:"start_day" yaml:"start_day"`
	EndMonth   int    `json:"end_month" yaml:"end_month"`
	EndDay     int    `json:"end_day" yaml:"end_day"`
}

Season defines a seasonal period in the calendar.

func (*Season) String

func (season *Season) String() string

func (*Season) Valid

func (season *Season) Valid(cal *Calendar) error

Valid returns nil if the season data is usable for the given calendar.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL