logo
Expand description

Astrolabe is a date and time library for Rust which aims to be feature rich, lightweight (zero dependencies) and easy-to-use. It implements formatting and manipulating functions for date and time values.

Features

  • Formatting with format strings based on Unicode Date Field Symbols
  • RFC3339 timestamp parsing/formatting
  • Manipulation functions to easily add, remove or set date units
  • Timezone offset
  • Zero dependencies

Example

A basic example which demonstrates creating, formatting and manipulating a DateTime instance.

use astrolabe::{DateTime, Precision, DateTimeUnit};

// Create a DateTime instance from year, month, and days (day of month)
let date_time = DateTime::from_ymd(2022, 5, 2).unwrap();

// Use the format function to freely format your DateTime instance
assert_eq!("2022/05/02", date_time.format("yyyy/MM/dd"));

// Create a new instance with a modified DateTime
// The previous instance is not modified and is still in scope
let modified_dt = date_time
    .apply(11, DateTimeUnit::Hour).unwrap()
    .apply(23, DateTimeUnit::Min).unwrap();

assert_eq!("2022/05/02 11:23:00", modified_dt.format("yyyy/MM/dd HH:mm:ss"));
assert_eq!("2022-05-02T11:23:00Z", modified_dt.format_rfc3339(Precision::Seconds));

To see all implementations for the DateTime struct, check out it’s documentation.

Modules

Various error types returned by methods in the astrolabe crate.

Structs

Date in the proleptic Gregorian calendar.

Combined date and time. Date is in the proleptic Gregorian calendar and clock time is with nanosecond precision.

Clock time with nanosecond precision.

Enums

Date and time units for functions like DateTime::get or DateTime::apply.

Date units for functions like Date::get or Date::apply.

Used to define if an offset is UTC+ or UTC- (eastern or western hemisphere).

Used for specifing the precision for RFC3339 timestamps.

Time units for functions like Time::get or Time::apply.