The hourglass package

[Tags: bsd3, library]

Simple time library focusing on simple but powerful and performant API

The backbone of the library are the Timeable and Time type classes.

Each Timeable instances can be converted to type that has a Time instances, and thus are different representations of current time.


[Skip to ReadMe]

Properties

Versions0.1.0, 0.1.1, 0.1.2, 0.2.0, 0.2.1, 0.2.2, 0.2.3, 0.2.4, 0.2.5, 0.2.6, 0.2.7, 0.2.8, 0.2.9
Change logCHANGELOG.md
Dependenciesbase (==4.*), deepseq, Win32 [details]
LicenseBSD3
CopyrightVincent Hanquez <vincent@snarc.org>
AuthorVincent Hanquez <vincent@snarc.org>
Maintainervincent@snarc.org
Stabilityexperimental
CategoryTime
Home pagehttps://github.com/vincenthz/hs-hourglass
Source repositoryhead: git clone https://github.com/vincenthz/hs-hourglass
UploadedWed Apr 1 14:53:52 UTC 2015 by VincentHanquez
DistributionsDebian:0.2.9, LTSHaskell:0.2.9, NixOS:0.2.9, Stackage:0.2.9
Downloads16697 total (637 in last 30 days)
Votes
0 []
StatusDocs available [build log]
Last success reported on 2015-04-01 [all 1 reports]

Modules

[Index]

Downloads

Maintainers' corner

For package maintainers and hackage trustees

Readme for hourglass-0.2.9

hourglass

Build Status BSD Haskell

Hourglass is a simple time library.

Documentation: hourglass on hackage

Design

Key parts of the design are the Timeable and Time typeclasses. Time representations of the same time values are interchangeable and easy to convert between each other. This also allows the user to define new time types that interact with the same functions as the built-in types.

For example:

let dateTime0 =
      DateTime { dtDate = Date { dateYear = 1970, dateMonth = January, dateDay = 1 }
               , dtTime = TimeOfDay {todHour = 0, todMin = 0, todSec = 0, todNSec = 0 }}
    elapsed0 = Elasped 0

> timeGetElapsed elapsed0 == timeGetElapsed dateTime0
True
> timeGetDate elapsed0 == timeGetDate dateTime0
True
> timePrint "YYYY-MM" elapsed0
"1970-01"
> timePrint "YYYY-MM" dateTime0
"1970-01"

Hourglass has the same limitations as your system:

Comparaison with time

-- With time
import Data.Time.Clock.POSIX

ptime <- getPOSIXTime

-- With hourglass
import System.Hourglass

ptime <- timeCurrent
-- With time
import Data.Time.Clock
import Data.Time.Calendar

currentYear <- (\(y,_,_) -> y) . toGregorian . utcDay <$> getCurrentTime

-- With hourglass
import System.Hourglass
import Data.Time

currentYear <- dateYear . timeGetDate <$> timeCurrent
-- With time
import Data.Time.Clock
import Date.Time.Calendar

let day = fromGregorian 1970 5 4
    diffTime = secondsToDiffTime (15 * 3600 + 12 * 60 + 24)
in UTCTime day diffTime

-- With hourglass
import Date.Time

DateTime (Date 1970 May 4) (TimeOfDay 15 12 24 0)