chrono_ext 0.1.1

Unofficial extensions for chrono crate (custom week definitions)
Documentation
  • Coverage
  • 44.83%
    13 out of 29 items documented8 out of 25 items with examples
  • Size
  • Source code size: 15.49 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 2.69 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 23s Average build duration of successful builds.
  • all releases: 23s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • bcourtine/chrono-ext
    2 1 1
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • bcourtine

Unofficial extensions for Rust chrono crate.

Overview

The purpose of this crate is to provide various helpers/extensions for the chrono crate.

Why?

The first requirement that decide me to write this crate was to have "custom" week definitions. For example, in France, movies are released on Wednesday.

Features

Calculate week number with custom week definitions.

French theater calendar have a week definition where the first week has at least 4 days in current year, and starts on Wednesday. For example:

  • the first week for 2019 starts on 2019-01-02.
  • the first week for 2016 starts on 2015-12-30.

The API for custom week definition is inspired by Java API WeekFields. Week is defined by:

  • The first day-of-week (Monday, Tuesday, …).
  • The minimal number of days in the first week.

Example:

use chrono::NaiveDate;
use chrono_ext::{WeekSpecification, CustomWeek};

fn use_french_theater_week() {
    let french_theater_week: WeekSpecification = WeekSpecification::french_theater_week();
    let date = NaiveDate::from_ymd(2017, 1, 3);

    let week = french_theater_week.week(date);
    println!("{}", week.format("%Y - W%W")); // 2016 - W53
}

Installation

Add the following to Cargo.toml under [dependencies]:

chrono_ext = "0.1.1"