1 {-# LANGUAGE TypeSynonymInstances #-}
2 {-# OPTIONS_GHC -fno-warn-orphans #-}
3 module Hcompta.Date where
5 import qualified Data.Fixed
6 import qualified Data.Time.Calendar as Time
7 import qualified Data.Time.Clock as Time
8 import qualified Data.Time.Clock.POSIX as Time (posixSecondsToUTCTime)
9 import qualified Data.Time.Format as Time ()
10 import qualified Data.Time.LocalTime as Time
12 -- import qualified Hcompta.Lib.Interval.Sieve as Interval.Sieve
16 type Date = Time.UTCTime
23 type Second = Data.Fixed.Pico
26 nil = Time.posixSecondsToUTCTime 0
29 now = Time.getCurrentTime
31 date :: Year -> Month -> DoM -> Hour -> Minute -> Second -> Maybe Date
32 date y m d h mn s = do
33 gday <- Time.fromGregorianValid y m d
34 hod <- Time.makeTimeOfDayValid h mn s
37 Time.timeOfDayToTime hod
41 gregorian :: Date -> (Year, Month, DoM)
42 gregorian = Time.toGregorian . Time.utctDay
45 year = (\(x, _, _) -> x) . gregorian
47 month :: Date -> Month
48 month = (\(_, x, _) -> x) . gregorian
54 dom = (\(_, _, x) -> x) . gregorian
56 tod :: Date -> Time.TimeOfDay
57 tod = Time.timeToTimeOfDay . Time.utctDayTime
60 hour = (\(Time.TimeOfDay x _ _) -> x) . tod
62 minute :: Date -> Minute
63 minute = (\(Time.TimeOfDay _ x _) -> x) . tod
65 second :: Date -> Second
66 second = (\(Time.TimeOfDay _ _ x) -> x) . tod
68 next_year_start :: Date -> Date
71 Time.addGregorianYearsClip
76 utc :: Date -> Time.UTCTime
79 bench :: IO a -> IO (a, Time.NominalDiffTime)
84 return (r, Time.diffUTCTime t1 t0)
92 | Interval_Quarters Int
94 | Interval_DayOfMonth Int
95 | Interval_DayOfWeek Int
96 -- Interval_WeekOfYear Int
97 -- Interval_MonthOfYear Int
98 -- Interval_QuarterOfYear Int
99 deriving (Data, Eq, Ord, Read, Show, Typeable)
103 = (String, String, String)
107 deriving (Eq, Read, Show)