formatting 3.1.3 → 3.1.4
raw patch · 3 files changed
+23/−1 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Formatting.Formatters: ords :: Integral n => Format n
+ Formatting.Time: dayOfMonthOrd :: FormatTime a => Format a
Files
- formatting.cabal +2/−1
- src/Formatting/Formatters.hs +15/−0
- src/Formatting/Time.hs +6/−0
formatting.cabal view
@@ -1,5 +1,5 @@ name: formatting-version: 3.1.3+version: 3.1.4 synopsis: Combinator-based type-safe formatting (like printf() or FORMAT) description: Combinator-based type-safe formatting (like printf() or FORMAT), modelled from the HoleyMonoids package. license: BSD3@@ -25,6 +25,7 @@ time, old-locale hs-source-dirs: src+ ghc-options: -O2 source-repository head type: git
src/Formatting/Formatters.hs view
@@ -29,6 +29,7 @@ prec, shortest, commas,+ ords, -- * Padding left, right,@@ -133,3 +134,17 @@ merge (f,c) rest | f == ',' = "," <> LT.singleton c <> rest | otherwise = LT.singleton c <> rest cycle' xs = xs <> cycle' xs++-- | Add a suffix to an integral, e.g. 1st, 2nd, 3rd, 21st.+ords :: Integral n => Format n+ords = later go+ where go n+ | tens > 3 && tens < 21 = T.shortest n <> "th"+ | otherwise =+ T.shortest n <>+ case n `mod` 10 of+ 1 -> "st"+ 2 -> "nd"+ 3 -> "rd"+ _ -> "th"+ where tens = n `mod` 100
src/Formatting/Time.hs view
@@ -158,6 +158,12 @@ dayOfMonth :: FormatTime a => Format a dayOfMonth = later (build . fmt "%d") +-- | Day of month, @1st@, @2nd@, @25th@, etc.+dayOfMonthOrd :: FormatTime a => Format a+dayOfMonthOrd = later (bprint ords . toInt)+ where toInt :: FormatTime a => a -> Int+ toInt = read . formatTime defaultTimeLocale "%d"+ -- | Day of month, leading space as needed, @ 1@ - @31@. dayOfMonthS :: FormatTime a => Format a dayOfMonthS = later (build . fmt "%e")