1 {-# OPTIONS_GHC -fno-warn-orphans #-}
2 module Hcompta.Date where
4 import Control.Monad (Monad(..))
5 import qualified Data.Fixed
6 import Data.Maybe (Maybe(..))
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
23 type Date = Time.UTCTime
30 type Second = Data.Fixed.Pico
33 nil = Time.posixSecondsToUTCTime 0
36 now = Time.getCurrentTime
38 date :: Year -> Month -> DoM -> Hour -> Minute -> Second -> Maybe Date
39 date y m d h mn s = do
40 gday <- Time.fromGregorianValid y m d
41 hod <- Time.makeTimeOfDayValid h mn s
44 Time.timeOfDayToTime hod
48 gregorian :: Date -> (Year, Month, DoM)
49 gregorian = Time.toGregorian . Time.utctDay
52 year = (\(x, _, _) -> x) . gregorian
54 month :: Date -> Month
55 month = (\(_, x, _) -> x) . gregorian
61 dom = (\(_, _, x) -> x) . gregorian
63 tod :: Date -> Time.TimeOfDay
64 tod = Time.timeToTimeOfDay . Time.utctDayTime
67 hour = (\(Time.TimeOfDay x _ _) -> x) . tod
69 minute :: Date -> Minute
70 minute = (\(Time.TimeOfDay _ x _) -> x) . tod
72 second :: Date -> Second
73 second = (\(Time.TimeOfDay _ _ x) -> x) . tod
75 next_year_start :: Date -> Date
78 Time.addGregorianYearsClip
83 utc :: Date -> Time.UTCTime
86 bench :: IO a -> IO (a, Time.NominalDiffTime)
91 return (r, Time.diffUTCTime t1 t0)
99 | Interval_Quarters Int
101 | Interval_DayOfMonth Int
102 | Interval_DayOfWeek Int
103 -- Interval_WeekOfYear Int
104 -- Interval_MonthOfYear Int
105 -- Interval_QuarterOfYear Int
106 deriving (Data, Eq, Ord, Read, Show, Typeable)
110 = (String, String, String)
114 deriving (Eq, Read, Show)