]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Utils/Chronos.purs
[APP] command line options added.
[gargantext.git] / src / Gargantext / Utils / Chronos.purs
1 module Data.Gargantext.Utils.Chronos where
2
3 import Data.Maybe (fromJust, isJust, isNothing)
4 import qualified Data.Time as DT
5 import qualified Data.UTC as DU
6
7 import Data.Time
8 import Data.Time.Clock.POSIX
9 import Text.Regex
10
11 parseDate :: String -> Maybe [String]
12 parseDate d = matchRegex (mkRegex "(.*)/(.*)/(.*)") d
13
14 getDate' :: Maybe [String] -> (Integer, Int, Int)
15 getDate' d
16 | isJust d == True = toGregorian $ fromGregorian (read year) (read month) (read day)
17 | otherwise = toGregorian $ fromGregorian 2015 1 1
18 where
19 Just [day, month, year] = d
20
21 getDate :: String -> (Integer, Int, Int)
22 getDate = getDate' . parseDate
23
24 --getDateDay :: Maybe [String] -> Day
25 --getDateDay d = fromGregorian (read year) (read month) (read day)
26 -- where Just [day, month, year] = matchRegex (mkRegex "(.*)/(.*)/(.*)") d
27
28 getDateDay' :: Maybe [String] -> Day
29 getDateDay' d
30 | isJust d == True = fromGregorian (read year) (read month) (read day)
31 | otherwise = fromGregorian 2015 1 1
32 where Just [day, month, year] = d
33
34 getDateDay :: String -> Day
35 getDateDay = getDateDay' . parseDate
36
37 getDateUTC :: String -> String
38 getDateUTC d = show $ DT.UTCTime (getDateDay d) (DT.timeOfDayToTime $ DT.TimeOfDay 0 0 0)
39
40 getYear :: String -> String
41 getYear date = s where
42 (y, m, d) = getDate date
43 s = show y
44
45 getMonth :: String -> String
46 getMonth date = s where
47 (y, m, d) = getDate date
48 s = show m
49
50 getDay :: String -> String
51 getDay date = s where
52 (y, m, d) = getDate date
53 s = show d
54
55 --for Dates exported via xls2csv tool
56 type MT = Maybe (DU.Local DU.DateTime)
57 type MS = Maybe String
58
59 --getDate'' :: String -> String
60 --getDate'' gd = d where
61 -- start = "1900-01-01T00:00:00Z"
62 -- da = (DU.parseRfc3339 start :: MT) >>= DU.addDays ( (read gd :: Integer) -2) >>= DU.renderRfc3339 :: MS
63 -- d = fromJust da
64 --
65 --getDate''' :: String -> String
66 --getDate''' gd = d where
67 -- start = "1900-01-01T00:00:00Z"
68 -- da = (DU.parseRfc3339 start :: MT) >>= DU.addDays ( (read gd :: Integer) -2) >>= DU.renderIso8601CalendarDate :: MS
69 -- d = fromJust da
70 --
71 --date2greg :: String ->
72 date2greg date = (y, m, d) where
73 (y, m, d) = DT.toGregorian $ DT.addDays ((read date :: Integer) -2) $ DT.utctDay (read "1900-01-01 00:00:00" :: DT.UTCTime)
74
75
76 getYear' :: String -> String
77 getYear' date = s where
78 (y, m, d) = date2greg date
79 s = show y
80
81
82 getMonth' :: String -> String
83 getMonth' date = s where
84 (y, m, d) = date2greg date
85 s = show m
86
87
88 getDay' :: String -> String
89 getDay' date = s where
90 (y, m, d) = date2greg date
91 s = show d
92
93
94