forked from qri-io/starlib
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdoc.go
More file actions
112 lines (107 loc) · 4.36 KB
/
doc.go
File metadata and controls
112 lines (107 loc) · 4.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*Package time provides time-related constants and functions. The time module
was upstreamed from starlib into go-Starlark. This package exists to add
documentation. The API is locked to strictly match the Starlark module.
Users are encouraged to import the time package directly via:
go.starlark.net/lib/time
For source code see
https://github.com/google/starlark-go/tree/master/lib/time
outline: time
time is a Starlark module of time-related functions and constants.
path: time
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: duration representing one hour.
functions:
from_timestamp(sec, nsec) Time
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.
is_valid_timezone(loc) boolean
Reports whether loc is a valid time zone name.
now() time
Returns the current local time
parse_duration(d) Duration
Parses the given 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".
parse_time(x, format, location) Time
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?) Time
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
parameters are optional.
types:
Duration
fields:
hours float
minutes float
seconds float
milliseconds int
microseconds int
nanoseconds int
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
Time
Time represents an instant in time with nanosecond precision. Each Time
has associated with it a Location, consulted when computing the
presentation form of the time, such as in the Format, Hour, and Year
methods.
fields:
year int
month int
day int
hour int
minute int
second int
nanosecond int
unix int
unix_nano int
functions:
in_location(locstr) Time
get time representing the same instant but in a different location
format() string
textual representation of time formatted according to the provided
layout string: 01/02 03:04:05PM '06 -0700 (January 2, 15:04:05, 2006,
in time zone seven hours west of GMT)
examples:
ISO timestamp
construct an ISO tiemstamp using the template string
code:
load("time.star", "time")
# create a time object: January 1st 2021 at midnight
timestamp = time.time(year=2021)
# use layout string to construct an RFC3339 timestamp string,
# which is what JSON serializers often use
formatted = timestamp.format("2006-01-02T15:04:05Z07:00")
print(timestamp)
# Output: 2020-11-30 00:00:00 +0000 UTC
operators:
time + duration = time
time - duration = time
time - time = duration
*/
package time
import "go.starlark.net/lib/time"
// ModuleName declares the intended load import string
// eg: load("time.star", "time")
const ModuleName = "time.star"
// Module exposes the time module. Implementation located at
// https://github.com/google/starlark-go/tree/master/lib/time
var Module = time.Module