1 {-# OPTIONS_GHC -fno-warn-orphans #-}
2 module Hcompta.Date where
4 import qualified Data.Fixed
5 import qualified Data.Time.Calendar as Time
6 import qualified Data.Time.Clock as Time
7 import qualified Data.Time.Clock.POSIX as Time (posixSecondsToUTCTime)
8 import qualified Data.Time.Format as Time ()
9 import qualified Data.Time.LocalTime as Time
11 -- import qualified Hcompta.Lib.Interval.Sieve as Interval.Sieve
15 type Date = Time.UTCTime
22 type Second = Data.Fixed.Pico
25 nil = Time.posixSecondsToUTCTime 0
28 now = Time.getCurrentTime
30 date :: Year -> Month -> DoM -> Hour -> Minute -> Second -> Maybe Date
31 date y m d h mn s = do
32 gday <- Time.fromGregorianValid y m d
33 hod <- Time.makeTimeOfDayValid h mn s
36 Time.timeOfDayToTime hod
40 gregorian :: Date -> (Year, Month, DoM)
41 gregorian = Time.toGregorian . Time.utctDay
44 year = (\(x, _, _) -> x) . gregorian
46 month :: Date -> Month
47 month = (\(_, x, _) -> x) . gregorian
53 dom = (\(_, _, x) -> x) . gregorian
55 tod :: Date -> Time.TimeOfDay
56 tod = Time.timeToTimeOfDay . Time.utctDayTime
59 hour = (\(Time.TimeOfDay x _ _) -> x) . tod
61 minute :: Date -> Minute
62 minute = (\(Time.TimeOfDay _ x _) -> x) . tod
64 second :: Date -> Second
65 second = (\(Time.TimeOfDay _ _ x) -> x) . tod
67 next_year_start :: Date -> Date
70 Time.addGregorianYearsClip
75 utc :: Date -> Time.UTCTime
78 bench :: IO a -> IO (a, Time.NominalDiffTime)
83 return (r, Time.diffUTCTime t1 t0)
91 | Interval_Quarters Int
93 | Interval_DayOfMonth Int
94 | Interval_DayOfWeek Int
95 -- Interval_WeekOfYear Int
96 -- Interval_MonthOfYear Int
97 -- Interval_QuarterOfYear Int
98 deriving (Data, Eq, Ord, Read, Show, Typeable)
102 = (String, String, String)
106 deriving (Eq, Read, Show)