Documentation ¶
Overview ¶
Package time provides time-related constants and functions.
Index ¶
- Variables
- func Now(thread *starlark.Thread) func() (time.Time, error)
- func SetNow(thread *starlark.Thread, nowFunc func() (time.Time, error))
- type Duration
- func (d Duration) Attr(name string) (starlark.Value, error)
- func (d Duration) AttrNames() []string
- func (d Duration) Binary(op syntax.Token, y starlark.Value, side starlark.Side) (starlark.Value, error)
- func (d Duration) Cmp(v starlark.Value, depth int) (int, error)
- func (d Duration) Freeze()
- func (d Duration) Hash() (uint32, error)
- func (d Duration) String() string
- func (d Duration) Truth() starlark.Bool
- func (d Duration) Type() string
- func (d *Duration) Unpack(v starlark.Value) error
- type Time
- func (t Time) Attr(name string) (starlark.Value, error)
- func (t Time) AttrNames() []string
- func (t Time) Binary(op syntax.Token, y starlark.Value, side starlark.Side) (starlark.Value, error)
- func (t Time) Cmp(yV starlark.Value, depth int) (int, error)
- func (t Time) Freeze()
- func (t Time) Hash() (uint32, error)
- func (t Time) String() string
- func (t Time) Truth() starlark.Bool
- func (t Time) Type() string
Constants ¶
This section is empty.
Variables ¶
var Module = &starlarkstruct.Module{ Name: "time", Members: starlark.StringDict{ "from_timestamp": starlark.NewBuiltin("from_timestamp", fromTimestamp), "is_valid_timezone": starlark.NewBuiltin("is_valid_timezone", isValidTimezone), "now": starlark.NewBuiltin("now", now), "parse_duration": starlark.NewBuiltin("parse_duration", parseDuration), "parse_time": starlark.NewBuiltin("parse_time", parseTime), "time": starlark.NewBuiltin("time", newTime), "nanosecond": Duration(time.Nanosecond), "microsecond": Duration(time.Microsecond), "millisecond": Duration(time.Millisecond), "second": Duration(time.Second), "minute": Duration(time.Minute), "hour": Duration(time.Hour), }, }
Module time is a Starlark module of time-related functions and constants. The module defines the following functions:
from_timestamp(sec, nsec) - Converts the given Unix time corresponding to the number of seconds and (optionally) nanoseconds since January 1, 1970 UTC into an object of type Time. For more details, refer to https://pkg.go.dev/time#Unix. is_valid_timezone(loc) - Reports whether loc is a valid time zone name. now() - Returns the current local time. Applications may replace this function by a deterministic one. parse_duration(d) - Parses the given duration string. For more details, refer to https://pkg.go.dev/time#ParseDuration. parse_time(x, format, location) - Parses the given time string using a specific time format and location. The expected arguments are a time string (mandatory), a time format (optional, set to RFC3339 by default, e.g. "2021-03-22T23:20:50.52Z") and a name of location (optional, set to UTC by default). For more details, refer to https://pkg.go.dev/time#Parse and https://pkg.go.dev/time#ParseInLocation. time(year, month, day, hour, minute, second, nanosecond, location) - Returns the Time corresponding to yyyy-mm-dd hh:mm:ss + nsec nanoseconds in the appropriate zone for that time in the given location. All the parameters are optional.
The module also defines the following constants:
nanosecond - A duration representing one nanosecond. microsecond - A duration representing one microsecond. millisecond - A duration representing one millisecond. second - A duration representing one second. minute - A duration representing one minute. hour - A duration representing one hour.
var NowFunc = time.Now
NowFunc is a function that reports the current time. Intentionally exported so that it can be overridden, for example by applications that require their Starlark scripts to be fully deterministic.
Deprecated: avoid updating this global variable and instead use SetNow on each thread to set its clock function.
Functions ¶
Types ¶
type Duration ¶
Duration is a Starlark representation of a duration.
func (Duration) Attr ¶
Attr gets a value for a string attribute, implementing dot expression support in starklark. required by starlark.HasAttrs interface.
func (Duration) AttrNames ¶
AttrNames lists available dot expression strings. required by starlark.HasAttrs interface.
func (Duration) Binary ¶
func (d Duration) Binary(op syntax.Token, y starlark.Value, side starlark.Side) (starlark.Value, error)
Binary implements binary operators, which satisfies the starlark.HasBinary interface. operators:
duration + duration = duration duration + time = time duration - duration = duration duration / duration = float duration / int = duration duration / float = duration duration // duration = int duration * int = duration
func (Duration) Cmp ¶
Cmp implements comparison of two Duration values. required by starlark.TotallyOrdered interface.
func (Duration) Freeze ¶
func (d Duration) Freeze()
Freeze renders Duration immutable. required by starlark.Value interface because duration is already immutable this is a no-op.
func (Duration) Hash ¶
Hash returns a function of x such that Equals(x, y) => Hash(x) == Hash(y) required by starlark.Value interface.
type Time ¶
Time is a Starlark representation of a moment in time.
func (Time) Attr ¶
Attr gets a value for a string attribute, implementing dot expression support in starklark. required by starlark.HasAttrs interface.
func (Time) AttrNames ¶
AttrNames lists available dot expression strings for time. required by starlark.HasAttrs interface.
func (Time) Binary ¶
Binary implements binary operators, which satisfies the starlark.HasBinary interface
time + duration = time time - duration = time time - time = duration
func (Time) Cmp ¶
Cmp implements comparison of two Time values. Required by starlark.TotallyOrdered interface.
func (Time) Freeze ¶
func (t Time) Freeze()
Freeze renders time immutable. required by starlark.Value interface because Time is already immutable this is a no-op.
func (Time) Hash ¶
Hash returns a function of x such that Equals(x, y) => Hash(x) == Hash(y) required by starlark.Value interface.
func (Time) String ¶
String returns the time formatted using the format string
"2006-01-02 15:04:05.999999999 -0700 MST".