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

cue
ANSIC: "Mon Jan _2 15:04:05 2006"

April

cue
April: 4

August

cue
August: 8

December

cue
December: 12

February

cue
February: 2

Friday

cue
Friday: 5

Hour

cue
Hour: 3600000000000

January

cue
January: 1

July

cue
July: 7

June

cue
June: 6

Kitchen

cue
Kitchen: "3:04PM"

Kitchen24

cue
Kitchen24: "15:04"

March

cue
March: 3

May

cue
May: 5

Microsecond

cue
Microsecond: 1000

Millisecond

cue
Millisecond: 1000000

Minute

cue
Minute: 60000000000

Monday

cue
Monday: 1

Nanosecond

cue
Nanosecond: 1

November

cue
November: 11

October

cue
October: 10

RFC1123

cue
RFC1123: "Mon, 02 Jan 2006 15:04:05 MST"

RFC1123Z

cue
RFC1123Z: "Mon, 02 Jan 2006 15:04:05 -0700"

RFC1123 with numeric zone

RFC3339

cue
RFC3339: "2006-01-02T15:04:05Z07:00"

RFC3339Date

cue
RFC3339Date: "2006-01-02"

RFC3339Nano

cue
RFC3339Nano: "2006-01-02T15:04:05.999999999Z07:00"

RFC822

cue
RFC822: "02 Jan 06 15:04 MST"

RFC822Z

cue
RFC822Z: "02 Jan 06 15:04 -0700"

RFC822 with numeric zone

RFC850

cue
RFC850: "Monday, 02-Jan-06 15:04:05 MST"

RubyDate

cue
RubyDate: "Mon Jan 02 15:04:05 -0700 2006"

Saturday

cue
Saturday: 6

Second

cue
Second: 1000000000

September

cue
September: 9

Sunday

cue
Sunday: 0

Thursday

cue
Thursday: 4

Tuesday

cue
Tuesday: 2

UnixDate

cue
UnixDate: "Mon Jan _2 15:04:05 MST 2006"

Wednesday

cue
Wednesday: 3

Functions

Duration validator

validator form

cue
validator(string)

call form

cue
func(s: string) -> bool

Duration validates a duration string.

  • Note: this format also accepts strings of the form '1h3m', '2ms', etc.

To limit this to seconds only, as often used in JSON, add the !~"hmuµn" constraint.

Format validator

validator form

cue
func(layout: string) -> validator(string)

call form

cue
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

cue
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

cue
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

cue
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 2006

would 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

cue
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

cue
Split: func(t: string) -> {...}

Split parses a time string into its individual parts.

Time validator

validator form

cue
validator(string)

call form

cue
func(s: string) -> bool

Time validates a RFC3339 date-time.

Caveat: this implementation uses the Go implementation, which does not accept leap seconds.

ToUnix

cue
ToUnix: func(value: string) -> int

ToUnix returns the given time value as a Unix time in seconds elapsed since January 1, 1970 UTC.

ToUnixNano

cue
ToUnixNano: func(value: string) -> int

ToUnixNano returns the given time value as a Unix time in nanoseconds elapsed since January 1, 1970 UTC.

Unix

cue
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).

Install CUE