]> gitweb.michael.orlitzky.com - dead/htsn-import.git/commitdiff
Begin to add xp_ambiguous_time, still needs doctests.
authorMichael Orlitzky <michael@orlitzky.com>
Tue, 22 Jul 2014 13:46:15 +0000 (09:46 -0400)
committerMichael Orlitzky <michael@orlitzky.com>
Tue, 22 Jul 2014 13:46:15 +0000 (09:46 -0400)
src/TSN/Picklers.hs

index f697b8ca48196fadebdfc6cd92a912f113ab0e2f..3863017c090018268dc67f93c8e34c3583667543 100644 (file)
@@ -2,6 +2,7 @@
 --   feed.
 --
 module TSN.Picklers (
+  xp_ambiguous_time,
   xp_date,
   xp_date_padded,
   xp_datetime,
@@ -285,3 +286,23 @@ xp_time_stamp =
     from_time_stamp :: UTCTime -> String
     from_time_stamp =
       formatTime defaultTimeLocale time_stamp_format . subtract_five
+
+
+-- | (Un)pickle an ambiguous 12-hour AM/PM time, which is ambiguous
+--   because it's missing the AM/PM part.
+--
+--   Examples:
+--
+xp_ambiguous_time :: PU UTCTime
+xp_ambiguous_time =
+  (to_time, from_time) `xpWrapMaybe` xpText
+  where
+    ambiguous_time_format :: String
+    ambiguous_time_format = "%-I:%M"
+
+    to_time :: String -> Maybe UTCTime
+    to_time = parseTime defaultTimeLocale ambiguous_time_format
+
+    from_time :: UTCTime -> String
+    from_time =
+      formatTime defaultTimeLocale ambiguous_time_format