mirror of
https://github.com/GULPF/systimes
synced 2026-01-08 05:01:17 +00:00
No description
| docs | ||
| .gitignore | ||
| LICENSE | ||
| README.md | ||
| systimes.nim | ||
| systimes.nimble | ||
| tests.nim | ||
systimes
The systimes module implements an alternative way to represent a timestamp + timezone. Nim's standard library uses the DateTime type to represent the same thing. There are two important differences between DateTime and SysTime:
SysTimeis immutable.SysTimeonly stores atimes.Timeand atimes.Timezone, meaning that individual calendar fields like year, month and so on are never stored.
Some things to keep in mind:
- When the calendar fields are accessed several times for the same object, there is a performance penalty when using
SysTimesince they must be computed at every access. - Many procs are faster for
SysTime. Notably all procs involvingDurationsince they no longer require timezone information. - Some procs are slower for
SysTime. Notably all procs involvingTimeInterval. SysTimeis much more space effecient.
The name SysTime comes from the SysTime class from Phobos, which uses a similiar representation for timestamp + timezone.
Usage
import systimes, times
let x = sysnow()
let y = initSysTime(01, mJan, 2000, 12, 00, 00, utc())
doAssert x > y
doAssert x < y + 10.years
echo y # 2000-01-01T12:00:00Z
systimes exposes a very similiar API for SysTime as the times module does for DateTime. Notable differences are listed in the table below. Generated docs are available here.
| DateTime | SysTime |
|---|---|
now() |
sysnow() |
parse(input, format) |
parseSysTime(input, format) |
time.inZone(zone) |
initSysTime(time, zone) |
initDateTime(...) |
initSysTime(...) |