1 {-# LANGUAGE DeriveDataTypeable #-}
2 {-# LANGUAGE StandaloneDeriving #-}
3 {-# LANGUAGE TypeSynonymInstances #-}
4 {-# OPTIONS_GHC -fno-warn-orphans #-}
5 module Hcompta.Model.Date where
8 import qualified Data.Fixed
9 import qualified Data.Time.Calendar as Time
10 import qualified Data.Time.Clock as Time
11 import qualified Data.Time.Clock.POSIX as Time (posixSecondsToUTCTime)
12 import qualified Data.Time.Format as Time ()
13 import qualified Data.Time.LocalTime as Time
14 import Data.Typeable ()
18 type Date = Time.UTCTime
21 nil = Time.posixSecondsToUTCTime 0
23 gregorian :: Date -> (Integer, Int, Int)
24 gregorian = Time.toGregorian . Time.utctDay
26 year :: Date -> Integer
27 year = (\(x, _, _) -> x) . gregorian
30 month = (\(_, x, _) -> x) . gregorian
33 dom = (\(_, _, x) -> x) . gregorian
35 tod :: Date -> Time.TimeOfDay
36 tod = Time.timeToTimeOfDay . Time.utctDayTime
39 hour = (\(Time.TimeOfDay x _ _) -> x) . tod
42 minute = (\(Time.TimeOfDay _ x _) -> x) . tod
44 second :: Date -> Data.Fixed.Pico
45 second = (\(Time.TimeOfDay _ _ x) -> x) . tod
52 | Interval_Quarters Int
54 | Interval_DayOfMonth Int
55 | Interval_DayOfWeek Int
56 -- Interval_WeekOfYear Int
57 -- Interval_MonthOfYear Int
58 -- Interval_QuarterOfYear Int
59 deriving (Data, Eq, Ord, Read, Show, Typeable)
62 = (String, String, String)
65 = Span (Maybe Time.Day) (Maybe Time.Day)
66 deriving (Data, Eq, Ord, Read, Show, Typeable)
71 deriving (Eq, Read, Show)