time-hourglass: A simple and efficient time library

[ bsd3, library, time ] [ Propose Tags ] [ Report a vulnerability ]
This version is deprecated.

A simple and efficient time library.

A key part of the library is the Timeable and Time type classes.

Types representing time values that are instances of the classes allow easy conversion between values of one time type and another.


[Skip to Readme]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.2.12, 0.2.13, 0.2.14, 0.3.0 (info)
Change log CHANGELOG.md
Dependencies base (>=4.11 && <5), deepseq, Win32 [details]
License BSD-3-Clause
Copyright Vincent Hanquez <vincent@snarc.org>
Author Vincent Hanquez <vincent@snarc.org>
Maintainer Mike Pilgrem <public@pilgrem.com>
Category Time
Home page https://github.com/mpilgrem/time-hourglass
Bug tracker https://github.com/mpilgrem/time-hourglass/issues
Source repo head: git clone https://github.com/mpilgrem/time-hourglass
Uploaded by mpilgrem at 2025-07-23T22:59:06Z
Distributions Stackage:0.3.0
Reverse Dependencies 3 direct, 1 indirect [details]
Downloads 14 total (14 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2025-07-23 [all 1 reports]

Readme for time-hourglass-0.2.13

[back to package description]

time-hourglass

Build Status License Haskell

Originally forked from hourglass-0.2.12.

time-hourglass (originally hourglass) is a simple and efficient time library.

Documentation

See the Haddock documentation on Hackage.

Design

A key part of the design is the Timeable and Time type classes. Types representing time values that are instances of these classes allow easy conversion between values of one time type and another.

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"

The library has the same limitations as your operating system, namely:

  • on 32-bit Linux, you can't get a date after the year 2038; and
  • on Windows, you can't get a date before the year 1601.

Comparaison with the time package

  • Getting the elapsed time since 1970-01-01 00:00:00 UTC (POSIX time) from the system clock:

    -- With time:
    import Data.Time.Clock.POSIX ( getPOSIXTime )
    
    ptime <- getPOSIXTime
    
    -- With time-hourglass:
    import System.Hourglass ( timeCurrent )
    
    ptime <- timeCurrent
    
  • Getting the current year:

    -- With time:
    import Data.Time.Clock ( UTCTime (..) )
    import Data.Time.Clock.POSIX ( getCurrentTime )
    import Data.Time.Calendar ( toGregorian )
    
    currentYear <- (\(y, _, _) -> y) . toGregorian . utcDay <$> getCurrentTime
    
    -- With time-hourglass:
    import System.Hourglass ( timeCurrent )
    import Data.Hourglass ( Date (..), timeGetDate )
    
    currentYear <- dateYear . timeGetDate <$> timeCurrent
    
  • Representating "4th May 1970 15:12:24"

    -- With time:
    import Data.Time.Clock ( UTCTime (..), secondsToDiffTime )
    import Date.Time.Calendar ( fromGregorian )
    
    let day = fromGregorian 1970 5 4
        diffTime = secondsToDiffTime (15 * 3600 + 12 * 60 + 24)
    in  UTCTime day diffTime
    
    -- With time-hourglass:
    import Date.Time ( Date (..), DateTime (..), TimeOfDay (..) )
    
    DateTime (Date 1970 May 4) (TimeOfDay 15 12 24 0)
    

History

The hourglass package was originated and then maintained by Vincent Hanquez. For published reasons, he does not intend to develop the package further after version 0.2.12 but he also does not want to introduce other maintainers.