Skip to content

Glistix/birl

Repository files navigation

birl

Package Version Hex Docs Nix-compatible

glistix-birl

Mirrors: GitHub | Codeberg

Glistix fork of birl, a Date/Time handling library for Gleam.

Adds support for the Nix target. For that, implements the algorithms at http://howardhinnant.github.io/date_algorithms.html.

Its documentation can be found at https://hexdocs.pm/glistix_birl.

Warning

Disclaimer: This is an unofficial fork of birl and we are not affiliated with its authors. If you are not using Glistix with the Nix target, consider using the original birl package directly instead.

Notes

Due to purity constraints, the Nix target cannot access the local timezone of the system. However, it can access the current time, but only outside pure-eval mode (otherwise it's assumed to be Jan 1, 1970, or 0 in Unix time). Do note, however, that accessing the current time can only be done once per evaluation (later calls to now() always return the same result).

Otherwise, the functions and algorithms should work just fine (just try not to depend on the current time).

Quick start

nix develop   # Optional: Enter a shell with glistix
glistix run   # Run the project
glistix test  # Run the tests

Installation

Installation

For the most recent instructions, please see the Glistix handbook.

You can use this fork by running glistix add birl followed by adding the line below to your Glistix project's gleam.toml file (as of Glistix v0.7.0):

[glistix.preview.patch]
# ... Existing patches ...
# Add this line:
birl = { name = "glistix_birl", version = ">= 1.0.0 and < 2.0.0" }

This ensures transitive dependencies on birl will also use the patch.

Keep in mind that patches only have an effect on end users' projects - they are ignored when publishing a package to Hex, so end users are responsible for any patches their dependencies may need.

If your project or package is only meant for the Nix target, you can also use this fork in [dependencies] directly through glistix add glistix_birl in order to not rely on patching. However, the patch above is still going to be necessary for end users to fix other dependencies which depend on birl.

Usage

import birl
import birl/duration

pub fn main() {
    let now = birl.now()
    let two_weeks_later = birl.add(now, duration.weeks(2))
    birl.to_iso8601(two_weeks_later)
}