chrono/timestamps
If you are going to just parse or format dates. I recommend using just the import chrono/timestamps module. It it imports the Timestamp that is enough for most cases involved with times. I always recommend storing dates as a float64 number of seconds since 1970. This is exactly what Timestamp is. When you need to parse it or display it use parseTs or formatTs.
var ts = parseTs( "{year/4}-{month/2}-{day/2}T{hour/2}:{minute/2}:{second/2}Z", "1988-02-09T03:34:12Z" )
echo ts
echo formatTs( ts, "{year/4}-{month/2}-{day/2}T{hour/2}:{minute/2}:{second/2}Z", )
If you need to parse ISO dates which is a very common format you find all over the internet. You can even use faster optimized versions here:
echo parseIsoTs("2017-11-08T08:01:43Z") echo Timestamp(1510128103.0).formatIso()
Procs
proc parseIsoTs(iso: string): Timestamp {....raises: [ValueError], tags: [], forbids: [].}
- Fastest way to convert an ISO 8601 string representation to a Timestamp. Use this instead of the parseTimestamp function when dealing with ISO format. Source Edit