-
Notifications
You must be signed in to change notification settings - Fork 6
The time library
The time library wraps around the Go time library.
The data types are somewhat different. Durations are simply given as integers; the Time type is an ordinary struct; and the Weekday enum has its elements in SCREAMING_SNAKE_CASE:
Time = struct(year, month, day, hour, min, sec, nsec int, loc string)
Weekday = enum SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY
The API varies from the Go time library in the usual systematic ways: there are no methods, these being replaced by functions; the names of functions are in camelCase. So t.YearDay() becomes yearDay(t).
Besides this, the various methods and functions competing to be called UnixMilli, etc, are now more verbosely called timeToUnixMilli and unixMilliToTime, etc, to make the direction of conversion explicit. The In method has been renamed timeIn.
This gives us functions with the following signatures (all duration parameters being expressed in nanoseconds):
add (t Time, duration int) -> TimeaddDate(t Time, years, months, days int) -> Timeafter(t, u Time) -> boolbefore(t, u Time) -> boolcompare(t, u Time) -> intequal(t, u Time) -> boolformat(t Time, layout string) -> stringisDst(t Time) -> boolisoWeek(t Time) -> intisZero(t Time) -> boollocal(t Time) -> Timeparse(layout, value string) -> TimeparseDuration(s string) -> intround(t Time, duration int) -> Timesub(t, u Time) -> inttimeIn(t Time, location string) -> TimetimeToUnix(t Time) -> inttimeToUnixMicro(t Time) -> inttimeToUnixMilli(t Time) -> inttimeToUnixNano(t Time) -> inttruncate(t Time, duration int) -> TimeunixToTime(sec, usec int) -> TimeunixMicroToTime(usec int) -> TimeunixMilliToTime(msec int) -> Timeutc(t Time) -> Timeweekday(t Time) -> WeekdayyearDay(t Time) -> int
You may be wondering how you get the present time. That's in the automatically-imported, null-namespaced world library (see the page on Basic IO for more details). As getting the time is impure, you can only do it in the command section of your script, using get <variable name> from Clock().
🧿 Pipefish is distributed under the MIT license. Please steal my code and ideas.
- Getting started
- Language basics
- The type system and built-in functions
- Functional Pipefish
- Encapsulation
- Imperative Pipefish
-
Imports and libraries
- The files library
- The fmt library
- The html library
- The math library
- The math/big library
- The math/cmplx library
- The math/rand library
- The path library
- The path/filepath library
- The reflect library
- The regexp library
- The sql library
- The strings library
- The terminal library
- The time library
- The unicode library
- Advanced Pipefish
- Developing in Pipefish
- Deployment
- Appendices