times
nimony/lib/std/times.nim
The std/times module provides basic support for working with time.
This is a minimal implementation for Nimony: it covers Unix-epoch based points in time with nanosecond resolution, simple durations, and a calendar breakdown for UTC. For monotonic timestamps suitable for measuring durations, use std/monotimes.
type Month = HoleyEnumfunc dollar`.Month(e: Month): stringtype WeekDay = enum dMon = (0, "dMon") dTue = (1, "dTue") dWed = (2, "dWed") dThu = (3, "dThu") dFri = (4, "dFri") dSat = (5, "dSat") dSun = (6, "dSun")
func dollar`.WeekDay(e: WeekDay): stringtype Time = object seconds: int64 nanosecond: int32
type Duration = object seconds: int64 nanosecond: int32
type DateTime = object year: int64 month: Month monthday: int32 hour: int32 minute: int32 second: int32 nanosecond: int32 weekday: WeekDay yearday: int32
func initTime(seconds: int64; nanoseconds: int64): TimeCreates a new
Timefrom a Unix timestamp.func fromUnix(unix: int64): TimeConvert a Unix timestamp (seconds since 1970-01-01 UTC) to a
Time.func toUnix(t: Time): int64Converts
tto a Unix timestamp.func seconds(t: Time): int64func nanosecond(t: Time): int32func initDuration(seconds: int64; nanoseconds: int64; milliseconds: int64; microseconds: int64; minutes: int64; hours: int64; days: int64; weeks: int64): DurationCreates a new
Duration.func inSeconds(d: Duration): int64func inMilliseconds(d: Duration): int64func inMicroseconds(d: Duration): int64func inNanoseconds(d: Duration): int64func ==(a: Time; b: Time): boolfunc <(a: Time; b: Time): boolfunc <=(a: Time; b: Time): boolfunc ==(a: Duration; b: Duration): boolfunc <(a: Duration; b: Duration): boolfunc <=(a: Duration; b: Duration): boolfunc -(a: Time; b: Time): DurationReturns the duration between two times.
func +(t: Time; d: Duration): TimeAdds a duration to a time.
func -(t: Time; d: Duration): TimeSubtracts a duration from a time.
proc getTime(): TimeGets the current time as a
Timewith up to nanosecond resolution.func isLeapYear(year: int64): boolReturns true if
yearis a leap year in the proleptic Gregorian calendar.func getDaysInMonth(month: Month; year: int64): int32Get the number of days in
monthofyear.func utc(t: Time): DateTimeConverts a
Timeto aDateTimein UTC.func initDateTime(year: int64; month: Month; monthday: int32; hour: int32; minute: int32; second: int32; nanosecond: int32): DateTimeCreates a new
DateTimein UTC.func toTime(dt: DateTime): TimeConverts a
DateTimeto aTime. TheDateTimeis assumed to be in UTC.proc now(): DateTimeReturns the current UTC date and time.
func $(dt: DateTime): stringConverts a
DateTimeto ISO-8601 format:YYYY-MM-DDTHH:MM:SS.func $(t: Time): stringfunc $(d: Duration): stringFormats a
DurationasNs M.N(seconds.nanoseconds).