Skip to content

Commit

Permalink
[ new ] utilities for working with date and time
Browse files Browse the repository at this point in the history
  • Loading branch information
stefan-hoeck committed Mar 20, 2024
1 parent ebfb4dc commit 8c91034
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
1 change: 1 addition & 0 deletions js/js.ipkg
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ modules = JS
, JS.ByteString
, JS.Buffer
, JS.Callback
, JS.Date
, JS.Inheritance
, JS.Marshall
, JS.Nullable
Expand Down
61 changes: 61 additions & 0 deletions js/src/JS/Date.idr
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
module JS.Date

%default total

||| External data type for working with JS `Date` values
public export
data JSDate : Type where [external]

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

%foreign "javascript:lambda:(w) => new Date(w)"
prim__stringDate : String -> JSDate

%foreign "javascript:lambda:(w) => w.toLocaleDateString()"
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) => d.getFullYear()"
prim__getFullYear : JSDate -> Bits32

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

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

export %inline
Cast Bits32 JSDate where cast = prim__date

export %inline
Cast String JSDate where cast = prim__stringDate

export %inline
toLocaleDateString : JSDate -> String
toLocaleDateString = prim__toLocaleDateString

export %inline
toLocaleTimeString : JSDate -> String
toLocaleTimeString = prim__toLocaleTimeString

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

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

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

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

0 comments on commit 8c91034

Please sign in to comment.