uniform-time (empty) → 0.1.0
raw patch · 5 files changed
+228/−0 lines, 5 filesdep +basedep +convertibledep +monads-tfsetup-changed
Dependencies added: base, convertible, monads-tf, time, uniform-algebras, uniform-error, uniform-strings
Files
- ChangeLog.md +2/−0
- README.md +7/−0
- Setup.lhs +6/−0
- Uniform/Time.hs +163/−0
- uniform-time.cabal +50/−0
+ ChangeLog.md view
@@ -0,0 +1,2 @@+ version 0.1.0 to find problem with building + and move to workspace11
+ README.md view
@@ -0,0 +1,7 @@+A unifified manipulation of time and date representations.++Uniform means:+- same functions with identical semantics independent of representation+- all functions are total (or become so using Maybe or Either)++Conversions from `EpochTime` to `UTCTime` and then to `YMD` and similar semantic structures.
+ Setup.lhs view
@@ -0,0 +1,6 @@+#!/usr/bin/runhaskell +> module Main where+> import Distribution.Simple+> main :: IO ()+> main = defaultMain+
+ Uniform/Time.hs view
@@ -0,0 +1,163 @@+----------------------------------------------------------------------+--+-- Module : Uniform.Time+--+----------------------------------------------------------------------+{-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE MultiParamTypeClasses #-}+{-# LANGUAGE OverloadedStrings #-}++-- | a minimal set of time operations+-- at the moment only a wrapper to time+-- examples in TestingTime.hs+module Uniform.Time+ ( module Uniform.Time,+ -- module Uniform.Strings, + EpochTime,+ UTCTime (..),+ ErrIO + )+where++import Data.Convertible (convert)+import Data.Time as T+ ( NominalDiffTime,+ UTCTime (..),+ addUTCTime,+ defaultTimeLocale,+ diffDays,+ diffUTCTime,+ formatTime,+ getCurrentTime,+ parseTimeM,+ parseTimeOrError,+ toGregorian,+ )+import Data.Time.Clock.POSIX+ ( getCurrentTime, posixSecondsToUTCTime )+import System.Posix.Types (EpochTime)++import Uniform.Error+--(ErrIO, errorT)++import Uniform.Strings+-- Text, CharChains2, show', IsString(..), t2s, s2)++import Uniform.Zero++year2000 :: UTCTime+year2000 = readDate3 "2000-01-01"+-- ^ may serve as zero in some applications++instance CharChains2 UTCTime Text where -- orphan instance+ show' = s2t . show++instance CharChains2 T.NominalDiffTime Text where+ show' = s2t . show++instance CharChains2 (Integer, Int, Int) Text where+ show' = s2t . show++instance IsString UTCTime where+ fromString = readNote "IsString UTCTime"++getCurrentTimeUTC :: ErrIO UTCTime+addSeconds :: Double -> UTCTime -> UTCTime+diffSeconds :: UTCTime -> UTCTime -> T.NominalDiffTime+getCurrentTimeUTC = liftIO T.getCurrentTime++addSeconds s t = T.addUTCTime (realToFrac s) t++diffSeconds = T.diffUTCTime++toYMD :: UTCTime -> (Integer, Int, Int)+toYMD = T.toGregorian . T.utctDay++diffDays :: UTCTime -> UTCTime -> Integer+diffDays a b = T.diffDays (T.utctDay a) (T.utctDay b)++epochTime2UTCTime :: EpochTime -> UTCTime+epochTime2UTCTime = convert++getDateAsText :: ErrIO Text+getDateAsText = callIO $ do+ now <- getCurrentTime+ let res = formatTime defaultTimeLocale "%b %-d, %Y" now+ return . s2t $ res+++readDate2 :: Text -> UTCTime+-- ^ read data in the Jan 7, 2019 format (no . after month)+readDate2 datestring =+ parseTimeOrError+ True+ defaultTimeLocale+ "%b %-d, %Y"+ (t2s datestring) ::+ UTCTime++readDate3 :: Text -> UTCTime+readDate3 dateText = case (readDateMaybe dateText) of+ Nothing -> errorT ["readDate3", dateText, "cannot be parsed"]+ Just t -> t++readDateMaybe :: Text -> Maybe UTCTime+-- ^ read data in various formats (but not 9.10.20 !)+readDateMaybe dateText =+ listToMaybe . catMaybes $+ [ shortMonth,+ longMonth,+ monthPoint,+ germanNumeralShort,+ germanNumeral,+ isoformat+ ]+ where+ shortMonth :: Maybe UTCTime+ shortMonth =+ parseTimeM+ True+ defaultTimeLocale+ "%b %-d, %Y"+ dateString ::+ Maybe UTCTime+ longMonth =+ parseTimeM+ True+ defaultTimeLocale+ "%B %-d, %Y"+ dateString ::+ Maybe UTCTime+ monthPoint =+ parseTimeM+ True+ defaultTimeLocale+ "%b. %-d, %Y"+ dateString ::+ Maybe UTCTime+ germanNumeral =+ parseTimeM+ True+ defaultTimeLocale+ "%-d.%-m.%Y"+ dateString ::+ Maybe UTCTime+ germanNumeralShort =+ parseTimeM+ True+ defaultTimeLocale+ "%-d.%-m.%y"+ dateString ::+ Maybe UTCTime+ isoformat =+ parseTimeM+ True+ defaultTimeLocale+ "%Y-%m-%d"+ dateString ::+ Maybe UTCTime++ dateString = t2s dateText++fromEpochTime' :: EpochTime -> UTCTime+fromEpochTime' et = posixSecondsToUTCTime (realToFrac et)
+ uniform-time.cabal view
@@ -0,0 +1,50 @@+cabal-version: 2.2++-- This file has been generated from package.yaml by hpack version 0.34.2.+--+-- see: https://github.com/sol/hpack+--+-- hash: 7a1b95ca033e9ff3e1c2633b6f099f095b1f01b203a63cf048897798ff95e383++name: uniform-time+version: 0.1.0+synopsis: Time in the uniform framework+description: A very small package for time+ .+ bridges between function on + .+ - UTCTime+ .+ - EpochTime+ .+ with an `IsString` for UTCTime+ .+ Please see the README on GitHub at <https://github.com/andrewufrank/uniform-time/readme>+category: Time Uniform+bug-reports: https://github.com/andrewufrank/uniform-time/issues+author: Andrew Frank+maintainer: Andrew U. Frank <uniform@gerastree.at>+copyright: 2021 Andrew U. Frank+license: GPL-2.0-only+build-type: Simple+extra-source-files:+ README.md+ ChangeLog.md++library+ exposed-modules:+ Uniform.Time+ other-modules:+ Paths_uniform_time+ hs-source-dirs:+ ./.+ build-depends:+ base >=4.7 && <5+ , convertible+ , monads-tf+ , time+ , uniform-algebras+ , uniform-error+ , uniform-strings+ default-language: Haskell2010+ autogen-modules: Paths_uniform_time