Crate dtt

source ·
Expand description

A Rust library for parsing, validating, manipulating, and formatting dates and times

Rust

Rust Crates.io Lib.rs GitHub License

Overview

The DateTime (DTT) library is a comprehensive and flexible tool that enables developers to manage dates and times with ease.

It provides drop-in replacement methods for parsing, validating, manipulating, and formatting dates and times in Rust.

The DateTime type to represent a date and a time in a defined timezone.

Features

The library DateTime provides date and time types and methods to make it easier to manipulate dates and times. It uses the serde library to derive the Deserialize and Serialize traits to convert the DateTime struct to and from various data formats. It also uses the time and regex crates to deal with time conversions and regular expressions respectively.

The DateTime struct includes fields such as:

FeatureDescription
dayDay of the month: (01-31)
hourHour of the day: (00-23)
iso_8601ISO 8601 date and time: (e.g. “2023-01-01T00:00:00+00:00”)
iso_weekISO week number: (1-53)
microsecondMicrosecond: (0-999999)
minuteMinute of the hour: (0-59)
monthMonth: (e.g. “January”)
nowNow object: (e.g. “2023-01-01”)
offsetOffset from UTC: (e.g. “+00:00”)
ordinalOrdinal date: (1-366)
secondSecond of the minute: (0-59)
timeTime object: (e.g. “00:00:00”)
tzTime zone object: (e.g. “UTC”)
weekdayWeekday object: (e.g. “Monday”)
yearYear object: (e.g. “2023”)

Each of which represents different aspects of a date and time.

Usage

  • DateTime can be any serde::Serialize or serde::Deserialize types.

Examples


// Import the DateTime library
extern crate dtt;
use self::dtt::DateTime;

// Create a new DateTime object.

// - The default timezone is UTC.
// - The default date is the current date.
// - The default time is the current time.
// - The default format is ISO 8601.
let dt = DateTime::new();

// Display the current date.
println!("Date: {}", dt.now); // 2023-01-01

// Display the current day.
println!("Day: {}", dt.day); // 01

// Display the current hour.
println!("Hour: {}", dt.hour); // 00

// Display the current ISO 8601 date and time.
println!("ISO 8601: {}", dt.iso_8601); // 2023-01-01T00:00:00+00:00

// Display the current ISO week number.
println!("ISO Week Number: {}", dt.iso_week); // 1

// Display the current microsecond.
println!("Microsecond: {}", dt.microsecond); // 000000

// Display the current minute.
println!("Minute: {}", dt.minute); // 00

// Display the current month.
println!("Month: {}", dt.month); // January

// Display the current offset.
println!("Offset: {}", dt.offset); // +00:00

// Display the current ordinal date.
println!("Ordinal Date: {}", dt.ordinal); // 1

// Display the current second.
println!("Second: {}", dt.second); // 00

// Display the current time.
println!("Time: {}", dt.time); // 00:00:00

// Display the current timezone.
println!("Timezone: {}", dt.tz); // UTC

// Display the current weekday.
println!("Weekday: {}", dt.weekday); // Monday

// Display the current year.
println!("Year: {}", dt.year);

License

The project is licensed under the terms of both the MIT license and the Apache License (Version 2.0).

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Modules

  • The macros module contains functions for generating macros. Macros for the dtt crate.

Macros

  • Macro for validating a string input against a regex.

Structs

  • DateTime struct to ease dates and times manipulation.