Created
December 10, 2013 19:04
-
-
Save mightybyte/7896191 to your computer and use it in GitHub Desktop.
A collection of core date/time formlets for digestive-functors.
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
utcTimeFormlet :: Monad m | |
=> String | |
-- ^ Date format string | |
-> String | |
-- ^ Time format string | |
-> TimeZone | |
-> Formlet Text m UTCTime | |
utcTimeFormlet dFmt tFmt tz d = | |
localTimeToUTC tz <$> localTimeFormlet dFmt tFmt (utcToLocalTime tz <$> d) | |
localTimeFormlet :: Monad m | |
=> String | |
-- ^ Date format string | |
-> String | |
-- ^ Time format string | |
-> Formlet Text m LocalTime | |
localTimeFormlet dFmt tFmt d = LocalTime | |
<$> "date" .: dateFormlet dFmt (localDay <$> d) | |
<*> "time" .: timeFormlet tFmt (localTimeOfDay <$> d) | |
dateFormlet :: Monad m | |
=> String | |
-- ^ Format string | |
-> Formlet Text m Day | |
dateFormlet fmt d = | |
validate vFunc (string $ formatTime defaultTimeLocale fmt <$> d) | |
where | |
vFunc = maybe (Error "invalid date") Success . | |
parseTime defaultTimeLocale fmt | |
timeFormlet :: Monad m | |
=> String | |
-- ^ Format string | |
-> Formlet Text m TimeOfDay | |
timeFormlet fmt d = | |
validate vFunc (string $ formatTime defaultTimeLocale fmt <$> d) | |
where | |
vFunc = maybe (Error "invalid time") Success . | |
parseTime defaultTimeLocale fmt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://gist.github.com/LukeHoersten/7896241 for my ZonedTime implementation w/ optional forms.