From e96ff7e42d569f5f20d03a968fbc1d1dde9ee0ce Mon Sep 17 00:00:00 2001 From: Ian McLerran Date: Mon, 29 Jan 2024 11:43:30 -0600 Subject: [PATCH] Begin migrating Utc and related time components to signed integers. --- platform/Effect.roc | 2 +- platform/Utc.roc | 14 +++++++------- platform/src/lib.rs | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/platform/Effect.roc b/platform/Effect.roc index 950ef292..f20b9e9b 100644 --- a/platform/Effect.roc +++ b/platform/Effect.roc @@ -88,7 +88,7 @@ tcpWrite : List U8, InternalTcp.Stream -> Effect InternalTcp.WriteResult pathType : List U8 -> Effect (Result InternalPath.InternalPathType InternalPath.GetMetadataErr) -posixTime : Effect U128 +posixTime : Effect I128 sleepMillis : U64 -> Effect {} commandStatus : Box InternalCommand.Command -> Effect (Result {} InternalCommand.CommandErr) diff --git a/platform/Utc.roc b/platform/Utc.roc index 297906f3..2ec503f7 100644 --- a/platform/Utc.roc +++ b/platform/Utc.roc @@ -12,7 +12,7 @@ interface Utc imports [Effect, InternalTask, Task.{ Task }] ## Stores a timestamp as nanoseconds since UNIX EPOCH -Utc := U128 implements [Inspect] +Utc := I128 implements [Inspect] ## Duration since UNIX EPOCH now : Task Utc * @@ -26,30 +26,30 @@ now = nanosPerMilli = 1_000_000 ## Convert Utc timestamp to milliseconds -toMillisSinceEpoch : Utc -> U128 +toMillisSinceEpoch : Utc -> I128 toMillisSinceEpoch = \@Utc nanos -> nanos // nanosPerMilli ## Convert milliseconds to Utc timestamp -fromMillisSinceEpoch : U128 -> Utc +fromMillisSinceEpoch : I128 -> Utc fromMillisSinceEpoch = \millis -> @Utc (millis * nanosPerMilli) ## Convert Utc timestamp to nanoseconds -toNanosSinceEpoch : Utc -> U128 +toNanosSinceEpoch : Utc -> I128 toNanosSinceEpoch = \@Utc nanos -> nanos ## Convert nanoseconds to Utc timestamp -fromNanosSinceEpoch : U128 -> Utc +fromNanosSinceEpoch : I128 -> Utc fromNanosSinceEpoch = @Utc ## Calculate milliseconds between two Utc timestamps -deltaAsMillis : Utc, Utc -> U128 +deltaAsMillis : Utc, Utc -> I128 deltaAsMillis = \@Utc first, @Utc second -> (Num.absDiff first second) // nanosPerMilli ## Calculate nanoseconds between two Utc timestamps -deltaAsNanos : Utc, Utc -> U128 +deltaAsNanos : Utc, Utc -> I128 deltaAsNanos = \@Utc first, @Utc second -> Num.absDiff first second diff --git a/platform/src/lib.rs b/platform/src/lib.rs index a089cc33..a57bebec 100644 --- a/platform/src/lib.rs +++ b/platform/src/lib.rs @@ -524,13 +524,13 @@ pub extern "C" fn roc_fx_cwd() -> RocList { } #[no_mangle] -pub extern "C" fn roc_fx_posixTime() -> roc_std::U128 { +pub extern "C" fn roc_fx_posixTime() -> roc_std::I128 { // TODO in future may be able to avoid this panic by using C APIs let since_epoch = SystemTime::now() .duration_since(UNIX_EPOCH) .expect("time went backwards"); - roc_std::U128::from(since_epoch.as_nanos()) + roc_std::I128::from(since_epoch.as_nanos() as i128) } #[no_mangle]