Skip to content

Commit

Permalink
[ new ] dateString
Browse files Browse the repository at this point in the history
  • Loading branch information
stefan-hoeck committed Mar 20, 2024
1 parent 8c91034 commit 4e5eff3
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions js/src/JS/Date.idr
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module JS.Date

import Data.String

%default total

||| External data type for working with JS `Date` values
Expand Down Expand Up @@ -59,3 +61,13 @@ getMonth = prim__getMonth
export %inline
getDate : JSDate -> Bits32
getDate = prim__getDate

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

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

0 comments on commit 4e5eff3

Please sign in to comment.