Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ New features:
Bugfixes:

Other improvements:
- Added support for single-digit months [#69](https://github.com/purescript-contrib/purescript-formatters/pull/69) (@vapaj)

## [v5.0.0](https://github.com/purescript-contrib/purescript-formatters/releases/tag/v5.0.0) - 2021-02-26

Expand Down
6 changes: 6 additions & 0 deletions src/Data/Formatter/DateTime.purs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ data FormatterCommand
| YearAbsolute
| MonthFull
| MonthShort
| MonthDigit
| MonthTwoDigits
| DayOfMonthTwoDigits
| DayOfMonth
Expand Down Expand Up @@ -87,6 +88,7 @@ printFormatterCommand = case _ of
YearAbsolute → "Y"
MonthFull → "MMMM"
MonthShort → "MMM"
MonthDigit → "M"
MonthTwoDigits → "MM"
DayOfMonthTwoDigits → "DD"
DayOfMonth → "D"
Expand Down Expand Up @@ -127,6 +129,7 @@ formatterCommandParser = (PC.try <<< PS.string) `oneOfAs`
, Tuple "MMMM" MonthFull
, Tuple "MMM" MonthShort
, Tuple "MM" MonthTwoDigits
, Tuple "M" MonthDigit
, Tuple "DD" DayOfMonthTwoDigits
, Tuple "D" DayOfMonth
, Tuple "E" DayOfWeek
Expand Down Expand Up @@ -170,6 +173,7 @@ formatCommand dt@(DT.DateTime d t) = case _ of
YearAbsolute → show $ fromEnum $ D.year d
MonthFull → show $ D.month d
MonthShort → printShortMonth $ D.month d
MonthDigit -> show $ fromEnum $ D.month d
MonthTwoDigits → padSingleDigit $ fromEnum $ D.month d
DayOfMonthTwoDigits → padSingleDigit $ fromEnum $ D.day d
DayOfMonth → show $ fromEnum $ D.day d
Expand Down Expand Up @@ -351,6 +355,8 @@ unformatCommandParser = case _ of
(fromEnum <$> parseMonth)
MonthShort → _{month = _} `modifyWithParser`
(fromEnum <$> parseShortMonth)
MonthDigit → _{month = _} `modifyWithParser`
(parseInt 2 (validateRange 1 12) "Incorrect month digit")
MonthTwoDigits → _{month = _} `modifyWithParser`
(parseInt 2 (validateRange 1 12 <> exactLength) "Incorrect 2-digit month")
DayOfMonthTwoDigits → _{day = _} `modifyWithParser`
Expand Down