MyNixOS website logo
Description

A simple and efficient time library.

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.

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.

Metadata

Version

0.3.0

Platforms (76)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-freebsd
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64-windows
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-linux
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows