package timere

  1. Overview
  2. Docs
OCaml time handling and reasoning library

Install

Dune Dependency

Authors

Maintainers

Sources

v0.1.3.tar.gz
sha256=fefd171ec57891bf641734b119db69750fbf854b77ed13c03af036e398d5c8eb

Description

Features:

  • Timestamp and date time handling with platform independent time zone support

    • Subset of the IANA time zone database is built into this library
  • Reasoning over time intervals via timere objects/expressions, examples:

    • Pattern matching time and intervals. These work across DST boundaries.

    • Intersection and union

    • Chunking at year or month boundary, or in fixed sizes

    • Evaluate (sub)expressions with a different time zone (e.g. intersection of 9am to 5pm of Sydney and 9am to 5pm of New York)

Published: 27 Jan 2021

README

Timere

OCaml time handling and reasoning library

API documentation

Note: The project core is largely complete, but still undergoing testing - you're welcome to use it in prototypes, but avoid using it in production for now. The NLP component is WIP.

Disclaimer: timere is not designed to handle prehistoric events. For prehistoric planning and booking software, please consult appropriate experts.

Examples

Christmases which fall on Wednesday from now

let () =
  let open Timere in
  match
    resolve (
      after (Date_time.now ())
      & months [`Dec]
      & days [25]
      & weekdays [`Wed]
    )
  with
  | Error msg -> failwith msg
  | Ok s ->
    Fmt.pr "%a@." (pp_intervals ~sep:(Fmt.any "@.") ()) s

gives

[2024 Dec 25 00:00:00 +00:00:00, 2024 Dec 26 00:00:00 +00:00:00)
[2030 Dec 25 00:00:00 +00:00:00, 2030 Dec 26 00:00:00 +00:00:00)
[2041 Dec 25 00:00:00 +00:00:00, 2041 Dec 26 00:00:00 +00:00:00)
[2047 Dec 25 00:00:00 +00:00:00, 2047 Dec 26 00:00:00 +00:00:00)
[2052 Dec 25 00:00:00 +00:00:00, 2052 Dec 26 00:00:00 +00:00:00)
[2058 Dec 25 00:00:00 +00:00:00, 2058 Dec 26 00:00:00 +00:00:00)
...

See examples/ for more examples

Features

  • Timestamp and date time handling with platform independent time zone support

    • Subset of the IANA time zone database is built into this library

  • Reasoning over time intervals via timere objects/expressions, examples:

    • Pattern matching time and intervals. These work across DST boundaries.

    • Intersection and union

    • Chunking at year or month boundary, or in fixed sizes

    • Evaluate (sub)expressions with a different time zone (e.g. intersection of 9am to 5pm of Sydney and 9am to 5pm of New York)

Usage

Include timere in the libraries stanza in your dune file, and optionally one of the following two to select a concrete implementation of time zone data source

  • timere.tzdb.full

    • This is the default implementation which embeds the IANA time zone database from year 1850 to year 2100 exclusive

  • timere.tzdb.none

    • This embeds no database. This is suitable for when you want to retrieve time zone data during run time, for instance, to reduce the built artifact size.

    • The following resources should allow you to implement said approach readily

      • A usable and test suite covered data source is provided under tzdb-json/.

      • List of available time zones is available as gen-artifacts/available-time-zones.txt

      • Time_zone.of_json_string can load files in tzdb-json/

Note: While tzdb-json/ may be useful and usable outside of Timere, we make no guarantees that the JSON format stays unmodified (though changes of the format should be a rare occurrence, if ever occurring)

License

Code files are licensed under the MIT license as specified in the LICENSE file

Time zone database derived files are licensed under its original terms (public domain)

Acknowledgement

  • Time zone information is extracted via zdump command output into src/time_zone_data.ml, using the IANA database (as time zone files) distributed on Linux

  • Time zone data handling code copies approach used by chrono-tz

    • This includes data representation and choices of some algorithms

Dependencies (9)

  1. fmt >= "0.8.7"
  2. yojson >= "1.6.0"
  3. ptime
  4. containers >= "3.0"
  5. mparser >= "1.3"
  6. seq
  7. oseq < "0.5"
  8. dune >= "2.7.0"
  9. ocaml >= "4.06.1" & < "5.0"

Dev Dependencies (6)

  1. qcheck with-test
  2. qcheck-alcotest with-test
  3. alcotest with-test
  4. fileutils with-test
  5. crowbar with-test
  6. bisect_ppx dev & >= "2.5.0"

Used by (1)

  1. dirsift < "0.0.4"

Conflicts

None

OCaml

Innovation. Community. Security.