Correction : CLI.Command.Balance : critère de redondance
[comptalang.git] / lib / Hcompta / Model / Date.hs
index 31b7cccefbcb80ba8405209a346f01a293377eb6..117a98b396e663bc4672db8d0852dac90cac98de 100644 (file)
@@ -1,35 +1,58 @@
 {-# LANGUAGE DeriveDataTypeable #-}
-module Hcompta.Model.Date
- ( module Hcompta.Model.Date
- , Day
- )
- where
+{-# LANGUAGE StandaloneDeriving #-}
+{-# LANGUAGE TypeSynonymInstances #-}
+{-# OPTIONS_GHC -fno-warn-orphans #-}
+module Hcompta.Model.Date where
 
-import Data.Data
-import Data.Time.Calendar (Day)
-import Data.Time.Format ()
-import Data.Typeable ()
+import           Data.Data
+import qualified Data.Time.LocalTime   as Time (ZonedTime(..), utc, utcToZonedTime, zonedTimeToUTC)
+import qualified Data.Time.Calendar    as Time (Day)
+import qualified Data.Time.Format      as Time ()
+import qualified Data.Time.Clock.POSIX as Time (posixSecondsToUTCTime)
+import qualified Data.Time.Clock       as Time (UTCTime)
+import           Data.Typeable ()
 
-type Smart =
- (String, String, String)
+-- * The 'Date' type
 
-data Which
- = Primary
- | Secondary
- deriving (Eq, Read, Show)
+type Date
+ = Time.ZonedTime
+deriving instance Eq Date
 
-data Span
- = Span (Maybe Day) (Maybe Day)
- deriving (Data, Eq, Ord, Read, Show, Typeable)
+nil :: Date
+nil = Time.utcToZonedTime Time.utc $ Time.posixSecondsToUTCTime 0
 
 data Interval
- = NoInterval
- | Days Int
- | Weeks Int
- | Months Int
- | Quarters Int
- | Years Int
- | DayOfMonth Int
- | DayOfWeek Int
- -- WeekOfYear Int | MonthOfYear Int | QuarterOfYear Int
+ =   Interval_None
+ |   Interval_Days Int
+ |   Interval_Weeks Int
+ |   Interval_Months Int
+ |   Interval_Quarters Int
+ |   Interval_Years Int
+ |   Interval_DayOfMonth Int
+ |   Interval_DayOfWeek Int
+ -- Interval_WeekOfYear Int
+ -- Interval_MonthOfYear Int
+ -- Interval_QuarterOfYear Int
+ deriving (Data, Eq, Ord, Read, Show, Typeable)
+
+type Smart
+ = (String, String, String)
+
+data Span
+ =   Span (Maybe Time.Day) (Maybe Time.Day)
  deriving (Data, Eq, Ord, Read, Show, Typeable)
+
+data Which
+ =   Which_Primary
+ |   Which_Secondary
+ deriving (Eq, Read, Show)
+
+type Year
+ = Integer
+
+-- * The 'UTC' type
+
+type UTC = Time.UTCTime
+
+to_UTC :: Date -> UTC
+to_UTC = Time.zonedTimeToUTC