-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add time formatting options to cron describe
- Loading branch information
1 parent
d919330
commit 6d4a16d
Showing
4 changed files
with
20 additions
and
13 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
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 |
---|---|---|
@@ -1,20 +1,17 @@ | ||
module System.Cron.Internal.Describe.Time where | ||
|
||
import System.Cron.Internal.Describe.Types | ||
import Data.Time (formatTime, TimeOfDay (TimeOfDay), defaultTimeLocale, TimeLocale, TimeZone, utc, utcToLocalTimeOfDay) | ||
|
||
newtype Minute = Minute Int | ||
newtype Hour = Hour Int | ||
|
||
format :: TimeFormat -> Minute -> Hour -> String | ||
format t (Minute m) (Hour h) = leftPad (hour t) ++ ":" ++ leftPad m ++ suffix t | ||
where leftPad n | ||
| n < 10 = "0" ++ show n | ||
| otherwise = show n | ||
suffix Hour24 = "" | ||
suffix Hour12 | ||
| h < 12 = " AM" | ||
| otherwise = " PM" | ||
hour Hour24 = h | ||
hour Hour12 | ||
| h > 12 = h `mod` 12 | ||
| otherwise = h | ||
format Hour24 = fmtTime utc defaultTimeLocale "%R" | ||
format Hour12 = fmtTime utc defaultTimeLocale "%I:%M %p" | ||
format (CustomTimeFormat zone locale pattern) = fmtTime zone locale pattern | ||
|
||
fmtTime :: TimeZone -> TimeLocale -> String -> Minute -> Hour -> String | ||
fmtTime zone locale pattern (Minute m) (Hour h) = formatTime locale pattern tod | ||
where | ||
tod = snd . utcToLocalTimeOfDay zone $ TimeOfDay h m 0 |
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