Sub second time resolution (#6978)

* Add deprecation warnings to recently deprecated procs

* Fix bad usage of the times module

* Introduce sub second resolution

* Fix usage of C's time()

* Switch to nanosecond resolution

* Make Time & Duration opaque again and fix some errors

* Change back to TimeInterval for shorthands

* Fix JS test

* Fix build error for windows

* Undeprecate epochTime

* Documentation and minor changes

* Lots of bugfixes and doc comments

* Attempt to make travis & appveyor green

* Fix edge cases for dealing with the local timezone

* Workaround JS backend overflow/underflow bug

* Use better workaround for not knowing the size of time_t

* Use all available timezones for tests

* Fix indentation

* Add procs for accessing the fractional part of a duration

* Order time units from smallest to largest since it makes more sense

* Include months and years in `TimeUnit`

* Review fix
This commit is contained in:
Oscar Nihlgård
2018-04-13 07:36:31 +02:00
committed by Andreas Rumpf
parent 19a1cc914f
commit f6df2d9956
7 changed files with 699 additions and 296 deletions

View File

@@ -71,7 +71,7 @@ proc genOid*(): Oid =
proc rand(): cint {.importc: "rand", header: "<stdlib.h>", nodecl.}
proc srand(seed: cint) {.importc: "srand", header: "<stdlib.h>", nodecl.}
var t = getTime().int32
var t = getTime().toUnix.int32
var i = int32(atomicInc(incr))

View File

@@ -225,10 +225,10 @@ proc fileNewer*(a, b: string): bool {.rtl, extern: "nos$1".} =
## Returns true if the file `a` is newer than file `b`, i.e. if `a`'s
## modification time is later than `b`'s.
when defined(posix):
result = getLastModificationTime(a) - getLastModificationTime(b) >= 0
result = getLastModificationTime(a) - getLastModificationTime(b) >= DurationZero
# Posix's resolution sucks so, we use '>=' for posix.
else:
result = getLastModificationTime(a) - getLastModificationTime(b) > 0
result = getLastModificationTime(a) - getLastModificationTime(b) > DurationZero
proc getCurrentDir*(): string {.rtl, extern: "nos$1", tags: [].} =
## Returns the `current working directory`:idx:.

View File

@@ -191,8 +191,8 @@ when not defined(nimscript):
proc randomize*() {.benign.} =
## Initializes the random number generator with a "random"
## number, i.e. a tickcount. Note: Does not work for NimScript.
let time = int64(times.epochTime() * 1_000_000_000)
randomize(time)
let now = times.getTime()
randomize(convert(Seconds, Nanoseconds, now.toUnix) + now.nanoseconds)
{.pop.}

File diff suppressed because it is too large Load Diff