time
Types from the Go package time (a library PocketBase builds on), as JavaScript sees them: they turn up as values of PocketBase's types and of hook events.
time.Month
A Month specifies a month of the year (January = 1, ...).
Has everything Number has.
| Member | Type | |
|---|---|---|
string() |
(): string |
String returns the English name of the month ("January", "February", ...). |
time.Weekday
A Weekday specifies a day of the week (Sunday = 0, ...).
Has everything Number has.
| Member | Type | |
|---|---|---|
string() |
(): string |
String returns the English name of the day ("Sunday", "Monday", ...). |
time.Location
A Location maps time instants to the zone in use at that time. Typically, the Location represents the collection of time offsets in use in a geographical area. For many Locations the time offset varies depending on whether daylight savings time is in use at the time instant.
Location is used to provide a time zone in a printed Time value and for calculations involving intervals that may cross daylight savings time boundaries.
| Member | Type | |
|---|---|---|
string() |
(): string |
String returns a descriptive name for the time zone information, corresponding to the name argument to LoadLocation or FixedZone. |
time.Time
A Time represents an instant in time with nanosecond precision.
Programs using times should typically store and pass them as values,
not pointers. That is, time variables and struct fields should be of
type time.time, not *time.Time.
A Time value can be used by multiple goroutines simultaneously except
that the methods Time.gobDecode, Time.unmarshalBinary, Time.unmarshalJSON and
Time.unmarshalText are not concurrency-safe.
Time instants can be compared using the Time.before, Time.after, and Time.equal methods.
The Time.sub method subtracts two instants, producing a Duration.
The Time.add method adds a Time and a Duration, producing a Time.
The zero value of type Time is January 1, year 1, 00:00:00.000000000 UTC.
As this time is unlikely to come up in practice, the Time.isZero method gives
a simple way of detecting a time that has not been initialized explicitly.
Each time has an associated Location. The methods Time.local, Time.uTC, and Time.In return a
Time with a specific Location. Changing the Location of a Time value with
these methods does not change the actual instant it represents, only the time
zone in which to interpret it.
Representations of a Time value saved by the Time.gobEncode, Time.marshalBinary, Time.appendBinary,
Time.marshalJSON, Time.marshalText and Time.appendText methods store the Time.location's offset,
but not the location name. They therefore lose information about Daylight Saving Time.
In addition to the required “wall clock” reading, a Time may contain an optional reading of the current process's monotonic clock, to provide additional precision for comparison or subtraction. See the “Monotonic Clocks” section in the package documentation for details.
Note that the Go == operator compares not just the time instant but also the Location and the monotonic clock reading. Therefore, Time values should not be used as map or database keys without first guaranteeing that the identical Location has been set for all values, which can be achieved through use of the UTC or Local method, and that the monotonic clock reading has been stripped by setting t = t.Round(0). In general, prefer t.Equal(u) to t == u, since t.Equal uses the most accurate comparison available and correctly handles the case when only one of its arguments has a monotonic clock reading.
| Member | Type | |
|---|---|---|
string() |
(): string |
String returns the time formatted using the format string |
goString() |
(): string |
GoString implements fmt.goStringer and formats t to be printed in Go source code. |
format() |
(layout: string): string |
Format returns a textual representation of the time value formatted according to the layout defined by the argument. See the documentation for the constant called Layout to see how to represent the layout format. |
appendFormat() |
(b: string|Array<number>, layout: string): string|Array<number> |
AppendFormat is like Time.format but appends the textual representation to b and returns the extended buffer. |
isZero() |
(): boolean |
IsZero reports whether t represents the zero time instant, January 1, year 1, 00:00:00 UTC. |
after() |
(u: Time): boolean |
After reports whether the time instant t is after u. |
before() |
(u: Time): boolean |
Before reports whether the time instant t is before u. |
compare() |
(u: Time): number |
Compare compares the time instant t with u. If t is before u, it returns -1; if t is after u, it returns +1; if they're the same, it returns 0. |
equal() |
(u: Time): boolean |
Equal reports whether t and u represent the same time instant. Two times can be equal even if they are in different locations. For example, 6:00 +0200 and 4:00 UTC are Equal. See the documentation on the Time type for the pitfalls of using == with Time values; most code should use Equal instead. |
date() |
(): [number, Month, number] |
Date returns the year, month, and day in which t occurs. |
year() |
(): number |
Year returns the year in which t occurs. |
month() |
(): Month |
Month returns the month of the year specified by t. |
day() |
(): number |
Day returns the day of the month specified by t. |
weekday() |
(): Weekday |
Weekday returns the day of the week specified by t. |
isoWeek() |
(): [number, number] |
ISOWeek returns the ISO 8601 year and week number in which t occurs. Week ranges from 1 to 53. Jan 01 to Jan 03 of year n might belong to week 52 or 53 of year n-1, and Dec 29 to Dec 31 might belong to week 1 of year n+1. |
clock() |
(): [number, number, number] |
Clock returns the hour, minute, and second within the day specified by t. |
hour() |
(): number |
Hour returns the hour within the day specified by t, in the range [0, 23]. |
minute() |
(): number |
Minute returns the minute offset within the hour specified by t, in the range [0, 59]. |
second() |
(): number |
Second returns the second offset within the minute specified by t, in the range [0, 59]. |
nanosecond() |
(): number |
Nanosecond returns the nanosecond offset within the second specified by t, in the range [0, 999999999]. |
yearDay() |
(): number |
YearDay returns the day of the year specified by t, in the range [1,365] for non-leap years, and [1,366] in leap years. |
add() |
(d: Duration): Time |
Add returns the time t+d. |
sub() |
(u: Time): Duration |
Sub returns the duration t-u. If the result exceeds the maximum (or minimum) value that can be stored in a Duration, the maximum (or minimum) duration will be returned. To compute t-d for a duration d, use t.Add(-d). |
addDate() |
(years: number, months: number, days: number): Time |
AddDate returns the time corresponding to adding the given number of years, months, and days to t. For example, AddDate(-1, 2, 3) applied to January 1, 2011 returns March 4, 2010. |
utc() |
(): Time |
UTC returns t with the location set to UTC. |
local() |
(): Time |
Local returns t with the location set to local time. |
in() |
(loc: Location): Time |
In returns a copy of t representing the same time instant, but with the copy's location information set to loc for display purposes. |
location() |
(): (Location) |
Location returns the time zone information associated with t. |
zone() |
(): [string, number] |
Zone computes the time zone in effect at time t, returning the abbreviated name of the zone (such as "CET") and its offset in seconds east of UTC. |
zoneBounds() |
(): [Time, Time] |
ZoneBounds returns the bounds of the time zone in effect at time t. The zone begins at start and the next zone begins at end. If the zone begins at the beginning of time, start will be returned as a zero Time. If the zone goes on forever, end will be returned as a zero Time. The Location of the returned times will be the same as t. |
unix() |
(): number |
Unix returns t as a Unix time, the number of seconds elapsed since January 1, 1970 UTC. The result does not depend on the location associated with t. Unix-like operating systems often record time as a 32-bit count of seconds, but since the method here returns a 64-bit value it is valid for billions of years into the past or future. |
unixMilli() |
(): number |
UnixMilli returns t as a Unix time, the number of milliseconds elapsed since January 1, 1970 UTC. The result is undefined if the Unix time in milliseconds cannot be represented by an int64 (a date more than 292 million years before or after 1970). The result does not depend on the location associated with t. |
unixMicro() |
(): number |
UnixMicro returns t as a Unix time, the number of microseconds elapsed since January 1, 1970 UTC. The result is undefined if the Unix time in microseconds cannot be represented by an int64 (a date before year -290307 or after year 294246). The result does not depend on the location associated with t. |
unixNano() |
(): number |
UnixNano returns t as a Unix time, the number of nanoseconds elapsed since January 1, 1970 UTC. The result is undefined if the Unix time in nanoseconds cannot be represented by an int64 (a date before the year 1678 or after 2262). Note that this means the result of calling UnixNano on the zero Time is undefined. The result does not depend on the location associated with t. |
appendBinary() |
(b: string|Array<number>): string|Array<number> |
AppendBinary implements the encoding.binaryAppender interface. |
marshalBinary() |
(): string|Array<number> |
MarshalBinary implements the encoding.binaryMarshaler interface. |
unmarshalBinary() |
(data: string|Array<number>): void |
UnmarshalBinary implements the encoding.binaryUnmarshaler interface. |
gobEncode() |
(): string|Array<number> |
GobEncode implements the gob.GobEncoder interface. |
gobDecode() |
(data: string|Array<number>): void |
GobDecode implements the gob.GobDecoder interface. |
marshalJSON() |
(): string|Array<number> |
MarshalJSON implements the [encoding/json.Marshaler] interface. The time is a quoted string in the RFC 3339 format with sub-second precision. If the timestamp cannot be represented as valid RFC 3339 (e.g., the year is out of range), then an error is reported. |
unmarshalJSON() |
(data: string|Array<number>): void |
UnmarshalJSON implements the [encoding/json.Unmarshaler] interface. The time must be a quoted string in the RFC 3339 format. |
appendText() |
(b: string|Array<number>): string|Array<number> |
AppendText implements the encoding.textAppender interface. The time is formatted in RFC 3339 format with sub-second precision. If the timestamp cannot be represented as valid RFC 3339 (e.g., the year is out of range), then an error is returned. |
marshalText() |
(): string|Array<number> |
MarshalText implements the encoding.textMarshaler interface. The output matches that of calling the Time.appendText method. |
unmarshalText() |
(data: string|Array<number>): void |
UnmarshalText implements the encoding.textUnmarshaler interface. The time must be in the RFC 3339 format. |
isDST() |
(): boolean |
IsDST reports whether the time in the configured location is in Daylight Savings Time. |
truncate() |
(d: Duration): Time |
Truncate returns the result of rounding t down to a multiple of d (since the zero time). If d <= 0, Truncate returns t stripped of any monotonic clock reading but otherwise unchanged. |
round() |
(d: Duration): Time |
Round returns the result of rounding t to the nearest multiple of d (since the zero time). The rounding behavior for halfway values is to round up. If d <= 0, Round returns t stripped of any monotonic clock reading but otherwise unchanged. |
time.Duration
A Duration represents the elapsed time between two instants as an int64 nanosecond count. The representation limits the largest representable duration to approximately 290 years.
Has everything Number has.
| Member | Type | |
|---|---|---|
string() |
(): string |
String returns a string representing the duration in the form "72h3m0.5s". Leading zero units are omitted. As a special case, durations less than one second format use a smaller unit (milli-, micro-, or nanoseconds) to ensure that the leading digit is non-zero. The zero duration formats as 0s. |
nanoseconds() |
(): number |
Nanoseconds returns the duration as an integer nanosecond count. |
microseconds() |
(): number |
Microseconds returns the duration as an integer microsecond count. |
milliseconds() |
(): number |
Milliseconds returns the duration as an integer millisecond count. |
seconds() |
(): number |
Seconds returns the duration as a floating point number of seconds. |
minutes() |
(): number |
Minutes returns the duration as a floating point number of minutes. |
hours() |
(): number |
Hours returns the duration as a floating point number of hours. |
truncate() |
(m: Duration): Duration |
Truncate returns the result of rounding d toward zero to a multiple of m. If m <= 0, Truncate returns d unchanged. |
round() |
(m: Duration): Duration |
Round returns the result of rounding d to the nearest multiple of m. The rounding behavior for halfway values is to round away from zero. If the result exceeds the maximum (or minimum) value that can be stored in a Duration, Round returns the maximum (or minimum) duration. If m <= 0, Round returns d unchanged. |
abs() |
(): Duration |
Abs returns the absolute value of d. As a special case, Duration(math.minInt64) is converted to Duration(math.maxInt64), reducing its magnitude by 1 nanosecond. |
Questions and comments
Comments are a GitHub Discussions thread; sign in with GitHub to post.