os.setLastModificationTime*(file: string, t: times.Time) (#7543)

* add proc toFILETIME to winlean
* add proc toWinTime to times
* add proc setFileTime to winlean
* openHandle with write access
* add proc setLastModificationTime to os
* moved epochDiff,rateDiff constants and proc toWinTime
The constants were moved out of the when defined(JS) block so that they
are alsways available in proc toWinTime.
proc toWinTime was moved above the # Deprecated procs comment. Best new
location seemed to be with the toUnix proc.
This commit is contained in:
Hendrik 2018-04-16 22:03:24 +02:00 • committed by Andreas Rumpf
commit b1b517128e
3 changed files with 35 additions and 6 deletions

View file

@ -191,6 +191,7 @@ const
secondsInHour = 60*60
secondsInDay = 60*60*24
minutesInHour = 60
rateDiff = 10000000'i64 # 100 nsecs
# The number of hectonanoseconds between 1601/01/01 (windows epoch)
# and 1970/01/01 (unix epoch).
epochDiff = 116444736000000000'i64
@ -371,6 +372,10 @@ proc toUnix*(t: Time): int64 {.benign, tags: [], raises: [], noSideEffect.} =
## Convert ``t`` to a unix timestamp (seconds since ``1970-01-01T00:00:00Z``).
t.seconds
proc toWinTime*(t: Time): int64 =
## Convert ``t`` to a Windows file time (100-nanosecond intervals since ``1601-01-01T00:00:00Z``).
result = t.seconds * rateDiff + epochDiff
proc isLeapYear*(year: int): bool =
## Returns true if ``year`` is a leap year.
year mod 4 == 0 and (year mod 100 != 0 or year mod 400 == 0)
@ -1713,9 +1718,6 @@ when not defined(JS):
var
clocksPerSec {.importc: "CLOCKS_PER_SEC", nodecl.}: int
const
rateDiff = 10000000'i64 # 100 nsecs
proc unixTimeToWinTime*(time: CTime): int64 =
## converts a UNIX `Time` (``time_t``) to a Windows file time
result = int64(time) * rateDiff + epochDiff