friendly-time 0.2.1 → 0.2.2
raw patch · 2 files changed
+71/−26 lines, 2 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Data.Time.Format.Human: HumanTimeLocale :: String -> (String -> String) -> String -> (String -> String) -> String -> (String -> String) -> (String -> String) -> (String -> String) -> (String -> String) -> (String -> String) -> (String -> String) -> TimeLocale -> HumanTimeLocale
+ Data.Time.Format.Human: aboutHoursAgo :: HumanTimeLocale -> String -> String
+ Data.Time.Format.Human: at :: HumanTimeLocale -> String -> String
+ Data.Time.Format.Human: data HumanTimeLocale
+ Data.Time.Format.Human: daysAgo :: HumanTimeLocale -> String -> String
+ Data.Time.Format.Human: defaultHumanTimeLocale :: HumanTimeLocale
+ Data.Time.Format.Human: humanReadableTimeI18N :: HumanTimeLocale -> UTCTime -> IO String
+ Data.Time.Format.Human: humanReadableTimeI18N' :: HumanTimeLocale -> UTCTime -> UTCTime -> String
+ Data.Time.Format.Human: justNow :: HumanTimeLocale -> String
+ Data.Time.Format.Human: locale :: HumanTimeLocale -> TimeLocale
+ Data.Time.Format.Human: minutesAgo :: HumanTimeLocale -> String -> String
+ Data.Time.Format.Human: onYear :: HumanTimeLocale -> String -> String
+ Data.Time.Format.Human: oneHourAgo :: HumanTimeLocale -> String
+ Data.Time.Format.Human: oneMinuteAgo :: HumanTimeLocale -> String
+ Data.Time.Format.Human: secondsAgo :: HumanTimeLocale -> String -> String
+ Data.Time.Format.Human: weekAgo :: HumanTimeLocale -> String -> String
+ Data.Time.Format.Human: weeksAgo :: HumanTimeLocale -> String -> String
Files
- Data/Time/Format/Human.hs +69/−24
- friendly-time.cabal +2/−2
Data/Time/Format/Human.hs view
@@ -1,3 +1,4 @@+{-# LANGUAGE RecordWildCards #-} ------------------------------------------------------------------------------- -- | -- Module : Data.Time.Format.Human@@ -8,33 +9,76 @@ -- Stability : unstable -- Portability : unportable ----- Prints a @'UTCTime'@ as "a few seconds ago" or "3 days ago" and--- similar.+-- Prints a @'UTCTime'@ as "a few seconds ago" or "3 days ago" and similar. -- ------------------------------------------------------------------------------- module Data.Time.Format.Human ( humanReadableTime , humanReadableTime'+ , humanReadableTimeI18N+ , humanReadableTimeI18N'+ , HumanTimeLocale(..)+ , defaultHumanTimeLocale ) where import Data.Time import Data.Char (isSpace)-import System.Locale (defaultTimeLocale)+import System.Locale +data HumanTimeLocale = HumanTimeLocale+ { justNow :: String+ , secondsAgo :: String -> String+ , oneMinuteAgo :: String+ , minutesAgo :: String -> String+ , oneHourAgo :: String+ , aboutHoursAgo :: String -> String+ , at :: String -> String+ , daysAgo :: String -> String+ , weekAgo :: String -> String+ , weeksAgo :: String -> String+ , onYear :: String -> String+ , locale :: TimeLocale+ }++defaultHumanTimeLocale :: HumanTimeLocale+defaultHumanTimeLocale = HumanTimeLocale+ { justNow = "just now"+ , secondsAgo = (++ " seconds ago")+ , oneMinuteAgo = "one minute ago"+ , minutesAgo = (++ " minutes ago")+ , oneHourAgo = "one hour ago"+ , aboutHoursAgo = \x -> "about " ++ x ++ " hours ago"+ , at = ("at " ++)+ , daysAgo = (++ " days ago")+ , weekAgo = (++ " week ago")+ , weeksAgo = (++ " weeks ago")+ , onYear = ("on " ++)+ , locale = defaultTimeLocale+ }+ -- | Based on @humanReadableTimeDiff@ found in -- <https://github.com/snoyberg/haskellers/blob/master/Haskellers.hs>, -- <https://github.com/snoyberg/haskellers/blob/master/LICENSE> humanReadableTime :: UTCTime -> IO String-humanReadableTime t = do- now <- getCurrentTime- return $ humanReadableTime' now t+humanReadableTime = humanReadableTimeI18N defaultHumanTimeLocale --- | A pure form, takes the current time as an argument+-- | A pure form, takes current time as an argument humanReadableTime' :: UTCTime -- ^ current time -> UTCTime -> String-humanReadableTime' cur t = helper $ diffUTCTime cur t+humanReadableTime' = humanReadableTimeI18N' defaultHumanTimeLocale +-- | I18N version of `humanReadableTime`+humanReadableTimeI18N :: HumanTimeLocale -> UTCTime -> IO String+humanReadableTimeI18N tl t = do+ now <- getCurrentTime+ return $ humanReadableTimeI18N' tl now t++-- | I18N version of `humanReadableTime'`+humanReadableTimeI18N' :: HumanTimeLocale+ -> UTCTime -- ^ current time+ -> UTCTime -> String+humanReadableTimeI18N' (HumanTimeLocale {..}) cur t = helper $ diffUTCTime cur t where minutes :: NominalDiffTime -> Double minutes n = realToFrac $ n / 60@@ -57,20 +101,21 @@ trim = f . f where f = reverse . dropWhile isSpace old = utcToLocalTime utc t- dow = trim $! formatTime defaultTimeLocale "%l:%M %p on %A" old- thisYear = trim $! formatTime defaultTimeLocale "%b %e" old- previousYears = trim $! formatTime defaultTimeLocale "%b %e, %Y" old+ format = formatTime locale+ dow = trim $! format "%l:%M %p on %A" old+ thisYear = trim $! format "%b %e" old+ previousYears = trim $! format "%b %e, %Y" old - helper d - | d < 1 = "just now"- | d < 60 = i2s d ++ " seconds ago"- | minutes d < 2 = "one minute ago"- | minutes d < 60 = i2s (minutes d) ++ " minutes ago"- | hours d < 2 = "one hour ago"- | hours d < 24 = "about " ++ i2s (hours d) ++ " hours ago"- | days d < 5 = "at " ++ dow- | days d < 10 = i2s (days d) ++ " days ago"- | weeks d < 2 = i2s (weeks d) ++ " week ago"- | weeks d < 5 = i2s (weeks d) ++ " weeks ago"- | years d < 1 = "on " ++ thisYear- | otherwise = "on " ++ previousYears+ helper d+ | d < 1 = justNow+ | d < 60 = secondsAgo $ i2s d+ | minutes d < 2 = oneMinuteAgo+ | minutes d < 60 = minutesAgo $ i2s (minutes d)+ | hours d < 2 = oneHourAgo+ | hours d < 24 = aboutHoursAgo $ i2s (hours d)+ | days d < 5 = at dow+ | days d < 10 = daysAgo $ i2s (days d)+ | weeks d < 2 = weekAgo $ i2s (weeks d)+ | weeks d < 5 = weeksAgo $ i2s (weeks d)+ | years d < 1 = onYear thisYear+ | otherwise = onYear previousYears
friendly-time.cabal view
@@ -1,5 +1,5 @@ name: friendly-time-version: 0.2.1+version: 0.2.2 description: Print time information in friendly ways synopsis: Print time information in friendly ways homepage: http://github.com/pbrisbin/friendly-time@@ -19,7 +19,7 @@ , old-locale ghc-options: -Wall- + source-repository head type: git location: git://github.com/pbrisbin/friendly-time.git