friendly-time 0.4 → 0.4.1
raw patch · 3 files changed
+205/−32 lines, 3 filesdep ~timePVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependency ranges changed: time
API changes (from Hackage documentation)
- Data.Time.Format.Human: aboutHoursAgo :: HumanTimeLocale -> Bool -> String -> String
- Data.Time.Format.Human: at :: HumanTimeLocale -> Int -> String -> String
- Data.Time.Format.Human: dayOfWeekFmt :: HumanTimeLocale -> String
- Data.Time.Format.Human: daysAgo :: HumanTimeLocale -> Bool -> String -> String
- Data.Time.Format.Human: justNow :: HumanTimeLocale -> String
- Data.Time.Format.Human: locale :: HumanTimeLocale -> TimeLocale
- Data.Time.Format.Human: minutesAgo :: HumanTimeLocale -> Bool -> String -> String
- Data.Time.Format.Human: onYear :: HumanTimeLocale -> String -> String
- Data.Time.Format.Human: oneHourAgo :: HumanTimeLocale -> Bool -> String
- Data.Time.Format.Human: oneMinuteAgo :: HumanTimeLocale -> Bool -> String
- Data.Time.Format.Human: prevYearFmt :: HumanTimeLocale -> String
- Data.Time.Format.Human: secondsAgo :: HumanTimeLocale -> Bool -> String -> String
- Data.Time.Format.Human: thisYearFmt :: HumanTimeLocale -> String
- Data.Time.Format.Human: timeZone :: HumanTimeLocale -> TimeZone
- Data.Time.Format.Human: weekAgo :: HumanTimeLocale -> Bool -> String -> String
- Data.Time.Format.Human: weeksAgo :: HumanTimeLocale -> Bool -> String -> String
+ Data.Time.Format.Human: [aboutHoursAgo] :: HumanTimeLocale -> Bool -> String -> String
+ Data.Time.Format.Human: [at] :: HumanTimeLocale -> Int -> String -> String
+ Data.Time.Format.Human: [dayOfWeekFmt] :: HumanTimeLocale -> String
+ Data.Time.Format.Human: [daysAgo] :: HumanTimeLocale -> Bool -> String -> String
+ Data.Time.Format.Human: [justNow] :: HumanTimeLocale -> String
+ Data.Time.Format.Human: [locale] :: HumanTimeLocale -> TimeLocale
+ Data.Time.Format.Human: [minutesAgo] :: HumanTimeLocale -> Bool -> String -> String
+ Data.Time.Format.Human: [onYear] :: HumanTimeLocale -> String -> String
+ Data.Time.Format.Human: [oneHourAgo] :: HumanTimeLocale -> Bool -> String
+ Data.Time.Format.Human: [oneMinuteAgo] :: HumanTimeLocale -> Bool -> String
+ Data.Time.Format.Human: [prevYearFmt] :: HumanTimeLocale -> String
+ Data.Time.Format.Human: [secondsAgo] :: HumanTimeLocale -> Bool -> String -> String
+ Data.Time.Format.Human: [thisYearFmt] :: HumanTimeLocale -> String
+ Data.Time.Format.Human: [timeZone] :: HumanTimeLocale -> TimeZone
+ Data.Time.Format.Human: [weekAgo] :: HumanTimeLocale -> Bool -> String -> String
+ Data.Time.Format.Human: [weeksAgo] :: HumanTimeLocale -> Bool -> String -> String
+ Data.Time.Format.Human.Locales: spanishHumanTimeLocale :: HumanTimeLocale
Files
- friendly-time.cabal +45/−32
- src/Data/Time/Format/Human/Locales.hs +62/−0
- test/Data/Time/Format/HumanSpec.hs +98/−0
friendly-time.cabal view
@@ -1,36 +1,49 @@-name: friendly-time-version: 0.4-author: Pat Brisbin <pbrisbin@gmail.com>-maintainer: Pat Brisbin <pbrisbin@gmail.com>-category: Web, Yesod-license: BSD3-license-file: LICENSE-synopsis: Print time information in friendly ways-description: Print time information in friendly ways-build-type: Simple-cabal-version: >= 1.10-build-type: Simple+-- This file has been generated from package.yaml by hpack version 0.17.0.+--+-- see: https://github.com/sol/hpack +name: friendly-time+version: 0.4.1+synopsis: Print time information in friendly ways+description: Print time information in friendly ways+category: Web, Yesod+author: Pat Brisbin <pbrisbin@gmail.com>+maintainer: Pat Brisbin <pbrisbin@gmail.com>+license: BSD3+license-file: LICENSE+build-type: Simple+cabal-version: >= 1.10++source-repository head+ type: git+ location: git://github.com/pbrisbin/friendly-time.git+ library- default-language: Haskell2010- hs-source-dirs: src- ghc-options: -Wall- exposed-modules: Data.Time.Format.Human- build-depends: base >= 4 && < 5- , time >= 1.4- , old-locale+ hs-source-dirs:+ src+ ghc-options: -Wall+ build-depends:+ time >=1.4+ , old-locale+ , base >=4 && <5+ exposed-modules:+ Data.Time.Format.Human+ Data.Time.Format.Human.Locales+ other-modules:+ Paths_friendly_time+ default-language: Haskell2010 test-suite spec- type: exitcode-stdio-1.0- default-language: Haskell2010- hs-source-dirs: test- main-is: Spec.hs- build-depends: base- , hspec- , friendly-time- , time >= 1.4- , old-locale--source-repository head- type: git- location: git://github.com/pbrisbin/friendly-time.git+ type: exitcode-stdio-1.0+ main-is: Spec.hs+ hs-source-dirs:+ test+ build-depends:+ time >=1.4+ , old-locale+ , base+ , hspec+ , friendly-time+ other-modules:+ Data.Time.Format.HumanSpec+ default-language: Haskell2010
+ src/Data/Time/Format/Human/Locales.hs view
@@ -0,0 +1,62 @@+module Data.Time.Format.Human.Locales+ ( spanishHumanTimeLocale+ ) where++import Data.Time+import Data.Time.Format.Human++-- | Spanish human time locale.+spanishHumanTimeLocale :: HumanTimeLocale+spanishHumanTimeLocale = HumanTimeLocale+ { justNow = "Justo ahora"+ , secondsAgo = \f x -> (dir f ++ " " ++ x ++ " segundos")+ , oneMinuteAgo = \f -> dir f ++ " un minuto"+ , minutesAgo = \f x -> (dir f ++ " " ++ x ++ " minutos")+ , oneHourAgo = \f -> dir f ++ " una hora"+ , aboutHoursAgo = \f x -> dir f ++ " aproximadamente " ++ x ++ " horas"+ , at = \_ -> ("El " ++)+ , daysAgo = \f x -> (dir f ++ " " ++ x ++ " dias")+ , weekAgo = \f x -> (dir f ++ " " ++ x ++ " semana")+ , weeksAgo = \f x -> (dir f ++ " " ++ x ++ " semanas")+ , onYear = ("En " ++)+ , locale = spanishTimeLocale+ , timeZone = utc+ , dayOfWeekFmt = "%A a las %l:%M %p"+ , thisYearFmt = "%b/%e"+ , prevYearFmt = "%Y/%b/%e"+ }+ where+ dir True = "Dentro de"+ dir False = "Hace"+ spanishTimeLocale = TimeLocale {+ wDays = [("Domingo", "Dom"), ("Lunes", "Lun"),+ ("Martes", "Mar"), ("Miercoles", "Mie"),+ ("Jueves", "Jue"), ("Viernes", "Vie"),+ ("Sabado", "Sab")],++ months = [("Enero", "Ene"), ("Febrero", "Feb"),+ ("Marzo", "Mar"), ("Abril", "Abr"),+ ("Mayo", "May"), ("Junio", "Jun"),+ ("Julio", "Jul"), ("Agosto", "Ago"),+ ("Septiembre", "Sep"), ("Octubre", "Oct"),+ ("Noviembre", "Nov"), ("Diciembre", "Dec")],++ amPm = ("AM", "PM"),+ dateTimeFmt = "%a %b %e %H:%M:%S %Z %Y",+ dateFmt = "%y/%m/%d",+ timeFmt = "%H:%M:%S",+ time12Fmt = "%I:%M:%S %p",+ knownTimeZones =+ [+ TimeZone 0 False "UT",+ TimeZone 0 False "GMT",+ TimeZone (-5 * 60) False "EST",+ TimeZone (-4 * 60) True "EDT",+ TimeZone (-6 * 60) False "CST",+ TimeZone (-5 * 60) True "CDT",+ TimeZone (-7 * 60) False "MST",+ TimeZone (-6 * 60) True "MDT",+ TimeZone (-8 * 60) False "PST",+ TimeZone (-7 * 60) True "PDT"+ ]+ }
+ test/Data/Time/Format/HumanSpec.hs view
@@ -0,0 +1,98 @@+{-# LANGUAGE CPP #-}++module Data.Time.Format.HumanSpec+ ( main+ , spec+ ) where++import Test.Hspec+import Data.Time.Format.Human++import Data.Maybe (fromJust)+import Data.Time++#if !MIN_VERSION_time(1,5,0)+import System.Locale (defaultTimeLocale)+parseTimeM _ = parseTime+#endif+++main :: IO ()+main = hspec spec++spec :: Spec+spec = describe "humanReadableTime'" $ do+ it "returns just now for near times" $ do+ let n = parseTime' "2015-01-01 01:00:00.1"+ t = parseTime' "2015-01-01 01:00:00"++ humanReadableTime' n t `shouldBe` "just now"+ humanReadableTime' t n `shouldBe` "just now"++ it "returns seconds for times less than a minute" $ do+ let n = parseTime' "2015-01-01 01:00:59"+ let t = parseTime' "2015-01-01 01:00:00"++ humanReadableTime' n t `shouldBe` "59 seconds ago"+ humanReadableTime' t n `shouldBe` "59 seconds from now"++ it "returns minutes for times less than an hour" $ do+ let n = parseTime' "2015-01-01 01:59:00"+ let t = parseTime' "2015-01-01 01:00:00"++ humanReadableTime' n t `shouldBe` "59 minutes ago"+ humanReadableTime' t n `shouldBe` "59 minutes from now"++ it "returns hours for times less than a day" $ do+ let n = parseTime' "2015-01-01 23:59:00"+ let t = parseTime' "2015-01-01 01:00:00"++ humanReadableTime' n t `shouldBe` "about 22 hours ago"+ humanReadableTime' t n `shouldBe` "about 22 hours from now"++ context "when less than 5 days " $ do+ let n = parseTime' "2015-01-04 01:00:00"+ let t = parseTime' "2015-01-01 01:00:00"++ it "returns day of week in EDT" $ do+ let l = defaultHumanTimeLocale { timeZone = read "EDT" }++ humanReadableTimeI18N' l n t `shouldBe` "at 9:00 PM on Wednesday"+ humanReadableTimeI18N' l t n `shouldBe` "at 9:00 PM on Saturday"++ it "returns day of week in India" $ do+ let l = defaultHumanTimeLocale { timeZone = read "+0530" }++ humanReadableTimeI18N' l n t `shouldBe` "at 6:30 AM on Thursday"+ humanReadableTimeI18N' l t n `shouldBe` "at 6:30 AM on Sunday"++ it "returns days for times less than 10 days" $ do+ let n = parseTime' "2015-01-10 01:00:00"+ let t = parseTime' "2015-01-01 01:00:00"++ humanReadableTime' n t `shouldBe` "9 days ago"+ humanReadableTime' t n `shouldBe` "9 days from now"++ it "returns weeks for times less than 5 weeks" $ do+ let n = parseTime' "2015-01-29 01:00:00"+ let t = parseTime' "2015-01-01 01:00:00"++ humanReadableTime' n t `shouldBe` "4 weeks ago"+ humanReadableTime' t n `shouldBe` "4 weeks from now"++ it "returns a date string without year for this year" $ do+ let n = parseTime' "2015-12-30 01:00:00"+ let t = parseTime' "2015-01-01 01:00:00"++ humanReadableTime' n t `shouldBe` "on Jan 1" -- TODO: spacing+ humanReadableTime' t n `shouldBe` "on Dec 30"++ it "returns a date string including the year for previous years" $ do+ let n = parseTime' "2025-12-30 01:00:00"+ let t = parseTime' "2015-01-01 01:00:00"++ humanReadableTime' n t `shouldBe` "on Jan 1, 2015" -- TODO: spacing+ humanReadableTime' t n `shouldBe` "on Dec 30, 2025"++parseTime' :: String -> UTCTime+parseTime' = fromJust . parseTimeM True defaultTimeLocale "%F %T%Q"