time
CUE v0.18.0
Package time defines time-related types.
In CUE time values are represented as a string of the format time.RFC3339Nano.
Constants
ANSIC
ANSIC: "Mon Jan _2 15:04:05 2006"April
April: 4August
August: 8December
December: 12February
February: 2Friday
Friday: 5Hour
Hour: 3600000000000January
January: 1July
July: 7June
June: 6Kitchen
Kitchen: "3:04PM"Kitchen24
Kitchen24: "15:04"March
March: 3May
May: 5Microsecond
Microsecond: 1000Millisecond
Millisecond: 1000000Minute
Minute: 60000000000Monday
Monday: 1Nanosecond
Nanosecond: 1November
November: 11October
October: 10RFC1123
RFC1123: "Mon, 02 Jan 2006 15:04:05 MST"RFC1123Z
RFC1123Z: "Mon, 02 Jan 2006 15:04:05 -0700"RFC1123 with numeric zone
RFC3339
RFC3339: "2006-01-02T15:04:05Z07:00"RFC3339Date
RFC3339Date: "2006-01-02"RFC3339Nano
RFC3339Nano: "2006-01-02T15:04:05.999999999Z07:00"RFC822
RFC822: "02 Jan 06 15:04 MST"RFC822Z
RFC822Z: "02 Jan 06 15:04 -0700"RFC822 with numeric zone
RFC850
RFC850: "Monday, 02-Jan-06 15:04:05 MST"RubyDate
RubyDate: "Mon Jan 02 15:04:05 -0700 2006"Saturday
Saturday: 6Second
Second: 1000000000September
September: 9Sunday
Sunday: 0Thursday
Thursday: 4Tuesday
Tuesday: 2UnixDate
UnixDate: "Mon Jan _2 15:04:05 MST 2006"Wednesday
Wednesday: 3Functions
Duration validator
validator form
validator(string)call form
func(s: string) -> boolDuration validates a duration string.
To limit this to seconds only, as often used in JSON, add the !~"hmuµn" constraint.
Format validator
validator form
func(layout: string) -> validator(string)call form
func(value: string, layout: string) -> boolFormat defines a type string that must adhere to a certain layout.
See Parse for a description on layout strings.
FormatDuration
FormatDuration: func(d: int) -> stringFormatDuration converts nanoseconds to a string representing the duration in the form "72h3m0.5s".
Leading zero units are omitted. As a special case, durations less than one second use a smaller unit (milli-, micro-, or nanoseconds) to ensure that the leading digit is non-zero. The zero duration formats as 0s.
FormatString
FormatString: func(layout: string, value: string) -> stringFormatString returns a textual representation of the time value. The formatted value is formatted according to the layout defined by the argument. See Parse for more information on the layout string.
Parse
Parse: func(layout: string, value: string) -> stringParse parses a formatted string and returns the time value it represents. The layout defines the format by showing how the reference time, defined to be
Mon Jan 2 15:04:05 -0700 MST 2006would be interpreted if it were the value; it serves as an example of the input format. The same interpretation will then be made to the input string.
Predefined layouts ANSIC, UnixDate, RFC3339 and others describe standard and convenient representations of the reference time. For more information about the formats and the definition of the reference time, see the documentation for ANSIC and the other constants defined by this package. Also, the executable example for Time.Format demonstrates the working of the layout string in detail and is a good reference.
Elements omitted from the value are assumed to be zero or, when zero is impossible, one, so parsing "3:04pm" returns the time corresponding to Jan 1, year 0, 15:04:00 UTC (note that because the year is 0, this time is before the zero Time). Years must be in the range 0000..9999. The day of the week is checked for syntax but it is otherwise ignored.
In the absence of a time zone indicator, Parse returns a time in UTC.
When parsing a time with a zone offset like -0700, if the offset corresponds to a time zone used by the current location (Local), then Parse uses that location and zone in the returned time. Otherwise it records the time as being in a fabricated location with time fixed at the given zone offset.
Parse currently does not support zone abbreviations like MST. All are interpreted as UTC.
ParseDuration
ParseDuration: func(s: string) -> intParseDuration reports the nanoseconds represented by a duration string.
A duration string is a possibly signed sequence of decimal numbers, each with optional fraction and a unit suffix, such as "300ms", "-1.5h" or "2h45m". Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h".
Split
Split: func(t: string) -> {...}Split parses a time string into its individual parts.
Time validator
validator form
validator(string)call form
func(s: string) -> boolTime validates a RFC3339 date-time.
Caveat: this implementation uses the Go implementation, which does not accept leap seconds.
ToUnix
ToUnix: func(value: string) -> intToUnix returns the given time value as a Unix time in seconds elapsed since January 1, 1970 UTC.
ToUnixNano
ToUnixNano: func(value: string) -> intToUnixNano returns the given time value as a Unix time in nanoseconds elapsed since January 1, 1970 UTC.
Unix
Unix: func(sec: int, nsec: int) -> stringUnix returns the Time, in UTC, corresponding to the given Unix time, sec seconds and nsec nanoseconds since January 1, 1970 UTC. It is valid to pass nsec outside the range [0, 999999999]. Not all sec values have a corresponding time value. One such value is 1<<63-1 (the largest int64 value).