packages feed

ordinal 0.3.1.0 → 0.4.0.0

raw patch · 10 files changed

+270/−20 lines, 10 filesdep +timePVP ok

version bump matches the API change (PVP)

Dependencies added: time

API changes (from Hackage documentation)

+ Text.Numerals.Class: Afternoon :: DayPart
+ Text.Numerals.Class: DaySegment :: DayPart -> Int -> DaySegment
+ Text.Numerals.Class: Evening :: DayPart
+ Text.Numerals.Class: Half :: ClockSegment
+ Text.Numerals.Class: Morning :: DayPart
+ Text.Numerals.Class: Night :: DayPart
+ Text.Numerals.Class: OClock :: ClockSegment
+ Text.Numerals.Class: Past :: Int -> ClockSegment
+ Text.Numerals.Class: PastHalf :: Int -> ClockSegment
+ Text.Numerals.Class: QuarterPast :: ClockSegment
+ Text.Numerals.Class: QuarterTo :: ClockSegment
+ Text.Numerals.Class: To :: Int -> ClockSegment
+ Text.Numerals.Class: ToHalf :: Int -> ClockSegment
+ Text.Numerals.Class: [dayHour] :: DaySegment -> Int
+ Text.Numerals.Class: [dayPart] :: DaySegment -> DayPart
+ Text.Numerals.Class: currentTimeText :: NumToWord a => TimeZone -> a -> IO Text
+ Text.Numerals.Class: currentTimeText' :: NumToWord a => a -> IO Text
+ Text.Numerals.Class: data ClockSegment
+ Text.Numerals.Class: data DayPart
+ Text.Numerals.Class: data DaySegment
+ Text.Numerals.Class: hourCorrection :: Int -> Int
+ Text.Numerals.Class: instance GHC.Classes.Eq Text.Numerals.Class.ClockSegment
+ Text.Numerals.Class: instance GHC.Classes.Eq Text.Numerals.Class.DayPart
+ Text.Numerals.Class: instance GHC.Classes.Eq Text.Numerals.Class.DaySegment
+ Text.Numerals.Class: instance GHC.Classes.Ord Text.Numerals.Class.ClockSegment
+ Text.Numerals.Class: instance GHC.Classes.Ord Text.Numerals.Class.DayPart
+ Text.Numerals.Class: instance GHC.Classes.Ord Text.Numerals.Class.DaySegment
+ Text.Numerals.Class: instance GHC.Enum.Bounded Text.Numerals.Class.DayPart
+ Text.Numerals.Class: instance GHC.Enum.Enum Text.Numerals.Class.DayPart
+ Text.Numerals.Class: instance GHC.Read.Read Text.Numerals.Class.ClockSegment
+ Text.Numerals.Class: instance GHC.Read.Read Text.Numerals.Class.DayPart
+ Text.Numerals.Class: instance GHC.Read.Read Text.Numerals.Class.DaySegment
+ Text.Numerals.Class: instance GHC.Show.Show Text.Numerals.Class.ClockSegment
+ Text.Numerals.Class: instance GHC.Show.Show Text.Numerals.Class.DayPart
+ Text.Numerals.Class: instance GHC.Show.Show Text.Numerals.Class.DaySegment
+ Text.Numerals.Class: toClockSegment :: Int -> ClockSegment
+ Text.Numerals.Class: toDayPart :: Int -> DayPart
+ Text.Numerals.Class: toDaySegment :: Int -> DaySegment
+ Text.Numerals.Class: toTimeText :: NumToWord a => a -> TimeOfDay -> Text
+ Text.Numerals.Class: toTimeText' :: NumToWord a => a -> Int -> Int -> Text
+ Text.Numerals.Class: type ClockText = ClockSegment " The 'ClockSegment' that describes the state of minutes within an hour." -> DaySegment " The 'DaySegment' that describes the state of hours within a day." -> Int " The number of hours." -> Int " The number of minutes." -> Text " A 'Text' object that describes the given time."
+ Text.Numerals.Languages.Dutch: toCardinal' :: Integral i => i -> Text
+ Text.Numerals.Languages.English: toCardinal' :: Integral i => i -> Text
+ Text.Numerals.Languages.French: toCardinal' :: Integral i => i -> Text
+ Text.Numerals.Languages.German: toCardinal' :: Integral i => i -> Text
- Text.Numerals.Algorithm: numeralsAlgorithm :: (Foldable f, Foldable g) => Text -> Text -> Text -> f Text -> g (Integer, Text) -> FreeValueSplitter -> FreeMergerFunction -> (Text -> Text) -> FreeNumberToWords -> NumeralsAlgorithm
+ Text.Numerals.Algorithm: numeralsAlgorithm :: (Foldable f, Foldable g) => Text -> Text -> Text -> f Text -> g (Integer, Text) -> FreeValueSplitter -> FreeMergerFunction -> (Text -> Text) -> FreeNumberToWords -> ClockText -> NumeralsAlgorithm

Files

CHANGELOG.md view
@@ -2,6 +2,10 @@  For a full list of changes, see the history on [GitHub](https://github.com/hapytex/ordinal). +## Version 0.4.0.0++Converting the time of the day to words by using `toTimeText` and `toTimeText'`.+ ## Version 0.3.1.0  Remove the `NumericUnderscores` extension to allow building the package for more
README.md view
@@ -15,21 +15,24 @@  1. Dutch (nl);  2. English (en);  3. French (fr); and- 4. German (de)+ 4. German (de).  ## Usage  One can import the `Text.Numerals` module, and use the `toCardinal`,-`toOrdinal` and `toShortOrdinal` functions with a number-to-word-algorithm that is exported by the `Text.Numerals.Languages` module, for example:+`toOrdinal`, `toShortOrdinal`, `toTimeText` and `toTimeText'` functions with a+number-to-word algorithm that is exported by the `Text.Numerals.Languages` module,+for example:  ``` Prelude Text.Numerals Data.Text.IO> Data.Text.IO.putStrLn (toCardinal english 42) forty-two Prelude Text.Numerals Data.Text.IO> Data.Text.IO.putStrLn (toOrdinal french 42) quarante-deuxième-Prelude Text.Numerals Data.Text.IO> Data.Text.IO.putStrLn (toShortOrdinal dutch 42)-42e+Prelude Text.Numerals Data.Text.IO> Data.Text.IO.putStrLn (toShortOrdinal german 42)+42.+Prelude Text.Numerals Data.Text.IO> Data.Text.IO.putStrLn (toTimeText' dutch 18 42)+twaalf minuten na half zeven 's avonds ```  One can also define a language algorithm themselves, for this one can look at
ordinal.cabal view
@@ -1,5 +1,5 @@ name:                ordinal-version:             0.3.1.0+version:             0.4.0.0 synopsis:            Convert numbers to words in different languages. description:     A package based on Python's num2words package that converts numbers@@ -42,6 +42,7 @@     , data-default >=0.2     , regex >=1.0     , text >= 0.1+    , time >=1.0     , template-haskell >=2.2.0.0     , vector >= 0.7   default-language:    Haskell2010
src/Text/Numerals/Algorithm.hs view
@@ -35,11 +35,13 @@ import qualified Data.Vector as V  import Text.Numerals.Class(-    NumToWord(toCardinal, toOrdinal, toShortOrdinal)+    NumToWord(toCardinal, toOrdinal, toShortOrdinal, toTimeText')   , FreeMergerFunction, FreeNumberToWords, FreeValueSplitter   , MergerFunction, MNumberSegment   , NumberSegment(NumberSegment), NumberSegmenting   , ValueSplit(valueSplit), ValueSplitter+  , ClockText+  , toClockSegment, toDaySegment   ) import Text.Numerals.Internal(_thousand, _iLogFloor) import Text.Numerals.Prefix(latinPrefixes)@@ -55,6 +57,7 @@   , mergeFunction :: FreeMergerFunction  -- ^ A function that specifies how to merge words based on the grammar of that specific language.   , ordinize :: Text -> Text  -- ^ A function to conver the /cardinal/ form of a number in an /ordinal/ one.   , shortOrdinal :: FreeNumberToWords -- ^ A function that converts a number to its /short ordinal/ form.+  , clockText :: ClockText  -- ^ A function that converts the clock segment and day segment to a /Text/ that describes the time of the day in words.   }  @@ -68,6 +71,7 @@      toOrdinal na@NumeralsAlgorithm { ordinize=_ordinize } = _ordinize . toCardinal na     toShortOrdinal = shortOrdinal+    toTimeText' alg h m = clockText alg (toClockSegment m) (toDaySegment h) h m   _toNumberScale :: (Integral i, Integral j) => i -> (j, i)@@ -128,7 +132,7 @@ -- | A /smart constructor/ for the 'NumeralsAlgorithm' type. This constructor -- allows one to use an arbitrary 'Foldable' type for the low words and mid -- words. It will also order the midwords accordingly.-numeralsAlgorithm :: (Foldable f, Foldable g) => Text -> Text -> Text -> f Text -> g (Integer, Text) -> FreeValueSplitter -> FreeMergerFunction -> (Text -> Text) -> FreeNumberToWords -> NumeralsAlgorithm+numeralsAlgorithm :: (Foldable f, Foldable g) => Text -> Text -> Text -> f Text -> g (Integer, Text) -> FreeValueSplitter -> FreeMergerFunction -> (Text -> Text) -> FreeNumberToWords -> ClockText -> NumeralsAlgorithm numeralsAlgorithm minus zero one _lowWords _midWords = NumeralsAlgorithm minus one (fromList (zero : one : toList _lowWords)) (sortOn (negate . fst) (toList _midWords))  _maybeSegment :: Integral i => (i -> NumberSegment i) -> i -> MNumberSegment i
src/Text/Numerals/Class.hs view
@@ -13,20 +13,31 @@  module Text.Numerals.Class (     -- * Typeclasses-    NumToWord(toCardinal, toOrdinal, toShortOrdinal, toWords)+    NumToWord(toCardinal, toOrdinal, toShortOrdinal, toWords, toTimeText, toTimeText')   , ValueSplit(valueSplit)     -- * Types of numbers   , NumberType(Cardinal, Ordinal, ShortOrdinal)     -- * Segmenting a number   , NumberSegment(NumberSegment, segmentDivision, segmentValue, segmentText, segmentRemainder)   , MNumberSegment+    -- * Segments of time+  , ClockSegment(OClock, Past, QuarterPast, ToHalf, Half, PastHalf, QuarterTo, To)+  , DayPart(Night, Morning, Afternoon, Evening)+  , DaySegment(DaySegment, dayPart, dayHour)+  , toDayPart, toDaySegment, toClockSegment+  , hourCorrection+    -- * Convert the current time to words+  , currentTimeText, currentTimeText'     -- * Utility type synonyms   , NumberToWords,  FreeNumberToWords   , MergerFunction, FreeMergerFunction, ValueSplitter, FreeValueSplitter, NumberSegmenting+  , ClockText   ) where  import Data.Default(Default(def)) import Data.Text(Text)+import Data.Time.Clock(getCurrentTime, utctDayTime)+import Data.Time.LocalTime(TimeOfDay(TimeOfDay), TimeZone, timeToTimeOfDay, utcToLocalTimeOfDay)  -- | A type alias for a function that maps a number to a 'Text' object. type NumberToWords i = i -> Text@@ -77,6 +88,83 @@   | ShortOrdinal -- ^ /Short ordinal/ numbers like 1st, 2nd, 3rd, etc.   deriving (Bounded, Enum, Eq, Ord, Read, Show) +-- | The type of a function that converts time to its description. The first+-- two parameters are used to make conversion more convenient.+type ClockText+  =  ClockSegment  -- ^ The 'ClockSegment' that describes the state of minutes within an hour.+  -> DaySegment  -- ^ The 'DaySegment' that describes the state of hours within a day.+  -> Int  -- ^ The number of hours.+  -> Int  -- ^ The number of minutes.+  -> Text  -- ^ A 'Text' object that describes the given time.++-- | A data type that describes the state of the minutes within an hour.+data ClockSegment+  = OClock  -- ^ The number of minutes is zero.+  | Past Int  -- ^ The parameter is the number of minutes past the hour, this is between @1@ and @14@.+  | QuarterPast  -- ^ It is a quarter past the hour.+  | ToHalf Int  -- ^ The parameter is the number of minutes until half, this is between @1@ and @14@.+  | Half  -- ^ It is half past an hour.+  | PastHalf Int  -- ^ The parameter is the number of minutes past half, this is between @1@ and @14@.+  | QuarterTo  -- ^ It is a quarter to an hour.+  | To Int  -- ^ The parameter is the number of minutes to the next hour, this is between @1@ and @14@.+  deriving (Eq, Ord, Read, Show)++-- | A data type that describes the state of the hours within a day.+data DayPart+  = Night  -- ^ It is night, this means that it is between @0:00@ and @5:59@.+  | Morning  -- ^ It is morning, this means that it is between @6:00@ and @11:59@.+  | Afternoon  -- ^ It is afternoon, this means it is between @12:00@ and @17:59@.+  | Evening  -- ^ It is evening, this means it is between @18:00@ and @23:59@.+  deriving (Bounded, Enum, Eq, Ord, Read, Show)++-- | A data type that describes the part of the day, and the number of hours on+-- a 12-hour clock.+data DaySegment+  = DaySegment {+        dayPart :: DayPart  -- ^ The part of the day.+      , dayHour :: Int  -- ^ The number of hours, between @1@ and @12@ (both inclusive).+      }+  deriving (Eq, Ord, Read, Show)+++-- | Convert the given number of minutes to the corresponding 'ClockSegment'.+toClockSegment+  :: Int  -- ^ The number of minutes.+  -> ClockSegment  -- ^ The corresponding 'ClockSegment'.+toClockSegment 0 = OClock+toClockSegment 15 = QuarterPast+toClockSegment 30 = Half+toClockSegment 45 = QuarterTo+toClockSegment n+    | n <= 15 = Past n+    | n <= 30 = ToHalf (30-n)+    | n <= 45 = PastHalf (n-30)+    | otherwise = To (60-n)++-- | Convert the given number of hours to the corresponding 'DayPart'.+toDayPart+  :: Int  -- ^ The given number of hours.+  -> DayPart  -- ^ The corresponding 'DayPart'.+toDayPart n+    | n <= 5 = Night+    | n <= 11 = Morning+    | n <= 17 = Afternoon+    | otherwise = Evening++-- | Convert the given number of hours to the corresponding 'DaySegment'.+toDaySegment+  :: Int  -- ^ The given number of hours.+  -> DaySegment  -- ^ The corresponding 'DaySegment'.+toDaySegment n = DaySegment (toDayPart n) (hourCorrection n)++-- | Correct the hour to a 12 number segment.+-- The input can be any Int number, whereas the+-- result will be in the @1 .. 12@ range.+hourCorrection+  :: Int  -- ^ The value for the number of hours.+  -> Int  -- ^ The hours in the @1 .. 12@ range.+hourCorrection h = ((h - 1) `mod` 12) + 1+ instance Default NumberType where     def = Cardinal @@ -117,7 +205,37 @@     toWords Cardinal = toCardinal     toWords Ordinal = toOrdinal     toWords ShortOrdinal = toShortOrdinal-    {-# MINIMAL toCardinal, toOrdinal, toShortOrdinal | toWords #-}+    +    -- | Convert the given time of the day to text describing that time.+    toTimeText+      :: a  -- ^ The conversion algorithm to transform numbers into words.+      -> TimeOfDay  -- ^ The time of the day to convert to words.+      -> Text  -- ^ The time as /text/.+    toTimeText gen (TimeOfDay h m _) = toTimeText' gen h m+    +    -- | Convert the given hours and minutes to text that describes the time.+    toTimeText'+      :: a  -- ^ The conversion algorithm to transform numbers into words.+      -> Int  -- ^ The number of hours, between 0 and 23 (both inclusive)+      -> Int  -- ^ The number of minutes, beween 0 and 59 (both inclusive)+      -> Text  -- ^ The time as /text/.+    toTimeText' gen h m = toTimeText gen (TimeOfDay h m 0)+    {-# MINIMAL ((toCardinal, toOrdinal, toShortOrdinal) | toWords), (toTimeText | toTimeText') #-}++-- | Convert the current time in the given 'TimeZone' to the time in words with the given 'NumToWord'+-- algorithm.+currentTimeText :: NumToWord a+  => TimeZone -- ^ The given 'TimeZone'.+  -> a  -- ^ The 'NumToWord' algorithm that converts time to words.+  -> IO Text  -- ^ An 'IO' that will generate a 'Text' object that describes the current time in words.+currentTimeText tz alg = toTimeText alg . snd . utcToLocalTimeOfDay tz . timeToTimeOfDay . utctDayTime <$> getCurrentTime++-- | Convert the current time to the time in words with the given 'NumToWord'+-- algorithm as UTC time.+currentTimeText' :: NumToWord a+  => a  -- ^ The 'NumToWord' algorithm that converts time to words.+  -> IO Text  -- ^ An 'IO' that will generate a 'Text' object that describes the current time in words.+currentTimeText' alg = toTimeText alg . timeToTimeOfDay . utctDayTime <$> getCurrentTime  -- | A type class used to split a value, based on the name of a number in a -- specific language. The value that is used to split, is often, depending on
src/Text/Numerals/Internal.hs view
@@ -2,6 +2,7 @@  module Text.Numerals.Internal (     _div10, _rem10, _divisableBy, _divisable100+  , _pluralize, _pluralize'   , _showText   , _mergeWith, _mergeWithSpace, _mergeWithHyphen, _mergeWith', _replaceSuffix   , _hundred, _thousand, _million, _billion, _trillion@@ -14,6 +15,17 @@ import Data.Char(intToDigit) import Data.Text(Text, cons, dropEnd, isSuffixOf, singleton, pack) import qualified Data.Text as T++_pluralize :: a -> a -> Int -> a+_pluralize sing plur = go+    where go 1 = sing+          go (-1) = sing+          go _ = plur++_pluralize' :: a -> a -> Int -> a+_pluralize' sing plur = go+    where go 1 = sing+          go _ = plur  _stripLastIf :: Char -> Text -> Text _stripLastIf c t
src/Text/Numerals/Languages/Dutch.hs view
@@ -13,6 +13,8 @@ module Text.Numerals.Languages.Dutch (     -- * Num to word algorithm     dutch+    -- * Convert a cardinal number to text+  , toCardinal'     -- * Convert to ordinal   , ordinize'     -- * Constant words@@ -28,8 +30,8 @@  import Text.Numerals.Algorithm(HighNumberAlgorithm(LongScale), NumeralsAlgorithm, numeralsAlgorithm) import Text.Numerals.Algorithm.Template(ordinizeFromDict)-import Text.Numerals.Class(valueSplit)-import Text.Numerals.Internal(_million, _mergeWithSpace, _showIntegral)+import Text.Numerals.Class(ClockSegment(OClock, Past, QuarterPast, ToHalf, Half, PastHalf, QuarterTo, To), DayPart(Night, Morning, Afternoon, Evening), DaySegment(dayPart, dayHour), ClockText, hourCorrection, toCardinal, valueSplit)+import Text.Numerals.Internal(_million, _mergeWithSpace, _pluralize', _showIntegral)  $(pure (ordinizeFromDict "_ordinize'" [     ("nul", "nuld")@@ -59,8 +61,14 @@  -- | A 'NumeralsAlgorithm' to convert numbers to words in the /Dutch/ language. dutch :: NumeralsAlgorithm  -- ^ A 'NumeralsAlgorithm' that can be used to convert numbers to different formats.-dutch = numeralsAlgorithm negativeWord' zeroWord' oneWord' lowWords' midWords' (valueSplit highWords') merge' ordinize' shortOrdinal'+dutch = numeralsAlgorithm negativeWord' zeroWord' oneWord' lowWords' midWords' (valueSplit highWords') merge' ordinize' shortOrdinal' clockText' +-- | Convert numers to their cardinal counterpart in /Dutch/.+toCardinal' :: Integral i+  => i  -- ^ The number to convert to text.+  -> Text  -- ^ The cardinal counterpart in /Dutch/.+toCardinal' = toCardinal dutch+ -- | The words used to mark a negative number in the /Dutch/ language. negativeWord' :: Text negativeWord' = "min"@@ -151,3 +159,29 @@   => i  -- ^ The number to convert to /short ordinal/ form.   -> Text  -- ^ The equivalent 'Text' specifying the number in /short ordinal/ form. shortOrdinal' = pack . (`_showIntegral` "e")++_dayPartText :: DayPart -> Text+_dayPartText Night = "'s nachts"+_dayPartText Morning = "'s ochtends"+_dayPartText Afternoon = "'s middags"+_dayPartText Evening = "'s avonds"++_dayComponent :: Text -> Int -> DaySegment -> Text+_dayComponent sep dh h = toCardinal' (hourCorrection (dayHour h + dh)) <> sep <> _dayPartText (dayPart h)++_dayComponent' :: Int -> DaySegment -> Text+_dayComponent' = _dayComponent " "++_mins :: Int -> Text+_mins = _pluralize' " minuut " " minuten "++-- | Converting the time to a text that describes that time in /Dutch/.+clockText' :: ClockText+clockText' OClock ds _ _ = _dayComponent " uur " 0 ds+clockText' (Past m) ds _ _ = toCardinal' m <> _mins m <> "na " <> _dayComponent' 0 ds+clockText' QuarterPast ds _ _ = "kwart na "  <> _dayComponent' 0 ds+clockText' (ToHalf m) ds _ _ = toCardinal' m <> _mins m <> "voor half " <> _dayComponent' 1 ds+clockText' Half ds _ _ = "half " <> _dayComponent' 1 ds+clockText' (PastHalf m) ds _ _ = toCardinal' m <> _mins m <> "na half " <> _dayComponent' 1 ds+clockText' QuarterTo ds _ _ = "kwart voor "  <> _dayComponent' 1 ds+clockText' (To m) ds _ _ = toCardinal' m <> _mins m <> "voor " <> _dayComponent' 1 ds
src/Text/Numerals/Languages/English.hs view
@@ -13,6 +13,8 @@ module Text.Numerals.Languages.English (     -- * Num to word algorithm     english+    -- * Convert a cardinal number to text+  , toCardinal'     -- * Convert to ordinal   , ordinize'     -- * Constant words@@ -30,7 +32,7 @@  import Text.Numerals.Algorithm(HighNumberAlgorithm, NumeralsAlgorithm, numeralsAlgorithm) import Text.Numerals.Algorithm.Template(ordinizeFromDict)-import Text.Numerals.Class(valueSplit)+import Text.Numerals.Class(ClockSegment(OClock, Past, QuarterPast, ToHalf, Half, PastHalf, QuarterTo, To), DayPart(Night, Morning, Afternoon, Evening), DaySegment(dayPart, dayHour), ClockText, hourCorrection, valueSplit, toCardinal) import Text.Numerals.Internal(_div10, _mergeWith, _mergeWithSpace, _mergeWithHyphen, _rem10, _showIntegral)  _ordinizepp :: Text -> Text@@ -57,8 +59,14 @@  -- | A 'NumeralsAlgorithm' to convert numbers to words in the /English/ language. english :: NumeralsAlgorithm  -- ^ A 'NumeralsAlgorithm' that can be used to convert numbers to different formats.-english = numeralsAlgorithm negativeWord' zeroWord' oneWord' lowWords' midWords' (valueSplit highWords') merge' ordinize' shortOrdinal'+english = numeralsAlgorithm negativeWord' zeroWord' oneWord' lowWords' midWords' (valueSplit highWords') merge' ordinize' shortOrdinal' clockText' +-- | Convert numers to their cardinal counterpart in /English/.+toCardinal' :: Integral i+  => i  -- ^ The number to convert to text.+  -> Text  -- ^ The cardinal counterpart in /English/.+toCardinal' = toCardinal english+ -- | The words used to mark a negative number in the /English/ language. negativeWord' :: Text negativeWord' = "minus"@@ -136,3 +144,26 @@           go' 2 = "nd"           go' 3 = "rd"           go' _ = "th"++_dayPartText :: DayPart -> Text+_dayPartText Night = "at night"+_dayPartText Morning = "in the morning"+_dayPartText Afternoon = "in the afternoon"+_dayPartText Evening = "in the evening"++_dayComponent :: Text -> Int -> DaySegment -> Text+_dayComponent sep dh h = toCardinal' (hourCorrection (dayHour h + dh)) <> sep <> _dayPartText (dayPart h)++_dayComponent' :: Int -> DaySegment -> Text+_dayComponent' = _dayComponent " "++-- | Converting the time to a text that describes that time in /English/.+clockText' :: ClockText+clockText' OClock ds _ _ = _dayComponent " o'clock " 0 ds+clockText' (Past m) ds _ _ = toCardinal' m <> " past " <> _dayComponent' 0 ds+clockText' QuarterPast ds _ _ = "quarter past "  <> _dayComponent' 0 ds+clockText' (ToHalf _) ds _ m = toCardinal' m <> " past " <> _dayComponent' 0 ds+clockText' Half ds _ _ = "half past " <> _dayComponent' 0 ds+clockText' (PastHalf _) ds _ m = toCardinal' (60 - m) <> " to " <> _dayComponent' 1 ds+clockText' QuarterTo ds _ _ = "quarter to "  <> _dayComponent' 1 ds+clockText' (To m) ds _ _ = toCardinal' m <> " to " <> _dayComponent' 1 ds
src/Text/Numerals/Languages/French.hs view
@@ -13,6 +13,8 @@ module Text.Numerals.Languages.French (     -- * Num to word algorithm     french+    -- * Convert a cardinal number to text+  , toCardinal'     -- * Convert to ordinal   , ordinize'     -- * Constant words@@ -28,8 +30,8 @@  import Text.Numerals.Algorithm(HighNumberAlgorithm(LongScale), NumeralsAlgorithm, numeralsAlgorithm) import Text.Numerals.Algorithm.Template(ordinizeFromDict)-import Text.Numerals.Class(FreeMergerFunction, valueSplit)-import Text.Numerals.Internal(_divisable100, _mergeWith, _mergeWithSpace, _mergeWithHyphen, _million, _showIntegral, _stripLastIf, _thousand)+import Text.Numerals.Class(ClockSegment(OClock, QuarterPast, Half, QuarterTo), DayPart(Night, Morning, Afternoon, Evening), DaySegment(dayPart, dayHour), ClockText, FreeMergerFunction, valueSplit, toCardinal)+import Text.Numerals.Internal(_divisable100, _mergeWith, _mergeWithSpace, _mergeWithHyphen, _million, _pluralize', _showIntegral, _stripLastIf, _thousand)  $(pure (ordinizeFromDict "_ordinize'" [     ("cinq", "cinqu")@@ -38,8 +40,14 @@  -- | A 'NumeralsAlgorithm' to convert numbers to words in the /French/ language. french :: NumeralsAlgorithm  -- ^ A 'NumeralsAlgorithm' that can be used to convert numbers to different formats.-french = numeralsAlgorithm negativeWord' zeroWord' oneWord' lowWords' midWords' (valueSplit highWords') merge' ordinize' shortOrdinal'+french = numeralsAlgorithm negativeWord' zeroWord' oneWord' lowWords' midWords' (valueSplit highWords') merge' ordinize' shortOrdinal' clockText' +-- | Convert numers to their cardinal counterpart in /French/.+toCardinal' :: Integral i+  => i  -- ^ The number to convert to text.+  -> Text  -- ^ The cardinal counterpart in /French/.+toCardinal' = toCardinal french+ -- | The words used to mark a negative number in the /French/ language. negativeWord' :: Text negativeWord' = "moins"@@ -128,3 +136,25 @@   => i  -- ^ The number to convert to /short ordinal/ form.   -> Text  -- ^ The equivalent 'Text' specifying the number in /short ordinal/ form. shortOrdinal' = pack . (`_showIntegral` "e")++_dayPartText :: DayPart -> Text+_dayPartText Night = " de la nuit"+_dayPartText Morning = " du matin"+_dayPartText Afternoon = " de l'après-midi"+_dayPartText Evening = " du soir"++_heures :: Text -> Int -> DaySegment -> Text+_heures sep dh ds = toCardinal' h <> _pluralize' "e heure" " heures" h <> sep <> _dayPartText (dayPart ds)+    where h = dayHour ds + dh++-- | Converting the time to a text that describes that time in /French/.+clockText' :: ClockText+clockText' _ _ 0 0 = "minuit"+clockText' _ _ 12 0 = "midi"+clockText' OClock ds _ _ = _heures "" 0 ds+clockText' QuarterPast ds _ _ = _heures " et quart" 0 ds+clockText' Half ds _ _ = _heures " et demie" 0 ds+clockText' QuarterTo ds _ _ = _heures " moins le quart" 1 ds+clockText' _ ds _ m+    | m <= 30 = _heures (" " <> toCardinal' m) 0 ds+    | otherwise = _heures (" moins " <> toCardinal' (60 - m)) 1 ds
src/Text/Numerals/Languages/German.hs view
@@ -13,6 +13,8 @@ module Text.Numerals.Languages.German (     -- * Num to word algorithm     german+    -- * Convert a cardinal number to text+  , toCardinal'     -- * Convert to ordinal   , ordinize'     -- * Constant words@@ -29,7 +31,7 @@  import Text.Numerals.Algorithm(HighNumberAlgorithm(LongScale), NumeralsAlgorithm, numeralsAlgorithm, valueSplit') import Text.Numerals.Algorithm.Template(ordinizeFromDict)-import Text.Numerals.Class(FreeMergerFunction)+import Text.Numerals.Class(ClockText, FreeMergerFunction, toCardinal) import Text.Numerals.Internal(_mergeWith, _mergeWithSpace, _million, _showIntegral) import Text.RE.TDFA.Text(RE, SearchReplace, (*=~/), ed) @@ -49,8 +51,14 @@  -- | A 'NumeralsAlgorithm' to convert numbers to words in the /German/ language. german :: NumeralsAlgorithm  -- ^ A 'NumeralsAlgorithm' that can be used to convert numbers to different formats.-german = numeralsAlgorithm negativeWord' zeroWord' oneWord' lowWords' midWords' (valueSplit' toTitle highWords') merge' ordinize' shortOrdinal'+german = numeralsAlgorithm negativeWord' zeroWord' oneWord' lowWords' midWords' (valueSplit' toTitle highWords') merge' ordinize' shortOrdinal' clockText' +-- | Convert numers to their cardinal counterpart in /German/.+toCardinal' :: Integral i+  => i  -- ^ The number to convert to text.+  -> Text  -- ^ The cardinal counterpart in /German/.+toCardinal' = toCardinal german+ -- | The words used to mark a negative number in the /German/ language. negativeWord' :: Text negativeWord' = "minus"@@ -148,3 +156,8 @@   => i  -- ^ The number to convert to /short ordinal/ form.   -> Text  -- ^ The equivalent 'Text' specifying the number in /short ordinal/ form. shortOrdinal' = pack . (`_showIntegral` ".")++-- | Converting the time to a text that describes that time in /German/.+clockText' :: ClockText+clockText' _ _ h 0 = toCardinal' h <> " Uhr"+clockText' _ _ h m = toCardinal' h <> " Uhr " <> toCardinal' m