Expand description
A Rust library for parsing, validating, manipulating, and formatting dates and times
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:
| Feature | Description |
|---|---|
day | Day of the month: (01-31) |
hour | Hour of the day: (00-23) |
iso_8601 | ISO 8601 date and time: (e.g. “2023-01-01T00:00:00+00:00”) |
iso_week | ISO week number: (1-53) |
microsecond | Microsecond: (0-999999) |
minute | Minute of the hour: (0-59) |
month | Month: (e.g. “January”) |
now | Now object: (e.g. “2023-01-01”) |
offset | Offset from UTC: (e.g. “+00:00”) |
ordinal | Ordinal date: (1-366) |
second | Second of the minute: (0-59) |
time | Time object: (e.g. “00:00:00”) |
tz | Time zone object: (e.g. “UTC”) |
weekday | Weekday object: (e.g. “Monday”) |
year | Year object: (e.g. “2023”) |
Each of which represents different aspects of a date and time.
Usage
- DateTime can be any
serde::Serializeorserde::Deserializetypes.
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
macrosmodule contains functions for generating macros. Macros for thedttcrate.
Macros
- Macro for validating a string input against a regex.
Structs
- DateTime struct to ease dates and times manipulation.