Documentation
¶
Overview ¶
Package datetime implements the date and time operations of ECMAScript. Time values count milliseconds since 1970-01-01T00:00:00Z. Day numbers count calendar days from the same epoch, starting at zero.
Index ¶
- Constants
- func CalendarFromTime(t float64) (year float64, month int, date float64)
- func CountryOfZone(zone string) string
- func DateFromTime(t float64) float64
- func DateString(tv float64, tz TimeZone) string
- func Day(t float64) float64
- func DayFromYear(y float64) float64
- func DayWithinYear(t float64) float64
- func DaysInYear(y float64) float64
- func HourFromTime(t float64) float64
- func ISOString(tv float64) string
- func InLeapYear(t float64) bool
- func LocalTime(t float64, tz TimeZone) float64
- func LocaleDateString(tv float64, tz TimeZone) string
- func LocaleString(tv float64, tz TimeZone) string
- func LocaleTimeString(tv float64, tz TimeZone) string
- func MakeDate(day, time float64) float64
- func MakeDay(year, month, date float64) float64
- func MakeFullYear(year float64) float64
- func MakeTime(hour, min, sec, ms float64) float64
- func MinFromTime(t float64) float64
- func MonthFromTime(t float64) float64
- func MsFromTime(t float64) float64
- func Parse(s string, tz TimeZone) float64
- func ParsePolled(s string, tz TimeZone, poll func()) float64
- func PrimaryZones() []string
- func SecFromTime(t float64) float64
- func String(tv, offset float64, name string) string
- func TimeClip(time float64) float64
- func TimeFromYear(y float64) float64
- func TimeString(tv, offset float64, name string) string
- func TimeWithinDay(t float64) float64
- func UTC(t float64, tz TimeZone) float64
- func UTCString(tv float64) string
- func WeekDay(t float64) float64
- func YearFromTime(t float64) float64
- func ZoneName(tz TimeZone) string
- func ZonesOfCountry(country string) []string
- type TimeZone
- type Zone
Constants ¶
const (
// MsPerDay is the number of milliseconds in a day.
MsPerDay = 24 * msPerHour
)
Variables ¶
This section is empty.
Functions ¶
func CalendarFromTime ¶
CalendarFromTime returns the year, the month (0 to 11) and the day of the month (1 to 31) of the finite time value t.
func CountryOfZone ¶
CountryOfZone returns the ISO 3166 code of the country that the IANA time zone database gives the zone with the primary identifier zone, or an empty string when it gives none.
func DateFromTime ¶
DateFromTime returns the day of the month (1 to 31) for the finite time value t.
func DateString ¶
DateString returns the result of Date.prototype.toDateString for the time value tv, which must not be NaN.
func DayFromYear ¶
DayFromYear returns the day number of January 1 of year y.
func DayWithinYear ¶
DayWithinYear returns the zero-based day of the year for the finite time value t.
func DaysInYear ¶
DaysInYear returns the number of days (365 or 366) in the Gregorian calendar year y.
func HourFromTime ¶
HourFromTime returns the hour of the day (0 to 23) for the time value t.
func ISOString ¶
ISOString returns the result of Date.prototype.toISOString for the time value tv, which must be finite.
func InLeapYear ¶
InLeapYear reports whether the finite time value t falls in a leap year.
func LocaleDateString ¶
LocaleDateString returns the result of Date.prototype.toLocaleDateString for the time value tv, which must not be NaN.
func LocaleString ¶
LocaleString returns the result of Date.prototype.toLocaleString for the time value tv, which must not be NaN. The format is fixed: month/day/year, hour:minute:second and AM or PM, in local time.
func LocaleTimeString ¶
LocaleTimeString returns the result of Date.prototype.toLocaleTimeString for the time value tv, which must not be NaN.
func MakeDate ¶
MakeDate returns the time value for the given day number and millisecond offset from midnight. It returns NaN if either input or the result is non-finite.
func MakeDay ¶
MakeDay returns the day number for the given year, zero-based month, and one-based date. It truncates the components toward zero and normalizes out-of-range months and dates. It returns NaN for non-finite input or if the year after month normalization is outside the range -1,000,000 to 1,000,000.
func MakeFullYear ¶
MakeFullYear truncates year toward zero and maps years 0 through 99 to 1900 through 1999. It preserves NaN and infinities.
func MakeTime ¶
MakeTime combines hours, minutes, seconds, and milliseconds into a millisecond offset from midnight. It truncates each component toward zero and returns NaN for non-finite input.
func MinFromTime ¶
MinFromTime returns the minute within the hour (0 to 59) for the time value t.
func MonthFromTime ¶
MonthFromTime returns the month of the finite time value t, from 0 (January) to 11 (December).
func MsFromTime ¶
MsFromTime returns the millisecond within the second (0 to 999) for the time value t.
func Parse ¶
Parse returns the time value that the string s represents, or NaN. It accepts the date time string format of ECMAScript, the formats of String and UTCString, and some common legacy formats. A time without an offset is a local time of tz.
func ParsePolled ¶
ParsePolled is like Parse. poll, which may be nil, is called now and then over a long s and may stop the parsing by panicking.
func PrimaryZones ¶
func PrimaryZones() []string
PrimaryZones returns the primary identifiers of the zones of the IANA time zone database, sorted.
func SecFromTime ¶
SecFromTime returns the second within the minute (0 to 59) for the time value t.
func String ¶
String implements ToDateString for the finite time value tv and UTC offset in milliseconds.
func TimeClip ¶
TimeClip truncates time toward zero to whole milliseconds. It returns NaN if time is non-finite or its magnitude exceeds 8.64e15 milliseconds.
func TimeFromYear ¶
TimeFromYear returns the time value at midnight on January 1 of year y.
func TimeString ¶
TimeString formats the local time of the finite time value tv with the UTC offset in milliseconds.
func TimeWithinDay ¶
TimeWithinDay returns the milliseconds since midnight for the time value t.
func UTC ¶
UTC implements UTC with tz as the system time zone. A local time that is repeated is the earlier of its instants, and a local time that is skipped is interpreted with the offset before the transition.
func UTCString ¶
UTCString returns the result of Date.prototype.toUTCString for the time value tv, which must not be NaN.
func YearFromTime ¶
YearFromTime returns the calendar year containing the finite time value t.
func ZonesOfCountry ¶
ZonesOfCountry returns the primary identifiers of the zones that the IANA time zone database gives the country with the ISO 3166 code country, sorted.
Types ¶
type TimeZone ¶
type TimeZone interface {
// Offset returns the offset from UTC in milliseconds at the finite time value t,
// a whole number of minutes, and the abbreviation of the zone, which may be empty.
Offset(t float64) (offset float64, name string)
}
TimeZone is the time zone of local time.
type Zone ¶
type Zone interface {
TimeZone
// OffsetSeconds returns the offset from UTC in seconds at the Unix time sec.
OffsetSeconds(sec int64) int
// IsDST reports whether the zone observes daylight saving time at Unix time sec.
IsDST(sec int64) bool
// Transition returns the first Unix time after sec at which the offset changes when next
// is true, or the last such time before sec when next is false. It reports false when
// there is none.
Transition(sec int64, next bool) (int64, bool)
}
Zone is a TimeZone whose offsets are known to the second, along with the instants at which they change.
func LoadZone ¶
LoadZone returns the time zone that the IANA time zone identifier name stands for, matched without regard to ASCII case, together with the identifier in the case of the time zone database and the primary identifier that name is a link to. It reports false when the platform has no such time zone.