Documentation
¶
Overview ¶
Package calendar provides a customizable calendar for roleplaying games.
Index ¶
- Constants
- Variables
- type Calendar
- func (cal *Calendar) Days(year int) int
- func (cal *Calendar) IsLeapMonth(month int) bool
- func (cal *Calendar) IsLeapYear(year int) bool
- func (cal *Calendar) MinDaysPerYear() int
- func (cal *Calendar) MustNewDate(month, day, year int) Date
- func (cal *Calendar) NewDate(month, day, year int) (Date, error)
- func (cal *Calendar) NewDateByDays(days int) Date
- func (cal *Calendar) ParseDate(in string) (Date, error)
- func (cal *Calendar) Text(year int, w io.Writer)
- func (cal *Calendar) Valid() error
- type Date
- func (date Date) DayInMonth() int
- func (date Date) DayInYear() int
- func (date Date) DaysInMonth() int
- func (date Date) Era() string
- func (date Date) Format(layout string) string
- func (date Date) MarshalText() ([]byte, error)
- func (date Date) Month() int
- func (date Date) MonthName() string
- func (date Date) String() string
- func (date Date) TextCalendarMonth(w io.Writer)
- func (date *Date) UnmarshalText(text []byte) error
- func (date Date) WeekDay() int
- func (date Date) WeekDayName() string
- func (date Date) WriteFormat(w io.Writer, layout string)
- func (date Date) Year() int
- type LeapYear
- type Month
- type Season
Constants ¶
const ( FullFormat = "%W, %M %D, %Y" LongFormat = "%M %D, %Y" MediumFormat = "%m %D, %Y" ShortFormat = "%N/%D/%Y" )
Predefined formats.
Variables ¶
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 { LeapYear *LeapYear `json:"leapyear,omitempty" yaml:",omitempty"` Era string `json:"era,omitempty" yaml:",omitempty"` PreviousEra string `json:"previous_era,omitempty" yaml:"previous_era,omitempty"` WeekDays []string `json:"weekdays"` Months []Month `json:"months"` Seasons []Season `json:"seasons"` DayZeroWeekDay int `json:"day_zero_weekday" yaml:"day_zero_weekday"` }
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) IsLeapMonth ¶
IsLeapMonth returns true if the month is the leap month.
func (*Calendar) IsLeapYear ¶
IsLeapYear returns true if the year is a leap year.
func (*Calendar) MinDaysPerYear ¶
MinDaysPerYear returns the minimum number of days in a year.
func (*Calendar) MustNewDate ¶
MustNewDate creates a new date from the specified month, day and year. Panics if the values are invalid.
func (*Calendar) NewDateByDays ¶
NewDateByDays creates a new date from a number of days, with 0 representing the date 1/1/1.
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 ¶
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 ¶
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 ¶
DaysInMonth returns the number of days in the month of the date.
func (Date) Format ¶
Format returns a formatted version of the date. The layout is parsed as in WriteFormat().
func (Date) MarshalText ¶
MarshalText implements encoding.TextMarshaler.
func (Date) Month ¶
Month returns the month of the date. Note that the first month is represented by 1, not 0.
func (Date) TextCalendarMonth ¶
TextCalendarMonth writes a text representation of the month.
func (*Date) UnmarshalText ¶
UnmarshalText implements encoding.TextUnmarshaler.
func (Date) WeekDayName ¶
WeekDayName returns the name of the weekday of the date.
func (Date) WriteFormat ¶
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' %% %
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.
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.