time

package
v0.0.0-...-c05ff20 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 25, 2024 License: BSD-3-Clause Imports: 7 Imported by: 49

Documentation

Overview

Package time provides time-related constants and functions.

Index

Constants

This section is empty.

Variables

View Source
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.
View Source
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

func Now

func Now(thread *starlark.Thread) func() (time.Time, error)

Now returns the clock function previously associated with this thread.

func SetNow

func SetNow(thread *starlark.Thread, nowFunc func() (time.Time, error))

SetNow sets the thread's optional clock function. If non-nil, it will be used in preference to NowFunc when the thread requests the current time by executing a call to time.now.

Types

type Duration

type Duration time.Duration

Duration is a Starlark representation of a duration.

func (Duration) Attr

func (d Duration) Attr(name string) (starlark.Value, error)

Attr gets a value for a string attribute, implementing dot expression support in starklark. required by starlark.HasAttrs interface.

func (Duration) AttrNames

func (d Duration) AttrNames() []string

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

func (d Duration) Cmp(v starlark.Value, depth int) (int, error)

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

func (d Duration) Hash() (uint32, error)

Hash returns a function of x such that Equals(x, y) => Hash(x) == Hash(y) required by starlark.Value interface.

func (Duration) String

func (d Duration) String() string

String implements the Stringer interface.

func (Duration) Truth

func (d Duration) Truth() starlark.Bool

Truth reports whether the duration is non-zero.

func (Duration) Type

func (d Duration) Type() string

Type returns a short string describing the value's type.

func (*Duration) Unpack

func (d *Duration) Unpack(v starlark.Value) error

Unpack is a custom argument unpacker

type Time

type Time time.Time

Time is a Starlark representation of a moment in time.

func (Time) Attr

func (t Time) Attr(name string) (starlark.Value, error)

Attr gets a value for a string attribute, implementing dot expression support in starklark. required by starlark.HasAttrs interface.

func (Time) AttrNames

func (t Time) AttrNames() []string

AttrNames lists available dot expression strings for time. required by starlark.HasAttrs interface.

func (Time) Binary

func (t Time) Binary(op syntax.Token, y starlark.Value, side starlark.Side) (starlark.Value, error)

Binary implements binary operators, which satisfies the starlark.HasBinary interface

time + duration = time
time - duration = time
time - time = duration

func (Time) Cmp

func (t Time) Cmp(yV starlark.Value, depth int) (int, error)

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

func (t Time) Hash() (uint32, error)

Hash returns a function of x such that Equals(x, y) => Hash(x) == Hash(y) required by starlark.Value interface.

func (Time) String

func (t Time) String() string

String returns the time formatted using the format string

"2006-01-02 15:04:05.999999999 -0700 MST".

func (Time) Truth

func (t Time) Truth() starlark.Bool

Truth returns the truth value of an object required by starlark.Value interface.

func (Time) Type

func (t Time) Type() string

Type returns "time.time".

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL