datetime

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: 0BSD Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
const (

	// MsPerDay is the number of milliseconds in a day.
	MsPerDay = 24 * msPerHour
)

Variables

This section is empty.

Functions

func CalendarFromTime

func CalendarFromTime(t float64) (year float64, month int, date float64)

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

func CountryOfZone(zone string) string

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

func DateFromTime(t float64) float64

DateFromTime returns the day of the month (1 to 31) for the finite time value t.

func DateString

func DateString(tv float64, tz TimeZone) string

DateString returns the result of Date.prototype.toDateString for the time value tv, which must not be NaN.

func Day

func Day(t float64) float64

Day returns the day number containing the time value t, with 1970-01-01 as day zero.

func DayFromYear

func DayFromYear(y float64) float64

DayFromYear returns the day number of January 1 of year y.

func DayWithinYear

func DayWithinYear(t float64) float64

DayWithinYear returns the zero-based day of the year for the finite time value t.

func DaysInYear

func DaysInYear(y float64) float64

DaysInYear returns the number of days (365 or 366) in the Gregorian calendar year y.

func HourFromTime

func HourFromTime(t float64) float64

HourFromTime returns the hour of the day (0 to 23) for the time value t.

func ISOString

func ISOString(tv float64) string

ISOString returns the result of Date.prototype.toISOString for the time value tv, which must be finite.

func InLeapYear

func InLeapYear(t float64) bool

InLeapYear reports whether the finite time value t falls in a leap year.

func LocalTime

func LocalTime(t float64, tz TimeZone) float64

LocalTime implements LocalTime with tz as the system time zone.

func LocaleDateString

func LocaleDateString(tv float64, tz TimeZone) string

LocaleDateString returns the result of Date.prototype.toLocaleDateString for the time value tv, which must not be NaN.

func LocaleString

func LocaleString(tv float64, tz TimeZone) string

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

func LocaleTimeString(tv float64, tz TimeZone) string

LocaleTimeString returns the result of Date.prototype.toLocaleTimeString for the time value tv, which must not be NaN.

func MakeDate

func MakeDate(day, time float64) float64

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

func MakeDay(year, month, date float64) float64

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

func MakeFullYear(year float64) float64

MakeFullYear truncates year toward zero and maps years 0 through 99 to 1900 through 1999. It preserves NaN and infinities.

func MakeTime

func MakeTime(hour, min, sec, ms float64) float64

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

func MinFromTime(t float64) float64

MinFromTime returns the minute within the hour (0 to 59) for the time value t.

func MonthFromTime

func MonthFromTime(t float64) float64

MonthFromTime returns the month of the finite time value t, from 0 (January) to 11 (December).

func MsFromTime

func MsFromTime(t float64) float64

MsFromTime returns the millisecond within the second (0 to 999) for the time value t.

func Parse

func Parse(s string, tz TimeZone) float64

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

func ParsePolled(s string, tz TimeZone, poll func()) float64

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

func SecFromTime(t float64) float64

SecFromTime returns the second within the minute (0 to 59) for the time value t.

func String

func String(tv, offset float64, name string) string

String implements ToDateString for the finite time value tv and UTC offset in milliseconds.

func TimeClip

func TimeClip(time float64) float64

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

func TimeFromYear(y float64) float64

TimeFromYear returns the time value at midnight on January 1 of year y.

func TimeString

func TimeString(tv, offset float64, name string) string

TimeString formats the local time of the finite time value tv with the UTC offset in milliseconds.

func TimeWithinDay

func TimeWithinDay(t float64) float64

TimeWithinDay returns the milliseconds since midnight for the time value t.

func UTC

func UTC(t float64, tz TimeZone) float64

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

func UTCString(tv float64) string

UTCString returns the result of Date.prototype.toUTCString for the time value tv, which must not be NaN.

func WeekDay

func WeekDay(t float64) float64

WeekDay returns the weekday of the time value t, from 0 (Sunday) to 6 (Saturday).

func YearFromTime

func YearFromTime(t float64) float64

YearFromTime returns the calendar year containing the finite time value t.

func ZoneName

func ZoneName(tz TimeZone) string

ZoneName returns the identifier of tz, or an empty string if it is unknown.

func ZonesOfCountry

func ZonesOfCountry(country string) []string

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.

func Local

func Local() TimeZone

Local returns the time zone of time.Local.

func LocationZone

func LocationZone(loc *time.Location) TimeZone

LocationZone returns the TimeZone of loc.

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

func LoadZone(name string) (id, primary string, z Zone, ok bool)

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.

func ZoneOf

func ZoneOf(tz TimeZone) (id string, z Zone, ok bool)

ZoneOf returns the rules of tz, with its identifier when known.

Jump to

Keyboard shortcuts

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