packages feed

fluent-1.0.0: src/Language/Fluent/Width.hs

module Language.Fluent.Width where

import Data.Char (toLower)
import Prelude

data Width
    = -- | e.g. @A@, @5s@
      Narrow
    | -- | e.g. @Aug@, @5 s@
      Short
    | -- | e.g. @August@, @5 seconds@
      Long
    deriving stock (Eq, Bounded, Enum)

instance Show Width where
    show Narrow = "narrow"
    show Short = "short"
    show Long = "long"

instance Read Width where
    readsPrec _ s = [(it, "") | it <- [minBound .. maxBound], fmap toLower (show it) == fmap toLower s]

-- | How often a date field symbol is repeated in a skeleton for this width,
-- e.g. @MMM@ gives 'Short' months, @MMMM@ 'Long' ones and @MMMMM@ 'Narrow' ones.
-- See the <https://unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table Unicode date field symbol table>.
letters :: Width -> Int
letters Short = 3
letters Long = 4
letters Narrow = 5