]> Git — Sourcephile - comptalang.git/blob - lib/Hcompta/Date.hs
Ajout : CLI.Command.* : intégration de --reduce-date.
[comptalang.git] / lib / Hcompta / Date.hs
1 {-# LANGUAGE StandaloneDeriving #-}
2 {-# LANGUAGE TypeSynonymInstances #-}
3 {-# OPTIONS_GHC -fno-warn-orphans #-}
4 module Hcompta.Date where
5
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
12
13 -- import qualified Hcompta.Lib.Interval.Sieve as Interval.Sieve
14
15 -- * Type 'Date'
16
17 type Date = Time.UTCTime
18 type Year = Integer
19 type Month = Int
20 type Day = Time.Day
21 type DoM = Int
22 type Hour = Int
23 type Minute = Int
24 type Second = Data.Fixed.Pico
25
26 nil :: Date
27 nil = Time.posixSecondsToUTCTime 0
28
29 now :: IO Date
30 now = Time.getCurrentTime
31
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
36 return $
37 Time.UTCTime gday $
38 Time.timeOfDayToTime hod
39
40 -- ** Components
41
42 gregorian :: Date -> (Year, Month, DoM)
43 gregorian = Time.toGregorian . Time.utctDay
44
45 year :: Date -> Year
46 year = (\(x, _, _) -> x) . gregorian
47
48 month :: Date -> Month
49 month = (\(_, x, _) -> x) . gregorian
50
51 day :: Date -> Day
52 day = Time.utctDay
53
54 dom :: Date -> DoM
55 dom = (\(_, _, x) -> x) . gregorian
56
57 tod :: Date -> Time.TimeOfDay
58 tod = Time.timeToTimeOfDay . Time.utctDayTime
59
60 hour :: Date -> Hour
61 hour = (\(Time.TimeOfDay x _ _) -> x) . tod
62
63 minute :: Date -> Minute
64 minute = (\(Time.TimeOfDay _ x _) -> x) . tod
65
66 second :: Date -> Second
67 second = (\(Time.TimeOfDay _ _ x) -> x) . tod
68
69 next_year_start :: Date -> Date
70 next_year_start d =
71 nil{ Time.utctDay =
72 Time.addGregorianYearsClip
73 (year d + 1 - 1970)
74 (Time.utctDay d)
75 }
76
77 utc :: Date -> Time.UTCTime
78 utc = id
79
80 {-
81 data Interval
82 = Interval_None
83 | Interval_Days Int
84 | Interval_Weeks Int
85 | Interval_Months Int
86 | Interval_Quarters Int
87 | Interval_Years Int
88 | Interval_DayOfMonth Int
89 | Interval_DayOfWeek Int
90 -- Interval_WeekOfYear Int
91 -- Interval_MonthOfYear Int
92 -- Interval_QuarterOfYear Int
93 deriving (Data, Eq, Ord, Read, Show, Typeable)
94
95
96 type Smart
97 = (String, String, String)
98 data Which
99 = Which_Primary
100 | Which_Secondary
101 deriving (Eq, Read, Show)
102 -}