BSD-3-Clause licensed by Vincent Hanquez
Maintained by [email protected]
This version can be pinned in stack with:hourglass-0.2.12@sha256:e083f5e030dfebe432e30a9c0fa07a99a54eac992f622442646be561fd7a44e8,3085

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:

  • 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 <- timeCurrent
  • Getting the current 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 <$> timeCurrent
  • Representating “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)

Changes

Version 0.2.8 (2015-01-07)

  • Fix test with time 1.5

Version 0.2.7 (2015-01-07)

  • Add compatibility module for easy convertion with time and other standards.
  • Format parsing improvements

Version 0.2.6 (2014-10-19)

  • fix compilation of benchs.
  • add utc time.
  • print the error in the test
  • remove all the read instances in favor of explicit parsing in time parsing.

Version 0.2.5 (2014-10-04)

  • Fixed Windows build
  • Added type signature to fromIntegral

Version 0.2.4 (2014-09-30)

  • Fix ElapsedP Num instance (addition and substraction)
  • add travis machinery

Version 0.2.3 (2014-09-25)

  • Fix build on GNU/Hurd.
  • Add milliseconds, microseconds and nanoseconds format time

Version 0.2.2 (2014-06-11)

  • wrap system time in local time correctly

Version 0.2.1 (2014-06-10)

  • unwrap local time structure when doing a localTimePrint
  • properly show hours, minutes and seconds in format print.
  • add some description of new calls.

Version 0.2.0 (2014-06-03)

  • use tasty to replace test-framework
  • add some inlining pragma to tentatively deal with rules properly.
  • Remove the Time method to get timezone offset, all local time must be handled through LocalTime
  • Remove the Time instance for Localtime.
  • add localTimeParse since timeParse is not suitable anymore for LocalTime (no more time instance).
  • add Hours and Minutes types.
  • add a time interval class to convert between time unit types.
  • add some new derived classes (Enum,Real,Integral) for time unit types.
  • split TimeDiff into a Period and Duration structure.

Version 0.1.2 (2014-05-05)

  • fix compilation on OSX
  • add some system benchmarks
  • comment and markup reformating

Version 0.1.1 (2014-05-04)

  • add all the cabal tests file to the source dist
  • https-ize some urls

Version 0.1.0 (2014-05-04)

  • Initial version