fluent-icu-1.0.0: test/TimeSpec.hs
module TimeSpec (spec) where
import Data.Time
import Prelude
spec :: Spec
spec = do
it "is a date of numbers when given nothing" $
translate "foo" ("when", TimeValue afternoon timeOptions) resource `shouldBe` Right "10/08/2026"
it "formats the date to match the locale's convention" $
translate "foo" ("when", TimeValue afternoon timeOptions) deCH resource `shouldBe` Right "10.8.2026"
it "spells the month out at the width it is given" $
translate
"foo"
("when", TimeValue afternoon dated{month = Just (Right Long)})
resource
`shouldBe` Right "10 August 2026"
it "formats only the field it is given" $
translate "foo" ("when", TimeValue afternoon timeOptions{month = Just (Right Long)}) resource
`shouldBe` Right "August"
it "spells the weekday out" $
translate "foo" ("when", TimeValue afternoon timeOptions{weekday = Just Long}) resource
`shouldBe` Right "Monday"
it "shows the time of day it is given" $
translate "foo" ("when", TimeValue afternoon clock) resource `shouldBe` Right "12:34"
it "formats the month in digits or in words, beside a year of digits" $ do
translate
"foo"
("when", TimeValue afternoon timeOptions{year = Just Numeric, month = Just (Right Narrow)})
resource
`shouldBe` Right "A 2026"
translate
"foo"
("when", TimeValue afternoon timeOptions{year = Just Numeric, month = Just (Left TwoDigit)})
resource
`shouldBe` Right "08/2026"
it "reads the time in the zone it is given" $
translate "foo" ("when", TimeValue afternoon berlin) resource `shouldBe` Right "14:34"
it "keeps the hour the zone keeps at that time of year" $
translate "foo" ("when", TimeValue midwinter berlin) resource `shouldBe` Right "13:34"
resource :: Resource
resource = [fluent|foo = { $when }|]
deCH :: LocaleName
deCH = "de-CH"
dated :: TimeOptions
dated = timeOptions{day = Just Numeric, year = Just Numeric}
clock :: TimeOptions
clock = timeOptions{hour = Just Numeric, minute = Just TwoDigit, hour12 = Just False}
berlin :: TimeOptions
berlin = clock{timeZone = "Europe/Berlin"}
time :: DiffTime
time = secondsToDiffTime $ foldl' ((+) . (60 *)) 0 [12, 34, 56]
afternoon :: UTCTime
afternoon = UTCTime (fromGregorian 2026 8 10) time
midwinter :: UTCTime
midwinter = UTCTime (fromGregorian 2026 1 10) time