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: 4
August
August: 8
December
December: 12
February
February: 2
Friday
Friday: 5
Hour
Hour: 3600000000000
January
January: 1
July
July: 7
June
June: 6
Kitchen
Kitchen: "3:04PM"
Kitchen24
Kitchen24: "15:04"
March
March: 3
May
May: 5
Microsecond
Microsecond: 1000
Millisecond
Millisecond: 1000000
Minute
Minute: 60000000000
Monday
Monday: 1
Nanosecond
Nanosecond: 1
November
November: 11
October
October: 10
RFC1123
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: 6
Second
Second: 1000000000
September
September: 9
Sunday
Sunday: 0
Thursday
Thursday: 4
Tuesday
Tuesday: 2
UnixDate
UnixDate: "Mon Jan _2 15:04:05 MST 2006"
Wednesday
Wednesday: 3
Functions
Duration validator
validator form
validator(string)
call form
func(s: string) -> bool
Duration 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) -> bool
Format defines a type string that must adhere to a certain layout.
See Parse for a description on layout strings.
FormatDuration
FormatDuration: func(d: int) -> string
FormatDuration 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) -> string
FormatString 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) -> string
Parse 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) -> int
ParseDuration 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) -> bool
Time validates a RFC3339 date-time.
Caveat: this implementation uses the Go implementation, which does not accept leap seconds.
ToUnix
ToUnix: func(value: string) -> int
ToUnix returns the given time value as a Unix time in seconds elapsed since January 1, 1970 UTC.
ToUnixNano
ToUnixNano: func(value: string) -> int
ToUnixNano returns the given time value as a Unix time in nanoseconds elapsed since January 1, 1970 UTC.
Unix
Unix: func(sec: int, nsec: int) -> string
Unix 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).