-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ new ] utilities for working with date and time
- Loading branch information
1 parent
ebfb4dc
commit 8c91034
Showing
2 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |