Skip to content

Commit

Permalink
[ fix ] use 64 bits for time integers
Browse files Browse the repository at this point in the history
  • Loading branch information
stefan-hoeck committed Jun 3, 2024
1 parent 2959153 commit 1e6fea8
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions js/src/JS/Date.idr
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import Data.String
public export
data JSDate : Type where [external]

%foreign "javascript:lambda:(w) => new Date(w)"
prim__date : Bits32 -> JSDate
%foreign "javascript:lambda:(w) => new Date(Number(w))"
prim__date : Bits64 -> JSDate

%foreign "javascript:lambda:(w) => new Date(w)"
prim__stringDate : String -> JSDate
Expand All @@ -20,20 +20,20 @@ prim__toLocaleDateString : JSDate -> String
%foreign "javascript:lambda:(w) => w.toLocaleTimeString()"
prim__toLocaleTimeString : JSDate -> String

%foreign "javascript:lambda:(d) => d.getTime()"
prim__getTime : JSDate -> Bits32
%foreign "javascript:lambda:(d) => BigInt(d.getTime())"
prim__getTime : JSDate -> Bits64

%foreign "javascript:lambda:(d) => d.getFullYear()"
prim__getFullYear : JSDate -> Bits32
%foreign "javascript:lambda:(d) => BigInt(d.getFullYear())"
prim__getFullYear : JSDate -> Bits64

%foreign "javascript:lambda:(d) => d.getMonth()"
prim__getMonth : JSDate -> Bits32
%foreign "javascript:lambda:(d) => BigInt(d.getMonth())"
prim__getMonth : JSDate -> Bits64

%foreign "javascript:lambda:(d) => d.getDate()"
prim__getDate : JSDate -> Bits32
%foreign "javascript:lambda:(d) => BigInt(d.getDate())"
prim__getDate : JSDate -> Bits64

export %inline
Cast Bits32 JSDate where cast = prim__date
Cast Bits64 JSDate where cast = prim__date

export %inline
Cast String JSDate where cast = prim__stringDate
Expand All @@ -47,27 +47,27 @@ toLocaleTimeString : JSDate -> String
toLocaleTimeString = prim__toLocaleTimeString

export %inline
getTime : JSDate -> Bits32
getTime : JSDate -> Bits64
getTime = prim__getTime

export %inline
getFullYear : JSDate -> Bits32
getFullYear : JSDate -> Bits64
getFullYear = prim__getFullYear

export %inline
getMonth : JSDate -> Bits32
getMonth : JSDate -> Bits64
getMonth = prim__getMonth

export %inline
getDate : JSDate -> Bits32
getDate : JSDate -> Bits64
getDate = prim__getDate

pad2 : Bits32 -> String
pad2 : Bits64 -> String
pad2 v = padLeft 2 '0' (show v)

||| Prints a date in the format "yyyy-mm-dd"
export
dateString : Bits32 -> String
dateString : Bits64 -> String
dateString ts =
let d := cast {to = JSDate} ts
in "\{show $ getFullYear d}-\{pad2 $ getMonth d + 1}-\{pad2 $ getDate d}"

0 comments on commit 1e6fea8

Please sign in to comment.