Skip to content

Commit 940a8ef

Browse files
committed
Merge pull request #15 from hdgarrood/locale-strings
Locale strings
2 parents 744faf5 + 75631e1 commit 940a8ef

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -801,6 +801,37 @@ millisecondOfSecond :: forall e. Date -> Eff (locale :: Locale | e) MillisecondO
801801
Get the millisecond-of-second value for a date based on the current
802802
machine’s locale.
803803

804+
#### `toLocaleString`
805+
806+
``` purescript
807+
toLocaleString :: forall e. Date -> Eff (locale :: Locale | e) String
808+
```
809+
810+
Format a date as a human-readable string (including the date and the
811+
time), based on the current machine's locale. Example output:
812+
"Fri May 22 2015 19:45:07 GMT+0100 (BST)", although bear in mind that this
813+
can vary significantly across platforms.
814+
815+
#### `toLocaleTimeString`
816+
817+
``` purescript
818+
toLocaleTimeString :: forall e. Date -> Eff (locale :: Locale | e) String
819+
```
820+
821+
Format a time as a human-readable string, based on the current machine's
822+
locale. Example output: "19:45:07", although bear in mind that this
823+
can vary significantly across platforms.
824+
825+
#### `toLocaleDateString`
826+
827+
``` purescript
828+
toLocaleDateString :: forall e. Date -> Eff (locale :: Locale | e) String
829+
```
830+
831+
Format a date as a human-readable string, based on the current machine's
832+
locale. Example output: "Friday, May 22, 2015", although bear in mind that
833+
this can vary significantly across platforms.
834+
804835

805836
## Module Data.Date.UTC
806837

src/Data/Date/Locale.purs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ module Data.Date.Locale
1010
, minuteOfHour
1111
, secondOfMinute
1212
, millisecondOfSecond
13+
, toLocaleString
14+
, toLocaleTimeString
15+
, toLocaleDateString
1316
) where
1417

1518
import Control.Monad.Eff (Eff())
@@ -76,6 +79,25 @@ secondOfMinute d = runFn2 dateMethod "getSeconds" d
7679
millisecondOfSecond :: forall e. Date -> Eff (locale :: Locale | e) MillisecondOfSecond
7780
millisecondOfSecond d = runFn2 dateMethod "getMilliseconds" d
7881

82+
-- | Format a date as a human-readable string (including the date and the
83+
-- | time), based on the current machine's locale. Example output:
84+
-- | "Fri May 22 2015 19:45:07 GMT+0100 (BST)", although bear in mind that this
85+
-- | can vary significantly across platforms.
86+
toLocaleString :: forall e. Date -> Eff (locale :: Locale | e) String
87+
toLocaleString d = runFn2 dateMethod "toLocaleString" d
88+
89+
-- | Format a time as a human-readable string, based on the current machine's
90+
-- | locale. Example output: "19:45:07", although bear in mind that this
91+
-- | can vary significantly across platforms.
92+
toLocaleTimeString :: forall e. Date -> Eff (locale :: Locale | e) String
93+
toLocaleTimeString d = runFn2 dateMethod "toLocaleTimeString" d
94+
95+
-- | Format a date as a human-readable string, based on the current machine's
96+
-- | locale. Example output: "Friday, May 22, 2015", although bear in mind that
97+
-- | this can vary significantly across platforms.
98+
toLocaleDateString :: forall e. Date -> Eff (locale :: Locale | e) String
99+
toLocaleDateString d = runFn2 dateMethod "toLocaleDateString" d
100+
79101
foreign import dateMethod
80102
"""
81103
function dateMethod(method, date) {

0 commit comments

Comments
 (0)