Skip to content

Commit

Permalink
Move typecast for posixTime from lib.rs to Utc.roc
Browse files Browse the repository at this point in the history
  • Loading branch information
imclerran committed Jan 30, 2024
1 parent e96ff7e commit bc3aa34
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
1 change: 1 addition & 0 deletions platform/Utc.roc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Utc := I128 implements [Inspect]
now : Task Utc *
now =
Effect.posixTime
|> Effect.map Num.toI128
|> Effect.map @Utc
|> Effect.map Ok
|> InternalTask.fromEffect
Expand Down
4 changes: 2 additions & 2 deletions platform/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -524,13 +524,13 @@ pub extern "C" fn roc_fx_cwd() -> RocList<u8> {
}

#[no_mangle]
pub extern "C" fn roc_fx_posixTime() -> roc_std::I128 {
pub extern "C" fn roc_fx_posixTime() -> roc_std::U128 {
// 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::I128::from(since_epoch.as_nanos() as i128)
roc_std::U128::from(since_epoch.as_nanos())
}

#[no_mangle]
Expand Down

0 comments on commit bc3aa34

Please sign in to comment.