hare

The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit 7dfb0145d6bc57177b0267a2e07d4a84e38eb659
parent 69f1eebbc3a593ea3a5df02732b6897fd36e5eb1
Author: Drew DeVault <sir@cmpwn.com>
Date:   Thu, 25 Mar 2021 09:42:41 -0400

time: rename time::time to time::instant

time::time will be timezone aware.

Diffstat:
Mfs/types.ha | 6+++---
Mos/+linux/dirfdfs.ha | 6+++---
Mtime/+linux/functions.ha | 10+++++-----
Mtime/types.ha | 20+++++++++-----------
4 files changed, 20 insertions(+), 22 deletions(-)

diff --git a/fs/types.ha b/fs/types.ha @@ -121,9 +121,9 @@ export type filestat = struct { gid: uint, sz: size, inode: u64, - atime: time::time, - mtime: time::time, - ctime: time::time, + atime: time::instant, + mtime: time::instant, + ctime: time::instant, }; // An entry in a directory. This may be borrowed from the filesystem's internal diff --git a/os/+linux/dirfdfs.ha b/os/+linux/dirfdfs.ha @@ -232,15 +232,15 @@ fn fs_stat(fs: *fs::fs, path: str) (fs::filestat | fs::error) = { uid = st.gid, sz = st.sz, inode = st.ino, - atime = time::time { + atime = time::instant { sec = st.atime.tv_sec, nsec = st.atime.tv_nsec, }, - mtime = time::time { + mtime = time::instant { sec = st.mtime.tv_sec, nsec = st.mtime.tv_nsec, }, - ctime = time::time { + ctime = time::instant { sec = st.ctime.tv_sec, nsec = st.ctime.tv_nsec, }, diff --git a/time/+linux/functions.ha b/time/+linux/functions.ha @@ -7,12 +7,12 @@ fn duration_to_timespec(n: duration, ts: *rt::timespec) void = { ts.tv_nsec = n % SECOND; }; -fn time_to_timespec(t: time, ts: *rt::timespec) void = { +fn instant_to_timespec(t: instant, ts: *rt::timespec) void = { ts.tv_sec = t.sec; ts.tv_nsec = t.nsec; }; -fn timespec_to_time(ts: rt::timespec) time = time { +fn timespec_to_instant(ts: rt::timespec) instant = instant { sec = ts.tv_sec, nsec = ts.tv_nsec, }; @@ -82,17 +82,17 @@ fn now_vdso(clock: clock, tp: *rt::timespec) (void | rt::errno) = { }; // Returns the current time for a given clock. -export fn now(clock: clock) time = { +export fn now(clock: clock) instant = { let tp = rt::timespec { ... }; let err = match (now_vdso(clock, &tp)) { - void => return timespec_to_time(tp), + void => return timespec_to_instant(tp), err: rt::errno => err }; if (err != rt::wrap_errno(rt::ENOSYS)) { abort("Unexpected error from clock_gettime"); }; return match (rt::clock_gettime(clock, &tp)) { - void => timespec_to_time(tp), + void => timespec_to_instant(tp), err: rt::errno => abort("Unexpected error from clock_gettime"), }; }; diff --git a/time/types.ha b/time/types.ha @@ -9,24 +9,22 @@ export def SECOND: duration = 1000 * MILLISECOND; export def MINUTE: duration = 60 * SECOND; export def HOUR: duration = 60 * MINUTE; -// TEMPORARY; MAY CHANGE -// -// Represents a specific instant in time as seconds (+nanoseconds) since a given -// epoch. For [clock::REALTIME], the epoch is the Unix epoch: January 1st, 1970, -// at midnight, UTC. -export type time = struct { sec: i64, nsec: i64 }; +// Represents a specific instant in time as seconds (+nanoseconds) since an +// arbitrary epoch. Instants may only be meaningfully compared with other +// instants sourced from the same clock. +export type instant = struct { sec: i64, nsec: i64 }; // The return value is negative if a < b, zero if a == b, and positive if a > b. -export fn compare(a: time, b: time) int = { +export fn compare(a: instant, b: instant) int = { return if (a.sec < b.sec) -1 else if (a.sec > b.sec) 1 else if (a.nsec < b.nsec) -1 else if (a.nsec > b.nsec) 1 else 0; }; -// Converts the given [time] to a Unix timestamp. -export fn unix(a: time) i64 = a.sec; +// Converts the given [instant] to a Unix timestamp. +export fn unix(a: instant) i64 = a.sec; -// Returns a [time] from a Unix timestamp. -export fn from_unix(u: i64) time = time { +// Returns a [instant] from a Unix timestamp. +export fn from_unix(u: i64) instant = instant { sec = u, nsec = 0, };