Coder Social home page Coder Social logo

hs-hourglass's Introduction

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)

hs-hourglass's People

Contributors

vincenthz avatar nicolasdp avatar fosskers avatar freeman42x avatar gg0 avatar jhinrichsen avatar markwright avatar

Watchers

Tanner Doshier avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.