Skip to content

Commit

Permalink
More time.* functions
Browse files Browse the repository at this point in the history
- time.date to construct a time object (variadic, from 1 to 8 args)
- time.location to extract location from a time
- time.loadlocation to create a location object by looking up in IANA
dictionary data on the given system
- time.fixedzone to create a location object by hand, given name and
offset-seconds-from-UTC
- time.locationname to get a string repr. of a location

This should round out the Go time pkg functions that are necessary to do
most date/time manipulation from Goal.
  • Loading branch information
semperos committed Oct 11, 2024
1 parent 6e11514 commit da2da82
Show file tree
Hide file tree
Showing 3 changed files with 407 additions and 40 deletions.
18 changes: 15 additions & 3 deletions goal.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,15 @@ import (
)

const (
monadic = 1
dyadic = 2
triadic = 3
monadic = 1
dyadic = 2
triadic = 3
quadratic = 4
tesseradic = 4
pentadic = 5
hexadic = 6
heptadic = 7
octadic = 8
)

// Goal Preamble in Goal
Expand Down Expand Up @@ -174,12 +180,16 @@ func goalRegisterVariadics(ariContext *Context, goalContext *goal.Context, help
// From Goal itself, os lib imported without prefix
gos.Import(goalContext, "")
// Ari
goalContext.RegisterExtension("ari", "v0.1.1")
// Monads
goalContext.RegisterMonad("rtnames", VFRTNames)
goalContext.RegisterMonad("sql.close", VFSqlClose)
goalContext.RegisterMonad("sql.open", VFSqlOpen)
goalContext.RegisterMonad("time.day", VFTimeDay)
goalContext.RegisterMonad("time.hour", VFTimeHour)
goalContext.RegisterMonad("time.loadlocation", VFTimeLoadLocation)
goalContext.RegisterMonad("time.location", VFTimeLocation)
goalContext.RegisterMonad("time.locationname", VFTimeLocationName)
goalContext.RegisterMonad("time.microsecond", VFTimeMicrosecond)
goalContext.RegisterMonad("time.millisecond", VFTimeMillisecond)
goalContext.RegisterMonad("time.minute", VFTimeMinute)
Expand Down Expand Up @@ -212,6 +222,8 @@ func goalRegisterVariadics(ariContext *Context, goalContext *goal.Context, help
goalContext.RegisterDyad("sql.q", VFSqlQFn(sqlDatabase))
goalContext.RegisterDyad("sql.exec", VFSqlExecFn(sqlDatabase))
goalContext.RegisterDyad("time.add", VFTimeAdd)
goalContext.RegisterDyad("time.date", VFTimeDate)
goalContext.RegisterDyad("time.fixedzone", VFTimeFixedZone)
goalContext.RegisterDyad("time.format", VFTimeFormat)
goalContext.RegisterDyad("time.parse", VFTimeParse)
goalContext.RegisterDyad("time.sub", VFTimeSub)
Expand Down
15 changes: 13 additions & 2 deletions testing/time-test.goal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
tt.t{"Mon Jan _2 15:04:05 MST 2006"~time.UnixDate}; ft:time.RFC3339
t1:time.parse[ft;"2019-12-31T23:59:58.123456789Z"];t2:time.parse[ft;"2020-01-01T00:00:00Z"]
tt.t{"Mon Jan _2 15:04:05 MST 2006"~time.UnixDate}; ft:time.RFC3339; pt:time.parse[ft;]
t1:pt@"2019-12-31T23:59:58.123456789Z";t2:pt@"2020-01-01T00:00:00Z"
tt.t{2=time.weekday t1} / Tuesday
tt.t{3=time.weekday t2} / Wednesday
tt.t{365=time.yearday t1}
Expand Down Expand Up @@ -27,3 +27,14 @@ tt.t{1e9~time.unixnano time.parse[ft;"1970-01-01T00:00:01Z"]}
tt.t{0=time.zoneoffset t1}
tt.t{"UTC"~time.zonename t1}
tt.t{-18000=time.zoneoffset time.parse[ft;"2020-01-01T00:00:00-05:00"]}
tt.t{t1~time.date[2019;12;31;23;59;58;123456789;time.UTC]}
tt.t{pt["2019-01-01T00:00:00.000000000Z"]~time.date[2019]}
tt.t{pt["2019-02-01T00:00:00.000000000Z"]~time.date[2019;2]}
tt.t{pt["2019-02-03T00:00:00.000000000Z"]~time.date[2019;2;3]}
tt.t{pt["2019-02-03T04:00:00.000000000Z"]~time.date[2019;2;3;4]}
tt.t{pt["2019-02-03T04:05:00.000000000Z"]~time.date[2019;2;3;4;5]}
tt.t{pt["2019-02-03T04:05:06.000000000Z"]~time.date[2019;2;3;4;5;6]}
tt.t{pt["2019-02-03T04:05:06.789000000Z"]~time.date[2019;2;3;4;5;6;789000000]}
utc8:time.fixedzone["UTC-8";*/-8 60 60]
tt.t{time.parse[time.RFC822Z;"03 Feb 19 04:05 -0800"]~time.date[2019;2;3;4;5;0;0;utc8]}
tt.t{"UTC-8"~time.locationname utc8}
Loading

0 comments on commit da2da82

Please sign in to comment.