Giter VIP home page Giter VIP logo

timezone's Introduction

Timezone for OCaml

Timezone handles parsing timezone data and create [Timezone.t] that can later be used to manipulate time in core_kernel and core (using [Time] and [Time_ns] modules).

Timezone is currently only able to read the Timezone Database provided by IANA. It should work out of the box on Linux and macOS.

Where are the timezone data located ?

The location of the timezone files can be set using the environment variable TZDIR. If not set, [Timezone] will fallback to /usr/share/zoneinfo/.

What is the local timezone ?

The local timezone can be set using the environment variable TZ. If not set, [Timezone] will fallback to /etc/localtime. In a JavaScript context, we automatically set the environment variable TZ to Intl.DateTimeFormat().resolvedOptions().timeZone.

Compatibility with JavaScript.

The [Timezone] library can be used when constructing JavaScript applications with Js_of_ocaml.

Node.js

[Timezone] should work out of the box when running on a Node.js environment on Linux or macOS. The file-system is accessible in that case.

Web browsers

In a web browser environment, the [Timezone] library requires some additional setup. One should generate a JavaScript file that will embed all timezone data required by the application. This can be done by using a tool provided by js_of_ocaml called jsoo_fs. The generated JavaScript file will have to be included in the HTML page before the JavaScript program itself.

For example, one can embed all timezones in all-tz.js with the following command:

grep -r TZif /usr/share/zoneinfo -l | xargs -n 1 -I {} echo {}:{} | xargs jsoo_fs -o all-tz.js

Example

open Core_kernel

let now = Time_ns.now ()

let () =
  Time_ns.to_sec_string now ~zone:(Lazy.force (Timezone.local))
  |> print_endline

let () =
  Time_ns.to_sec_string now ~zone:(Timezone.find_exn "America/New_York")
  |> print_endline

Please report bugs and feature requests on GitHub.

You can find all of Jane Street's open-source libraries on GitHub.

Documentation can be found here.

timezone's People

Contributors

xclerc avatar

Watchers

James Cloos 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.