Skip to content

Commit

Permalink
time: add time module (google#327)
Browse files Browse the repository at this point in the history
* time: add time module

Signed-off-by: b5 <[email protected]>

* time: adjust package API

move parsing functions:
  time.time     -> time.parse_time
  time.duration -> time.parse_duration

make `time.time` a constructor function that wraps golang's `time.Date`

make `time.duration` a constructor funciton that accepts a single param of type
int, string, or duration

rename time.fromtimestamp -> time.from_timestamp

make time.time unit accessors fields instead of methods:
  t.year() -> t.year
  t.month() -> t.month
  t.day() -> t.day
  t.hour() -> t.hour
  t.minute() -> t.minute
  t.second() -> t.second
  t.nanosecond() -> t.nanosecond
  t.unix() -> t.unix
  t.unix_nano() -> t.unix_nano

make time.duration unit accessors fields instead of methods:
  d.hours() -> d.hours
  d.minutes() -> d.minutes
  d.seconds() -> d.seconds
  d.nanoseconds() -> d.nanoseconds

* perf(time): don't allocate int on time & duration Hash methods

* time: apply remarks

* time: Use int64 instead of int as type of argument

* time: Remove the file doc.go as it is not compliant with the current doc convention

* time: Applied remarks

* time: Applied remarks

* time: Set the correct name of the functions

Co-authored-by: essobedo <[email protected]>
  • Loading branch information
b5 and essobedo authored Mar 5, 2021
1 parent e043a3d commit 6a590ae
Show file tree
Hide file tree
Showing 4 changed files with 646 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cmd/starlark/starlark.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"strings"

"go.starlark.net/internal/compile"
"go.starlark.net/lib/time"
"go.starlark.net/repl"
"go.starlark.net/resolve"
"go.starlark.net/starlark"
Expand Down Expand Up @@ -91,6 +92,7 @@ func doMain() int {
// Ideally this statement would update the predeclared environment.
// TODO(adonovan): plumb predeclared env through to the REPL.
starlark.Universe["json"] = starlarkjson.Module
starlark.Universe["time"] = time.Module

switch {
case flag.NArg() == 1 || *execprog != "":
Expand Down
Loading

0 comments on commit 6a590ae

Please sign in to comment.