Documentation ¶
Overview ¶
Package civil implements types for civil time, a time-zone-independent representation of time that follows the rules of the proleptic Gregorian calendar with exactly 24-hour days, 60-minute hours, and 60-second minutes.
Because they lack location information, these types do not represent unique moments or intervals of time. Use time.Time for that purpose.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Date ¶
type Date struct { Year int // Year (e.g., 2014). Month time.Month // Month of the year (January = 1, ...). Day int // Day of the month, starting at 1. }
A Date represents a date (year, month, day).
This type does not include location information, and therefore does not describe a unique 24-hour timespan.
func ParseDate ¶
ParseDate parses a string in RFC3339 full-date format and returns the date value it represents.
func (Date) AddDays ¶
AddDays returns the date that is n days in the future. n can also be negative to go into the past.
func (Date) DaysSince ¶
DaysSince returns the signed number of days between the date and s, not including the end day. This is the inverse operation to AddDays.
func (Date) In ¶
In returns the time corresponding to time 00:00:00 of the date in the location.
In is always consistent with time.Date, even when time.Date returns a time on a different day. For example, if loc is America/Indiana/Vincennes, then both
time.Date(1955, time.May, 1, 0, 0, 0, 0, loc)
and
civil.Date{Year: 1955, Month: time.May, Day: 1}.In(loc)
return 23:00:00 on April 30, 1955.
In panics if loc is nil.
type DateTime ¶
A DateTime represents a date and time.
This type does not include location information, and therefore does not describe a unique moment in time.
func DateTimeOf ¶
DateTimeOf returns the DateTime in which a time occurs in that time's location.
func ParseDateTime ¶
ParseDateTime parses a string and returns the DateTime it represents. ParseDateTime accepts a variant of the RFC3339 date-time format that omits the time offset but includes an optional fractional time, as described in ParseTime. Informally, the accepted format is
YYYY-MM-DDTHH:MM:SS[.FFFFFFFFF]
where the 'T' may be a lower-case 't'.
func (DateTime) In ¶
In returns the time corresponding to the DateTime in the given location.
If the time is missing or ambigous at the location, In returns the same result as time.Date. For example, if loc is America/Indiana/Vincennes, then both
time.Date(1955, time.May, 1, 0, 30, 0, 0, loc)
and
civil.DateTime{ civil.Date{Year: 1955, Month: time.May, Day: 1}}, civil.Time{Minute: 30}}.In(loc)
return 23:30:00 on April 30, 1955.
In panics if loc is nil.
type Time ¶
type Time struct { Hour int // The hour of the day in 24-hour format; range [0-23] Minute int // The minute of the hour; range [0-59] Second int // The second of the minute; range [0-59] Nanosecond int // The nanosecond of the second; range [0-999999999] }
A Time represents a time with nanosecond precision.
This type does not include location information, and therefore does not describe a unique moment in time.
This type exists to represent the TIME type in storage-based APIs like BigQuery. Most operations on Times are unlikely to be meaningful. Prefer the DateTime type.
func ParseTime ¶
ParseTime parses a string and returns the time value it represents. ParseTime accepts an extended form of the RFC3339 partial-time format. After the HH:MM:SS part of the string, an optional fractional part may appear, consisting of a decimal point followed by one to nine decimal digits. (RFC3339 admits only one digit after the decimal point).