hourglass-0.2.9: simple performant time related library

License | BSD-style
Maintainer | Vincent Hanquez <vincent@snarc.org>
Safe Haskell | None
Language | Haskell2010

Data.Hourglass.Types

Contents

- Time units
- Time enumeration
- Timezone
- Computer friendly format
  - Unix elapsed
- Human friendly format
  - Calendar time

Description

Basic times units and types.

While pratically some units could hold infinite values, for practical and efficient purpose they are limited to int64 types for seconds and int types for years.

Most units use the unix epoch referential, but by no means reduce portability. the unix referential works under the Windows platform or any other platforms.

Synopsis

- newtype NanoSeconds = NanoSeconds Int64
- newtype Seconds = Seconds Int64
- newtype Minutes = Minutes Int64
- newtype Hours = Hours Int64
- class TimeInterval i where
  - toSeconds :: i -> Seconds
  - fromSeconds :: Seconds -> (i, Seconds)
- data Month
  - = January
  - | February
  - | March
  - | April
  - | May
  - | June
  - | July
  - | August
  - | September
  - | October
  - | November
  - | December
- data WeekDay
  - = Sunday
  - | Monday
  - | Tuesday
  - | Wednesday
  - | Thursday
  - | Friday
  - | Saturday
- newtype TimezoneOffset = TimezoneOffset {
  - timezoneOffsetToMinutes :: Int
  }
- timezoneOffsetToSeconds :: TimezoneOffset -> Seconds
- timezone_UTC :: TimezoneOffset
- newtype Elapsed = Elapsed Seconds
- data ElapsedP = ElapsedP !Elapsed !NanoSeconds
- data Date = Date {
  - dateYear :: !Int
  - dateMonth :: !Month
  - dateDay :: !Int
  }
- data TimeOfDay = TimeOfDay {
  - todHour :: !Hours
  - todMin :: !Minutes
  - todSec :: !Seconds
  - todNSec :: !NanoSeconds
  }
- data DateTime = DateTime {
  - dtDate :: Date
  - dtTime :: TimeOfDay
  }

# Time units

newtype NanoSeconds Source

Nanoseconds

Constructors

NanoSeconds Int64 |

Instances

Eq NanoSeconds Source |
Data NanoSeconds Source |
Num NanoSeconds Source |
Ord NanoSeconds Source |
Read NanoSeconds Source |
Show NanoSeconds Source |
NFData NanoSeconds Source |
TimeInterval NanoSeconds Source |

newtype Seconds Source

Number of seconds without a referential.

Can hold a number between [-2^63,2^63-1], which should be good for some billions of years.

However, because of limitation in the calendar conversion currently used, seconds should be in the range [-2^55,2^55-1], which is good for only 1 billion of year.

Constructors

Seconds Int64 |

Instances

Enum Seconds Source |
Eq Seconds Source |
Integral Seconds Source |
Data Seconds Source |
Num Seconds Source |
Ord Seconds Source |
Read Seconds Source |
Real Seconds Source |
Show Seconds Source |
NFData Seconds Source |
TimeInterval Seconds Source |

newtype Minutes Source

Number of minutes without a referential.

Constructors

Minutes Int64 |

Instances

Enum Minutes Source |
Eq Minutes Source |
Integral Minutes Source |
Data Minutes Source |
Num Minutes Source |
Ord Minutes Source |
Read Minutes Source |
Real Minutes Source |
Show Minutes Source |
NFData Minutes Source |
TimeInterval Minutes Source |

newtype Hours Source

Number of hours without a referential.

Constructors

Hours Int64 |

Instances

Enum Hours Source |
Eq Hours Source |
Integral Hours Source |
Data Hours Source |
Num Hours Source |
Ord Hours Source |
Read Hours Source |
Real Hours Source |
Show Hours Source |
NFData Hours Source |
TimeInterval Hours Source |

class TimeInterval i where Source

Represent any time interval that has an equivalent value to a number of seconds.

Methods

toSeconds :: i -> Seconds Source

fromSeconds :: Seconds -> (i, Seconds) Source

Instances

TimeInterval Hours Source |
TimeInterval Minutes Source |
TimeInterval Seconds Source |
TimeInterval NanoSeconds Source |
TimeInterval Duration Source |

# Time enumeration

data Month Source

Month of the year

Constructors

January |
February |
March |
April |
May |
June |
July |
August |
September |
October |
November |
December |

Instances

Enum Month Source |
Eq Month Source |
Data Month Source |
Ord Month Source |
Show Month Source |

data WeekDay Source

Day of the week

the enumeration starts on Sunday.

Constructors

Sunday |
Monday |
Tuesday |
Wednesday |
Thursday |
Friday |
Saturday |

Instances

Enum WeekDay Source |
Eq WeekDay Source |
Data WeekDay Source |
Ord WeekDay Source |
Read WeekDay Source |
Show WeekDay Source |

# Timezone

newtype TimezoneOffset Source

Offset against UTC in minutes

- a positive number represent a location East of UTC.
- a negative number represent a location West of UTC.

LocalTime t (-300) = t represent a time at UTC-5 LocalTime t (+480) = t represent a time at UTC+8

should be between -11H and +14H

Constructors

TimezoneOffset |

Fields

timezoneOffsetToMinutes :: Int

  return the number of minutes

Instances

Eq TimezoneOffset Source |
Data TimezoneOffset Source |
Ord TimezoneOffset Source |
Show TimezoneOffset Source |
NFData TimezoneOffset Source |

timezoneOffsetToSeconds :: TimezoneOffset -> Seconds Source

Return the number of seconds associated with a timezone

timezone_UTC :: TimezoneOffset Source

The UTC timezone. offset of 0

# Computer friendly format

## Unix elapsed

newtype Elapsed Source

A number of seconds elapsed since the unix epoch.

Constructors

Elapsed Seconds |

Instances

Eq Elapsed Source |
Data Elapsed Source |
Num Elapsed Source |
Ord Elapsed Source |
Read Elapsed Source |
Show Elapsed Source |
NFData Elapsed Source |
Time Elapsed Source |
Timeable Elapsed Source |

data ElapsedP Source

A number of seconds and nanoseconds elapsed since the unix epoch.

Constructors

ElapsedP !Elapsed !NanoSeconds |

Instances

Eq ElapsedP Source |
Data ElapsedP Source |
Num ElapsedP Source |
Ord ElapsedP Source |
Read ElapsedP Source |
Real ElapsedP Source |
Show ElapsedP Source |
NFData ElapsedP Source |
Time ElapsedP Source |
Timeable ElapsedP Source |

# Human friendly format

## Calendar time

data Date Source

human date representation using common calendar

Constructors

Date |

Fields

dateYear :: !Int

  year (Common Era)

dateMonth :: !Month

  month of the year

dateDay :: !Int

  day of the month, between 1 to 31

Instances

Eq Date Source |
Data Date Source |
Ord Date Source |
Show Date Source |
NFData Date Source |
Time Date Source |
Timeable Date Source |

data TimeOfDay Source

human time representation of hour, minutes, seconds in a day.

Constructors

TimeOfDay |

Fields

todHour :: !Hours

  hours, between 0 and 23

todMin :: !Minutes

  minutes, between 0 and 59

todSec :: !Seconds

  seconds, between 0 and 59. 60 when having leap second */

todNSec :: !NanoSeconds

  nanoseconds, between 0 and 999999999 */

Instances

Eq TimeOfDay Source |
Data TimeOfDay Source |
Ord TimeOfDay Source |
Show TimeOfDay Source |
NFData TimeOfDay Source |

data DateTime Source

Date and Time

Constructors

DateTime |

Fields

dtDate :: Date
dtTime :: TimeOfDay

Instances

Eq DateTime Source |
Data DateTime Source |
Ord DateTime Source |
Show DateTime Source |
NFData DateTime Source |
Time DateTime Source |
Timeable DateTime Source |