hourglass: simple performant time related library

[ bsd3, library, time ] [ Propose Tags ]

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]

Downloads

Note: This package has metadata revisions in the cabal description newer than included in the tarball. To unpack the package including the revisions, use 'cabal get'.

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.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, 0.2.10, 0.2.11, 0.2.12
Dependencies base (>=4.5 && <4.11), deepseq, Win32 [details]
License BSD-3-Clause
Copyright Vincent Hanquez <vincent@snarc.org>
Author Vincent Hanquez <vincent@snarc.org>
Maintainer vincent@snarc.org
Revised Revision 2 made by phadej at 2018-04-03T21:18:49Z
Category Time
Home page http://github.com/vincenthz/hs-hourglass
Source repo head: git clone git://github.com/vincenthz/hs-hourglass
Uploaded by VincentHanquez at 2014-05-04T05:48:19Z
Distributions Arch:0.2.12, Debian:0.2.12, Fedora:0.2.12, FreeBSD:0.2.9, LTSHaskell:0.2.12, NixOS:0.2.12, Stackage:0.2.12, openSUSE:0.2.12
Reverse Dependencies 27 direct, 3549 indirect [details]
Downloads 109161 total (225 in the last 30 days)
Rating 2.0 (votes: 2) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Successful builds reported [all 1 reports]

Readme for hourglass-0.1.0

[back to package description]

hourglass

Hourglass is a simple time library.

Documentation: hourglass on hackage

Design

One of the key design are the Timeable and Time type classes. Time representation of the same time value are interchangeable and easy to convert between each other. This also allow 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 limitation as your system:

  • On 32 bit linux, you can't get a date after the year 2038.
  • In Windows 7, you can't get the date before the year 1601.

Comparaison with time

  • getting posix time:

    ------- with time import Data.Time.Clock.POSIX ptime <- getPOSIXTime

    ------- with hourglass import System.Hourglass ptime <- getCurrentElapsed

  • getting current date year:

    ------- 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 <$> getCurrentElapsed

  • creating a time representation of "4th May 1970 15:12:24"

    ------- 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)