daypack-dev / timere

OCaml date time handling and reasoning suite
MIT License
68 stars 7 forks source link
date-time datetime ocaml time-zone timezone

Timere

OCaml date time handling and reasoning suite

This repo houses:

API documentation

Note: 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 (
      since (Timedesc.now ())
      &&& months [12]
      &&& days [25]
      &&& weekdays [`Wed]
    )
  with
  | Error msg -> failwith msg
  | Ok s ->
    Fmt.pr "%a@." (Timedesc.Interval.pp_seq ~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

Timedesc

Timere

Basic usage

Include timedesc (timere and timere-parse if needed) in the libraries stanza in your dune file

Tzdb backend

You can optionally pick one of the following concrete implementations of time zone data source

Tzlocal backend

You can optionally pick one of the following concrete implementations of local time zone detection

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)

Advanced usage

Using Timedesc in utop

To use Timedesc in utop, you need to pick the backends explicitly first

For example, to use the default implementations, one can first type the following lines in utop

#require "timedesc-tzdb.full";;
#require "timedesc-tzlocal.unix";;
#require "timedesc";;

then Timedesc should be accessible in utop

Building a custom Tzdb backend

Timedesc itself can help build a time zone data source backend

TODO

Changelog

See here

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