No description
Find a file
2020-03-30 19:03:49 +02:00
docs Docs 2018-08-24 15:30:02 +02:00
.gitignore Initial commit 2018-07-31 09:23:31 +02:00
LICENSE Initial commit 2018-07-31 09:23:31 +02:00
README.md Update README.md 2020-03-30 19:03:49 +02:00
systimes.nim Docs 2018-08-24 15:30:02 +02:00
systimes.nimble Fix nimble file 2018-08-24 15:40:34 +02:00
tests.nim Import style 2018-08-18 08:53:05 +02:00

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:

  • SysTime is immutable.
  • SysTime only stores a times.Time and a times.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 SysTime since they must be computed at every access.
  • Many procs are faster for SysTime. Notably all procs involving Duration since they no longer require timezone information.
  • Some procs are slower for SysTime. Notably all procs involving TimeInterval.
  • SysTime is 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(...)