Time 🕰️

Work with time in Gleam!

Package Version Hex Docs

gleam add gleam_time

This package is the foundation of all code that works with time in Gleam. If your program uses time then you should be using the types in this package, and you might choose to add other packages to provide additional functionality.

How not to have time related bugs

Time is famously difficult to work with! It’s a very complex area, and there’s many approaches that seem reasonable or obvious, but then commonly result in bugs. This package is carefully designed to help you avoid these problems, so it is wise to read this documentation before continuing.

It is important to understand there are two main ways that time is represented:

In this package epoch time is provided by the gleam/time/timestamp module, and calendar time is provided by the gleam/time/timestamp module.

Time zone information has to be loaded from elsewhere, but which approch is best will depend on your application. User interfaces may want to read current time zone information from the user’s web browser or operating system. Server side applications may want to embed or downloads a full copy of the time zone database and then ask clients which time zone they want to use.

Which time representation should you use?

tldr: Use gleam/time/timestamp.

The longer, more detailed answer:

Any time you do use calendar time you should be extra careful! It is very easy to make mistake with. Avoid it where possible.

Special thanks

This package was created with great help from several kind contributors. In alphabetical order:

These non-Gleam projects where highly influential on the design of this package:

Search Document