Crates.io | chrono_ext |
lib.rs | chrono_ext |
version | 0.1.1 |
source | src |
created_at | 2020-03-30 14:36:10.797124 |
updated_at | 2020-03-31 14:48:38.623829 |
description | Unofficial extensions for chrono crate (custom week definitions) |
homepage | https://github.com/bcourtine/chrono-ext |
repository | https://github.com/bcourtine/chrono-ext |
max_upload_size | |
id | 224378 |
size | 15,491 |
The purpose of this crate is to provide various helpers/extensions for the chrono crate.
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.
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 API for custom week definition is inspired by Java API WeekFields. Week is defined by:
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
}
Add the following to Cargo.toml
under [dependencies]
:
chrono_ext = "0.1.1"