1 {-# LANGUAGE StandaloneDeriving #-}
2 {-# LANGUAGE TypeSynonymInstances #-}
3 {-# OPTIONS_GHC -fno-warn-orphans #-}
4 module Hcompta.Date where
6 import qualified Data.Fixed
7 import qualified Data.Time.Calendar as Time
8 import qualified Data.Time.Clock as Time
9 import qualified Data.Time.Clock.POSIX as Time (posixSecondsToUTCTime)
10 import qualified Data.Time.Format as Time ()
11 import qualified Data.Time.LocalTime as Time
13 -- import qualified Hcompta.Lib.Interval.Sieve as Interval.Sieve
17 type Date = Time.UTCTime
24 type Second = Data.Fixed.Pico
27 nil = Time.posixSecondsToUTCTime 0
30 now = Time.getCurrentTime
32 date :: Year -> Month -> DoM -> Hour -> Minute -> Second -> Maybe Date
33 date y m d h mn s = do
34 gday <- Time.fromGregorianValid y m d
35 hod <- Time.makeTimeOfDayValid h mn s
38 Time.timeOfDayToTime hod
42 gregorian :: Date -> (Year, Month, DoM)
43 gregorian = Time.toGregorian . Time.utctDay
46 year = (\(x, _, _) -> x) . gregorian
48 month :: Date -> Month
49 month = (\(_, x, _) -> x) . gregorian
55 dom = (\(_, _, x) -> x) . gregorian
57 tod :: Date -> Time.TimeOfDay
58 tod = Time.timeToTimeOfDay . Time.utctDayTime
61 hour = (\(Time.TimeOfDay x _ _) -> x) . tod
63 minute :: Date -> Minute
64 minute = (\(Time.TimeOfDay _ x _) -> x) . tod
66 second :: Date -> Second
67 second = (\(Time.TimeOfDay _ _ x) -> x) . tod
69 next_year_start :: Date -> Date
72 Time.addGregorianYearsClip
77 utc :: Date -> Time.UTCTime
80 bench :: IO a -> IO (a, Time.NominalDiffTime)
85 return (r, Time.diffUTCTime t1 t0)
93 | Interval_Quarters Int
95 | Interval_DayOfMonth Int
96 | Interval_DayOfWeek Int
97 -- Interval_WeekOfYear Int
98 -- Interval_MonthOfYear Int
99 -- Interval_QuarterOfYear Int
100 deriving (Data, Eq, Ord, Read, Show, Typeable)
104 = (String, String, String)
108 deriving (Eq, Read, Show)