DateUtils.hs 977 Bytes
Newer Older
1
{-|
2
Module      : Gargantext.Core.Utils.DateUtils
3 4 5 6 7 8 9 10 11 12
Description : 
Copyright   : (c) CNRS, 2017-Present
License     : AGPL + CECILL v3
Maintainer  : team@gargantext.org
Stability   : experimental
Portability : POSIX
-}

{-# LANGUAGE NoImplicitPrelude #-}

13
module Gargantext.Core.Utils.DateUtils where
14

15
import Gargantext.Prelude
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
import Data.Time (UTCTime, toGregorian, utctDay)

--
--readInt :: IO [Char] -> IO Int
--readInt = readLn
--
--readBool :: IO [Char] -> IO Bool
--readBool = readLn

utc2gregorian :: UTCTime -> (Integer, Int, Int)
utc2gregorian date = toGregorian $ utctDay date

gregorian2year :: (Integer, Int, Int) -> Integer
gregorian2year (y, _m, _d) = y

utc2year :: UTCTime -> Integer
utc2year date = gregorian2year $ utc2gregorian date

averageLength :: Fractional a => [[a1]] -> a
averageLength l = fromIntegral (sum (map length l)) / fromIntegral (length l)

--main :: IO ()
--main = do
--	c <- getCurrentTime
--	print c -- $ toYear $ toGregorian $ utctDay c