Skip to content

Commit f6df2d9

Browse files
GULPFAraq
authored andcommitted
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
1 parent 19a1cc9 commit f6df2d9

File tree

7 files changed

+700
-297
lines changed

7 files changed

+700
-297
lines changed

compiler/scriptconfig.nim

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,7 @@ proc setupVM*(module: PSym; cache: IdentCache; scriptName: string;
7777
cbos copyDir:
7878
os.copyDir(getString(a, 0), getString(a, 1))
7979
cbos getLastModificationTime:
80-
# depends on Time's implementation!
81-
setResult(a, int64(getLastModificationTime(getString(a, 0))))
80+
setResult(a, getLastModificationTime(getString(a, 0)).toUnix)
8281
cbos findExe:
8382
setResult(a, os.findExe(getString(a, 0)))
8483

lib/pure/oids.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ proc genOid*(): Oid =
7171
proc rand(): cint {.importc: "rand", header: "<stdlib.h>", nodecl.}
7272
proc srand(seed: cint) {.importc: "srand", header: "<stdlib.h>", nodecl.}
7373

74-
var t = getTime().int32
74+
var t = getTime().toUnix.int32
7575

7676
var i = int32(atomicInc(incr))
7777

lib/pure/os.nim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,10 +225,10 @@ proc fileNewer*(a, b: string): bool {.rtl, extern: "nos$1".} =
225225
## Returns true if the file `a` is newer than file `b`, i.e. if `a`'s
226226
## modification time is later than `b`'s.
227227
when defined(posix):
228-
result = getLastModificationTime(a) - getLastModificationTime(b) >= 0
228+
result = getLastModificationTime(a) - getLastModificationTime(b) >= DurationZero
229229
# Posix's resolution sucks so, we use '>=' for posix.
230230
else:
231-
result = getLastModificationTime(a) - getLastModificationTime(b) > 0
231+
result = getLastModificationTime(a) - getLastModificationTime(b) > DurationZero
232232

233233
proc getCurrentDir*(): string {.rtl, extern: "nos$1", tags: [].} =
234234
## Returns the `current working directory`:idx:.

lib/pure/random.nim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,8 @@ when not defined(nimscript):
191191
proc randomize*() {.benign.} =
192192
## Initializes the random number generator with a "random"
193193
## number, i.e. a tickcount. Note: Does not work for NimScript.
194-
let time = int64(times.epochTime() * 1_000_000_000)
195-
randomize(time)
194+
let now = times.getTime()
195+
randomize(convert(Seconds, Nanoseconds, now.toUnix) + now.nanoseconds)
196196

197197
{.pop.}
198198

0 commit comments

Comments
 (0)