calendar

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: May 25, 2024 License: BSD-2-Clause Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatDate

func FormatDate(d Date, format DateFormat) string

FormatDate returns a textual representation of the Date value formatted according to the format defined by the argument.

func FormatYear

func FormatYear(y Year) string

FormatYear returns a textual representation of the Year value formatted.

func FormatYearMonth

func FormatYearMonth(ym YearMonth) string

FormatYearMonth returns a textual representation of the YearMonth value formatted.

func FormatYearWeek

func FormatYearWeek(yw YearWeek) string

FormatYearWeek returns a textual representation of the YearWeek value formatted.

Types

type Date

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

Date represents a date in the proleptic Gregorian calendar. The zero value is 0001-01-01.

func DateOfYD

func DateOfYD(year int, dayOfYear int) Date

DateOfYD returns a Date of the given year and day of year. It panics if the arguments represents an invalid date.

func DateOfYMD

func DateOfYMD(year int, month Month, dayOfMonth int) Date

DateOfYMD returns a Date of the given year, month, and day of month. It panics if the arguments represents an invalid date.

func DateOfYWD

func DateOfYWD(year int, week int, dayOfWeek DayOfWeek) Date

DateOfYWD returns a Date of the given year, week, and day of week. It panics if the arguments represents an invalid date.

func ParseDate

func ParseDate(s string, format DateFormat) (d Date, err error)

ParseDate parses a formatted string and returns the Date value it represents.

func UnixDay

func UnixDay(epochDays int64) Date

UnixDay returns a Date of the given epoch days since the Unix epoch.

func (Date) Add

func (d Date) Add(days int) Date

Add returns the date going forward by the amount of days.

func (Date) After

func (d Date) After(other Date) bool

After returns whether the date is after the other date.

func (Date) Before

func (d Date) Before(other Date) bool

Before returns whether the date is before the other date.

func (Date) Cmp

func (d Date) Cmp(other Date) int

Cmp compares the date with the other date.

func (Date) DaysUntil

func (d Date) DaysUntil(endExclusive Date) int64

DaysUntil returns the number of days until the date of endExclusive.

func (Date) Equal

func (d Date) Equal(other Date) bool

Equal returns whether the date is equal to the other date.

func (Date) String

func (d Date) String() string

String returns the string representation of the date.

func (Date) Sub

func (d Date) Sub(days int) Date

Sub returns the date going backward by the amount of days.

func (Date) UnixDay

func (d Date) UnixDay() int64

UnixDay returns the number of days since the Unix epoch.

func (Date) YD

func (d Date) YD() (year int, dayOfYear int)

YD returns the year and day of year.

func (Date) YMD

func (d Date) YMD() (year int, month Month, day int)

YMD returns the year, month, and day of month.

func (Date) YWD

func (d Date) YWD() (year int, week int, dayOfWeek DayOfWeek)

YWD returns the year, week, and day of week.

func (Date) Year

func (d Date) Year() Year

Year returns the year including this date.

func (Date) YearMonth

func (d Date) YearMonth() YearMonth

YearMonth returns the year and month including this date.

func (Date) YearWeek

func (d Date) YearWeek() YearWeek

YearWeek returns the year and week including this date.

type DateFormat

type DateFormat int

DateFormat represents the format of a date. The following formats are supported:

- DateFormatYMD: yyyy-mm-dd - DateFormatYWD: yyyy-Www-d - DateFormatYD: yyyy-ddd

where y, m, d, and w are decimal digits and W is a rune 'W'. Each of the above formats may have a prefix of '-' or '+' for the sign of the year.

const (
	// DateFormatAny represents any date format.
	DateFormatAny DateFormat = iota
	// DateFormatYMD represents the yyyy-mm-dd format.
	DateFormatYMD
	// DateFormatYWD represents the yyyy-Www-d format.
	DateFormatYWD
	// DateFormatYD represents the yyyy-ddd format.
	DateFormatYD
)

type DayOfWeek

type DayOfWeek int

DayOfWeek represents a day of week.

const (
	DayOfWeekUnspecified DayOfWeek = iota // Unspecified
	DayOfWeekMonday                       // Monday
	DayOfWeekTuesday                      // Tuesday
	DayOfWeekWednesday                    // Wednesday
	DayOfWeekThursday                     // Thursday
	DayOfWeekFriday                       // Friday
	DayOfWeekSaturday                     // Saturday
	DayOfWeekSunday                       // Sunday
)

func (DayOfWeek) String

func (i DayOfWeek) String() string

type Month

type Month int

Month represents a month.

const (
	MonthUnspecified Month = iota // Unspecified
	MonthJanuary                  // January
	MonthFebruary                 // February
	MonthMarch                    // March
	MonthApril                    // April
	MonthMay                      // May
	MonthJune                     // June
	MonthJuly                     // July
	MonthAugust                   // August
	MonthSeptember                // September
	MonthOctober                  // October
	MonthNovember                 // November
	MonthDecember                 // December
)

func (Month) String

func (i Month) String() string

type Year

type Year int

Year represents a year.

func ParseYear

func ParseYear(s string) (Year, error)

ParseYear parses a formatted string and returns the Year value it represents. The following format is supported:

  • yyyy:

where y is a decimal digit. The above format may have a prefix of '-' or '+' for the sign of the year.

func (Year) ContainsDay

func (y Year) ContainsDay(dayOfYear int) bool

ContainsDay returns true if the dayOfYear is in this year.

func (Year) ContainsWeek

func (y Year) ContainsWeek(week int) bool

ContainsWeek returns true if the week is in this year.

func (Year) Date

func (y Year) Date(dayOfYear int) Date

Date returns a Date of the dayOfYear in this year.

func (Year) Days

func (y Year) Days() int

Days returns the number of days in the year.

func (Year) FirstDate

func (y Year) FirstDate() Date

FirstDate returns the first date in this year.

func (Year) FirstMonth

func (y Year) FirstMonth() YearMonth

FirstMonth returns the first month in this year.

func (Year) FirstWeek

func (y Year) FirstWeek() YearWeek

FirstWeek returns the first week in this year.

func (Year) IsLeap

func (y Year) IsLeap() bool

IsLeap returns true if the year is a leap year.

func (Year) LastDate

func (y Year) LastDate() Date

LastDate returns the last date in this year.

func (Year) LastMonth

func (y Year) LastMonth() YearMonth

LastMonth returns the last month in this year.

func (Year) LastWeek

func (y Year) LastWeek() YearWeek

LastWeek returns the last week in this year.

func (Year) Month

func (y Year) Month(month Month) YearMonth

Month returns a YearMonth of the month in this year.

func (Year) String

func (y Year) String() string

String returns the string representation of the year.

func (Year) Week

func (y Year) Week(weekOfYear int) YearWeek

Week returns a YearWeek of the weekOfYear in this year.

func (Year) Weeks

func (y Year) Weeks() int

Weeks returns the number of weeks in the year.

type YearMonth

type YearMonth struct {
	// contains filtered or unexported fields
}

YearMonth represents a year and a month in the proleptic Gregorian calendar.

func ParseYearMonth

func ParseYearMonth(s string) (YearMonth, error)

ParseYearMonth parses a formatted string and returns the YearMonth value it represents. The following format is supported:

  • yyyy-mm

where y and m are decimal digits. The above format may have a prefix of '-' or '+' for the sign of the year.

func YearMonthOf

func YearMonthOf(year int, month Month) YearMonth

YearMonthOf returns a YearMonth of the given year and month.

func (YearMonth) Add

func (ym YearMonth) Add(months int) YearMonth

Add returns the year and month going forward by the amount of months.

func (YearMonth) After

func (ym YearMonth) After(other YearMonth) bool

After returns whether the year and month is after the other year and month.

func (YearMonth) Before

func (ym YearMonth) Before(other YearMonth) bool

Before returns whether the year and month is before the other year and month.

func (YearMonth) Cmp

func (ym YearMonth) Cmp(other YearMonth) int

Cmp compares the year and month with the other year and month.

func (YearMonth) ContainsDay

func (ym YearMonth) ContainsDay(dayOfMonth int) bool

ContainsDay returns true if the dayOfMonth is in this year and month.

func (YearMonth) Date

func (ym YearMonth) Date(dayOfMonth int) Date

Date returns a Date of the dayOfMonth in this year and month.

func (YearMonth) Days

func (ym YearMonth) Days() int

Days returns the number of days in this year and month.

func (YearMonth) Equal

func (ym YearMonth) Equal(other YearMonth) bool

Equal returns whether the year and month is equal to the other year and month.

func (YearMonth) FirstDate

func (ym YearMonth) FirstDate() Date

FirstDate returns the first date in this year and month.

func (YearMonth) LastDate

func (ym YearMonth) LastDate() Date

LastDate returns the last date in this year and month.

func (YearMonth) MonthsUntil

func (ym YearMonth) MonthsUntil(endExclusive YearMonth) int64

MonthsUntil returns the number of months until the year and month of endExclusive.

func (YearMonth) String

func (ym YearMonth) String() string

String returns a textual representation of the YearMonth value formatted.

func (YearMonth) Sub

func (ym YearMonth) Sub(months int) YearMonth

Sub returns the year and month going backward by the amount of months.

func (YearMonth) YM added in v0.0.2

func (ym YearMonth) YM() (year int, month Month)

YM returns the year and the month.

func (YearMonth) Year

func (ym YearMonth) Year() Year

Year returns the year.

type YearWeek

type YearWeek struct {
	// contains filtered or unexported fields
}

YearWeek represents a year and a week.

func ParseYearWeek

func ParseYearWeek(s string) (YearWeek, error)

ParseYearWeek parses a formatted string and returns the YearWeek value it represents. The following format is supported:

- year-week:

  • yyyy-Www:

where y and w are a decimal digits and W is a rune 'W'. The above format may have a prefix of '-' or '+' for the sign of the year.

func YearWeekOf

func YearWeekOf(year int, week int) YearWeek

YearWeekOf returns a YearWeek of the given year and week.

func (YearWeek) After

func (yw YearWeek) After(other YearWeek) bool

After returns true if the YearWeek is after the other.

func (YearWeek) Before

func (yw YearWeek) Before(other YearWeek) bool

Before returns true if the YearWeek is before the other.

func (YearWeek) Cmp

func (yw YearWeek) Cmp(other YearWeek) int

Cmp compares two YearWeeks.

func (YearWeek) Date

func (yw YearWeek) Date(dayOfWeek DayOfWeek) Date

Date returns a Date of the dayOfWeek in this year and week.

func (YearWeek) Equal

func (yw YearWeek) Equal(other YearWeek) bool

Equal returns true if the YearWeek is equal to the other.

func (YearWeek) FirstDate

func (yw YearWeek) FirstDate() Date

FirstDate returns the first date in this year and week.

func (YearWeek) LastDate

func (yw YearWeek) LastDate() Date

LastDate returns the last date in this year and week.

func (YearWeek) String

func (yw YearWeek) String() string

String returns the string representation of the YearWeek.

func (YearWeek) YW added in v0.0.2

func (yw YearWeek) YW() (year int, week int)

YW returns the year and the week.

func (YearWeek) Year

func (yw YearWeek) Year() Year

Year returns the year.

Jump to

Keyboard shortcuts

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