The API for this package was created based on Go's time
package.
LAYOUT
ANSIC
UNIX_DATE
RUBY_DATE
RFC822
RFC822Z
RFC850
RFC1123
RFC1123Z
RFC3339
RFC3339NANO
KITCHEN
STAMP
STAMP_MILLI
STAMP_MICRO
STAMP_NANO
DATETIME
DATE_ONLY
TIME_ONLY
NANOSECOND
MICROSECOND
MILLISECOND
SECOND
MINUTE
HOUR
toDuration
parseDuration
since
until
Duration.abs
Duration.hours
Duration.microseconds
Duration.milliseconds
Duration.minutes
Duration.nanoseconds
Duration.round
Duration.seconds
Duration.string
Duration.truncate
date
now
parse
unix
unixMicro
unixMilli
Time.add
Time.addDate
Time.after
Time.appendFormat
Time.before
Time.compare
Time.day
Time.equal
Time.format
Time.hour
Time.withLocation
Time.isDST
Time.isZero
Time.local
Time.location
Time.minute
Time.month
Time.nanosecond
Time.round
Time.second
Time.string
Time.sub
Time.truncate
Time.utc
Time.unix
Time.unixMicro
Time.unixMilli
Time.unixNano
Time.weekday
Time.year
Time.yearDay
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.
Duration
type is compatible with google.protobuf.Duration
type.
FYI: https://pkg.go.dev/time#Duration
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.
FYI: https://pkg.go.dev/time#Location
asTime
converts google.protobuf.Timestamp value to grpc.federation.time.Time value.
asTime() Time
google.protobuf.Timestamp{}.asTime() //=> grpc.federation.time.Time{timestamp: google.protobuf.Timestamp{}}
A Time
represents google.protobuf.Timestamp
with time zone.
FYI: https://pkg.go.dev/time#pkg-constants
string
01/02 03:04:05PM '06 -0700
string
Mon Jan _2 15:04:05 2006
string
Mon Jan _2 15:04:05 MST 2006
string
Mon Jan 02 15:04:05 -0700 2006
string
02 Jan 06 15:04 MST
string
02 Jan 06 15:04 -0700
string
Monday, 02-Jan-06 15:04:05 MST
string
Mon, 02 Jan 2006 15:04:05 MST
string
Mon, 02 Jan 2006 15:04:05 -0700
string
2006-01-02T15:04:05Z07:00
string
2006-01-02T15:04:05.999999999Z07:00
string
3:04PM
string
Jan _2 15:04:05
string
Jan _2 15:04:05.000
string
Jan _2 15:04:05.000000
string
Jan _2 15:04:05.000000000
string
2006-01-02 15:04:05
string
2006-01-02
string
15:04:05
int
1
int
1000 * grpc.federation.time.NANOSECOND
int
1000 * grpc.federation.time.MICROSECOND
int
1000 * grpc.federation.time.MILLISECOND
int
60 * grpc.federation.time.SECOND
int
60 * grpc.federation.time.MINUTE
toDuration
converts int type to Duration
type.
toDuration(var int) Duration
var
: source value
grpc.federation.time.toDuration(10 * grpc.federation.time.SECOND) // 10s
parseDuration
parses 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".
FYI: https://pkg.go.dev/time#ParseDuration
parseDuration(s string) Duration
s
: duration string
grpc.federation.time.parseDuration("1h10m10s")
since
returns the time elapsed since t
. It is shorthand for now().sub(t)
.
FYI: https://pkg.go.dev/time#Since
since(t Time) Duration
t
: time value
grpc.federation.time.since(grpc.federation.time.now())
until
returns the duration until t
. It is shorthand for t.sub(now())
.
until(t Time) Duration
t
: time value
grpc.federation.time.until(grpc.federation.time.now())
abs
returns the absolute value of Duration
. As a special case, <min-int-value>
is converted to <max-int-value>
.
FYI: https://pkg.go.dev/time#Duration.Abs
Duration.abs() Duration
hours
returns the duration as a double type number of hours.
FYI: https://pkg.go.dev/time#Duration.Hours
Duration.hours() double
grpc.federation.time.parseDuration("4h30m").hours() //=> 4.5
microseconds
returns the duration as an integer microsecond count.
FYI: https://pkg.go.dev/time#Duration.Microseconds
Duration.microseconds() int
grpc.federation.time.parseDuration("1s").microseconds() //=> 1000000
milliseconds
returns the duration as an integer millisecond count.
FYI: https://pkg.go.dev/time#Duration.Milliseconds
Duration.milliseconds() int
grpc.federation.time.parseDuration("1s").milliseconds() //=> 1000
minutes
returns the duration as a double type number of minutes.
FYI: https://pkg.go.dev/time#Duration.Minutes
Duration.minutes() double
grpc.federation.time.parseDuration("1h30m").minutes() //=> 90
nanoseconds
returns the duration as an integer nanosecond count.
FYI: https://pkg.go.dev/time#Duration.Nanoseconds
Duration.nanoseconds() int
grpc.federation.time.parseDuration("1µs").nanoseconds() //=> 1000
round
returns the result of rounding Duration
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 Duration
unchanged.
Duration.round(m Duration) Duration
m
: the value for round operation
grpc.federation.time.parseDuration("1h15m30.918273645s").round(grpc.federation.time.MILLISECOND) //=> 1h15m30.918s
seconds
returns the duration as a double type number of seconds.
FYI: https://pkg.go.dev/time#Duration.Seconds
Duration.seconds() double
grpc.federation.time.parseDuration("1m30s").seconds() //=> 90
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.
FYI: https://pkg.go.dev/time#Duration.String
Duration.string() string
grpc.federation.time.toDuration(grpc.federation.time.HOUR + 2*grpc.federatino.time.MINUTE).string() //=> 1h2m
truncate
returns the result of rounding d toward zero to a multiple of m
. If m
<= 0, truncate
returns Duration
unchanged.
FYI: https://pkg.go.dev/time#Duration.Truncate
Duration.truncate(m Duration) Duration
m
: the value for truncate operation
grpc.federation.time.parseDuration("1h15m30.918273645s").truncate(grpc.federation.time.MILLISECOND) //=> 1h15m30.918s
LOCAL
represents the system's local time zone. On Unix systems, LOCAL
consults the TZ environment variable to find the time zone to use. No TZ means use the system default /etc/localtime. TZ="" means use UTC. TZ="foo" means use file foo in the system timezone directory.
LOCAL() Location
UTC
represents Universal Coordinated Time (UTC).
UTC() Location
fixedZone
returns a Location
that always uses the given zone name and offset (seconds east of UTC
).
FYI: https://pkg.go.dev/time#FixedZone
fixedZone(name string, offset int) Location
name
: the zone nameoffset
: the seconds east ofUTC
grpc.federation.time.fixedZone("UTC-8", -8*60*60)
loadLocation
returns the Location
with the given name.
If the name is ""
or "UTC"
, loadLocation
returns UTC
. If the name is "Local"
, loadLocation
returns LOCAL
.
Otherwise, the name is taken to be a location name corresponding to a file in the IANA Time Zone database, such as "America/New_York"
.
FYI: https://pkg.go.dev/time#LoadLocation
loadLocation(name string) Location
grpc.federation.time.loadLocation("America/Los_Angeles")
loadLocationFromTZData
returns a Location
with the given name initialized from the IANA Time Zone database-formatted data. The data should be in the format of a standard IANA time zone file (for example, the content of /etc/localtime on Unix systems).
FYI: https://pkg.go.dev/time#LoadLocationFromTZData
loadLocationFromTZData(name string data bytes) Location
name
: the zone namedata
: the IANA Time Zone database-formatted data
string
returns a descriptive name for the time zone information, corresponding to the name argument to loadLocation
or fixedZone
.
FYI: https://pkg.go.dev/time#Location.String
Location.string() string
date
returns the Time
corresponding to
yyyy-mm-dd hh:mm:ss + nsec nanoseconds
in the appropriate zone for that time in the given location.
FYI: https://pkg.go.dev/time#Date
date(year int, month int, day int, hour int, min int, sec int, nsec int, loc Location) Time
year
: the year numbermonth
: the month numberday
: the day numberhour
: the hour numbermin
: the minute numbersec
: the second numbernsec
: the nanosecond numberloc
: the Location value
grpc.federation.time.date(2009, time.November, 10, 23, 0, 0, 0, grpc.federation.time.UTC()) //=> 2009-11-10 23:00:00 +0000 UTC
now
returns the current local time.
FYI: https://pkg.go.dev/time#Now
now() Time
grpc.federation.time.now()
parse
parses a formatted string and returns the time value it represents. See the documentation for the constant called LAYOUT
to see how to represent the format. The second argument must be parseable using the format string (layout) provided as the first argument.
FYI: https://pkg.go.dev/time#Parse
parse(layout string, value string) Time
grpc.federation.time.parse("2006-Jan-02", "2013-Feb-03")
parseInLocation
is like parse
but differs in two important ways. First, in the absence of time zone information, parse
interprets a time as UTC
; parseInLocation
interprets the time as in the given location. Second, when given a zone offset or abbreviation, parse
tries to match it against the LOCAL
location; parseInLocation
uses the given location.
FYI: https://pkg.go.dev/time#ParseInLocation
parseInLocation(layout string, value string, loc Location) Time
grpc.federation.time.parseInLocation("Jan 2, 2006 at 3:04pm (MST)", "Jul 9, 2012 at 5:02am (CEST)", grpc.federation.time.loadLocation("Europe/Berlin"))
unix
returns the local Time 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).
FYI: https://pkg.go.dev/time#Unix
unix(sec int, nsec int) Time
sec
: the second valuensec
: the nanosecond value
unixMicro
returns the local Time corresponding to the given Unix time, usec microseconds since January 1, 1970 UTC.
FYI: https://pkg.go.dev/time#UnixMicro
unixMicro(usec int) Time
usec
: microseconds since January 1, 1970 UTC.
unixMilli
returns the local Time corresponding to the given Unix time, msec milliseconds since January 1, 1970 UTC.
FYI: https://pkg.go.dev/time#UnixMilli
unixMilli(msec int) Time
msec
: milliseconds since January 1, 1970 UTC.
add
returns the time Time
+d
.
FYI: https://pkg.go.dev/time#Time.Add
Time.add(d Duration) Time
d
: Duration value
addDate
returns the time corresponding to adding the given number of years, months, and days to Time
. For example, addDate(-1, 2, 3)
applied to January 1, 2011 returns March 4, 2010.
addDate
normalizes its result in the same way that Date does, so, for example, adding one month to October 31 yields December 1, the normalized form for November 31.
FYI: https://pkg.go.dev/time#Time.AddDate
Time.addDate(years int, months int, days int) Time
years
: year numbermonths
: month numberdays
: day number
after
reports whether the time instant Time
is after u
.
FYI: https://pkg.go.dev/time#Time.After
Time.after(u Time) bool
u
: the time value to compare
grpc.federation.time.date(3000, 1, 1, 0, 0, 0, 0, grpc.federation.time.UTC()).after(grpc.federation.time.date(2000, 1, 1, 0, 0, 0, 0, grpc.federation.time.UTC())) //=> true
appendFormat
is like Format but appends the textual representation to b
and returns the extended buffer.
FYI: https://pkg.go.dev/time#Time.AppendFormat
Time.appendFormat(b bytes, layout string) string
Time.appendFormat(s string, layout string) string
grpc.federation.time.date(2017, 11, 4, 11, 0, 0, 0, grpc.federation.time.UTC()).appendFormat("Time: ", grpc.federation.time.KITCHEN) //=> Time: 11:00AM
before
reports whether the time instant Time
is before u
.
FYI: https://pkg.go.dev/time#Time.Before
Time.before(u Time) bool
u
: the time value to compare
grpc.federation.time.date(2000, 1, 1, 0, 0, 0, 0, grpc.federation.time.UTC()).before(grpc.federation.time.date(3000, 1, 1, 0, 0, 0, 0, grpc.federation.time.UTC())) //=> true
compare
compares the time instant Time
with u
. If Time
is before u
, it returns -1
; if Time
is after u
, it returns +1
; if they're the same, it returns 0
.
FYI: https://pkg.go.dev/time#Time.Compare
Time.compare(u Time) int
u
: the time value to compare
day
returns the day of the month specified by Time
.
FYI: https://pkg.go.dev/time#Time.Day
Time.day() int
grpc.federation.time.date(2000, 2, 1, 12, 30, 0, 0, grpc.federation.time.UTC()).day() //=> 1
equal
reports whether Time
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.
FYI: https://pkg.go.dev/time#Time.Equal
Time.equal(u Time) bool
grpc.federation.time.date(2000, 2, 1, 12, 30, 0, 0, grpc.federation.time.UTC()).equal(grpc.federation.time.date(2000, 2, 1, 20, 30, 0, 0, grpc.federation.time.fixedZone('Beijing Time', grpc.federation.time.toDuration(8 * grpc.federation.time.HOUR).seconds()))) //=> true
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.
FYI: https://pkg.go.dev/time#Time.Format
Time.format(layout string) string
layout
: the layout value to format
hour
returns the hour within the day specified by Time
, in the range [0, 23].
FYI: https://pkg.go.dev/time#Time.Hour
Time.hour() int
withLocation
returns a copy of Time
representing the same time instant, but with the copy's location information set to loc for display purposes.
FYI: https://pkg.go.dev/time#Time.In
Time.withLocation(loc Location) Time
isDST
reports whether the time in the configured location is in Daylight Savings Time.
FYI: https://pkg.go.dev/time#Time.IsDST
Time.isDST() bool
isZero
reports whether Time
represents the zero time instant, January 1, year 1, 00:00:00 UTC.
FYI: https://pkg.go.dev/time#Time.IsZero
Time.isZero() bool
local
returns Time
with the location set to local time.
FYI: https://pkg.go.dev/time#Time.Local
Time.local() Time
location
returns the time zone information associated with Time
.
FYI: https://pkg.go.dev/time#Time.Location
Time.location() Location
minute
returns the minute offset within the hour specified by Time
, in the range [0, 59].
FYI: https://pkg.go.dev/time#Time.Minute
Time.minute() int
month
returns the month of the year specified by Time
.
FYI: https://pkg.go.dev/time#Time.Month
Time.month() int
nanosecond
returns the nanosecond offset within the second specified by Time
, in the range [0, 999999999].
FYI: https://pkg.go.dev/time#Time.Nanosecond
Time.nanosecond() int
round
returns the result of rounding Time
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 Time
stripped of any monotonic clock reading but otherwise unchanged.
round
operates on the time as an absolute duration since the zero time; it does not operate on the presentation form of the time. Thus, round(grpc.federation.time.HOUR)
may return a time with a non-zero minute, depending on the time's Location.
FYI: https://pkg.go.dev/time#Time.Round
Time.round(d Duration) Time
d
: the duration value
grpc.federation.time.date(0, 0, 0, 12, 15, 30, 918273645, grpc.federation.time.UTC()).round(grpc.federation.time.MILLISECOND).format("15:04:05.999999999") //=> 12:15:30.918
second
returns the second offset within the minute specified by Time
, in the range [0, 59].
FYI: https://pkg.go.dev/time#Time.Second
Time.second() int
string
returns the time formatted using the format string.
"2006-01-02 15:04:05.999999999 -0700 MST"
If the time has a monotonic clock reading, the returned string includes a final field "m=±", where value is the monotonic clock reading formatted as a decimal number of seconds.
FYI: https://pkg.go.dev/time#Time.String
Time.string() string
sub
returns the duration Time
-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 Time
-d
for a duration d
, use Time.add(-d)
.
FYI: https://pkg.go.dev/time#Time.Sub
Time.sub(u Time) Duration
u
: the time value
grpc.federation.time.date(2000, 1, 1, 12, 0, 0, 0, grpc.federation.time.UTC()).sub(grpc.federation.time.date(2000, 1, 1, 0, 0, 0, 0, grpc.federation.time.UTC())) //=> 12h0m0s
truncate
returns the result of rounding Time
down to a multiple of d
(since the zero time). If d
<= 0, truncate
returns Time
stripped of any monotonic clock reading but otherwise unchanged.
truncate
operates on the time as an absolute duration since the zero time; it does not operate on the presentation form of the time. Thus, truncate(grpc.federation.time.HOUR)
may return a time with a non-zero minute, depending on the time's Location.
FYI: https://pkg.go.dev/time#Time.Truncate
Time.truncate(d Duration) Time
d
: since the zero time
grpc.federation.time.parse("2006 Jan 02 15:04:05", "2012 Dec 07 12:15:30.918273645").truncate(grpc.federation.time.MILLISECOND).format("15:04:05.999999999") //=> 12:15:30.918
utc
returns Time
with the location set to UTC.
FYI: https://pkg.go.dev/time#Time.UTC
Time.utc() Time
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 Time
. 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.
FYI: https://pkg.go.dev/time#Time.Unix
Time.unix() int
unixMicro
returns Time
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 Time
.
FYI: https://pkg.go.dev/time#Time.UnixMicro
Time.unixMicro() int
unixMilli
returns Time
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 Time
.
FYI: https://pkg.go.dev/time#Time.UnixMilli
Time.unixMilli() int
unixNano
returns Time
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 Time
.
FYI: https://pkg.go.dev/time#Time.UnixNano
Time.unixNano() int
weekday
returns the day of the week specified by Time
.
FYI: https://pkg.go.dev/time#Time.Weekday
Time.weekday() int
year
returns the year in which Time
occurs.
FYI: https://pkg.go.dev/time#Time.Year
Time.year() int
yearDay
returns the day of the year specified by Time
, in the range [1,365] for non-leap years, and [1,366] in leap years.
FYI: https://pkg.go.dev/time#Time.YearDay
Time.yearDay() int