DateTime (DTT): Uncover Essential Installation Prerequisites

Discover DateTime (DTT), a Rust library for efficient date-time parsing, validation, and formatting, tailored for accuracy and performance in software.

DateTime (DTT):  Setup and Usage Guide

Overview

DateTime (DTT) is a versatile Rust library designed for parsing, validating, manipulating, and formatting dates and times. Tailored to modern software development needs, DTT enhances date and time data handling with a focus on performance and accuracy.

It offers a range of functions and data structures that allow you to perform various date and time operations with ease, such as determining the day of the month, hour of the day, working with ISO 8601 date and time formats, and many others.

The library supports the creation of new DateTime objects with either UTC or custom timezone specifications, ensuring that you always have accurate and relevant date and time information. Additionally, it provides a mechanism to validate input dates and times, ensuring that you always have accurate information to work with.

Features

Core Features

Advanced Features

Functionality

The library DateTime (DTT) 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 (DTT) 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 (DTT) 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") |

Divider

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

The DateTime (DTT) struct has two methods to create instances: new and new_with_tz. new creates a new DateTime (DTT) object with UTC timezone, and new_with_tz creates a new DateTime (DTT) object with a custom timezone.

It also includes a method is_valid_day which checks if the input string represents a valid day of the week. It also includes a method is_valid_month which checks if the input string represents a valid month of the year.

Divider

Getting Started

Begin using DateTime (DTT) in just a few steps.

Requirements

Ensure you have the Rust toolchain, version 1.69.0 or later (stable).

Installation

After installing the Rust toolchain (instructions on the Rust website ⧉), install DateTime (DTT) with: instructions on the Rust website ⧉.

Once you have the Rust toolchain installed, you can install dtt using the following command:

cargo install dtt

You can then run the help command to see the available options:

dtt --help

Divider

Usage

To use the dtt library in your project, add the following to your Cargo.toml file:

[dependencies]
dtt = "0.0.4"

Add the following to your main.rs file:

extern crate dtt;
use dtt::*;

then you can use the functions in your application code.

Divider

Errors

DateTime (DTT) defines specific error types, such as ParseError and FormatError, ensuring robust error handling in your applications.

Divider

Examples

To get started with DateTime (DTT), you can use the examples provided in the examples directory of the project.

To run the examples, clone the repository and run the following command in your terminal from the project root directory.

cargo run --example dtt

Example 1: Creating a new DateTime object

use dtt::DateTime;
use dtt::dtt_print;

fn main() {
    // Create a new DateTime object with the current UTC time
    let now = DateTime::new();
    dtt_print!(now);
}

Example 2: Creating a new DateTime object with a custom timezone

use dtt::DateTime;
use dtt::dtt_print;

fn main() {
    // Create a new DateTime object with a custom timezone (e.g., CEST)
    let paris_time = DateTime::new_with_tz("CEST");
    dtt_print!(paris_time);
}

Custom timezone supported by DateTime (DTT) are:

| Abbreviation | UtcOffset | Time Zone Description | |--------------|-------------------------------------|------------------------------------------| | ACDT | UtcOffset::from_hms(10, 30, 0) | Australian Central Daylight Time | | ACST | UtcOffset::from_hms(9, 30, 0) | Australian Central Standard Time | | ADT | UtcOffset::from_hms(-3, 0, 0) | Atlantic Daylight Time | | AEDT | UtcOffset::from_hms(11, 0, 0) | Australian Eastern Daylight Time | | AEST | UtcOffset::from_hms(10, 0, 0) | Australian Eastern Standard Time | | AKDT | UtcOffset::from_hms(-8, 0, 0) | Alaska Daylight Time | | AKST | UtcOffset::from_hms(-9, 0, 0) | Alaska Standard Time | | AST | UtcOffset::from_hms(-4, 0, 0) | Atlantic Standard Time | | AWST | UtcOffset::from_hms(8, 0, 0) | Australian Western Standard Time | | BST | UtcOffset::from_hms(1, 0, 0) | British Summer Time | | CDT | UtcOffset::from_hms(-5, 0, 0) | Central Daylight Time | | CEST | UtcOffset::from_hms(2, 0, 0) | Central European Summer Time | | CET | UtcOffset::from_hms(1, 0, 0) | Central European Time | | CST | UtcOffset::from_hms(-6, 0, 0) | Central Standard Time | | ECT | UtcOffset::from_hms(-4, 0, 0) | Eastern Caribbean Time | | EDT | UtcOffset::from_hms(-4, 0, 0) | Eastern Daylight Time | | EEST | UtcOffset::from_hms(3, 0, 0) | Eastern European Summer Time | | EET | UtcOffset::from_hms(2, 0, 0) | Eastern European Time | | EST | UtcOffset::from_hms(-5, 0, 0) | Eastern Standard Time | | GMT | UtcOffset::from_hms(0, 0, 0) | Greenwich Mean Time | | HADT | UtcOffset::from_hms(-9, 0, 0) | Hawaii-Aleutian Daylight Time | | HAST | UtcOffset::from_hms(-10, 0, 0) | Hawaii-Aleutian Standard Time | | HKT | UtcOffset::from_hms(8, 0, 0) | Hong Kong Time | | IST | UtcOffset::from_hms(5, 30, 0) | Indian Standard Time | | IDT | UtcOffset::from_hms(3, 0, 0) | Israel Daylight Time | | JST | UtcOffset::from_hms(9, 0, 0) | Japan Standard Time | | KST | UtcOffset::from_hms(9, 0, 0) | Korean Standard Time | | MDT | UtcOffset::from_hms(-6, 0, 0) | Mountain Daylight Time | | MST | UtcOffset::from_hms(-7, 0, 0) | Mountain Standard Time | | NZDT | UtcOffset::from_hms(13, 0, 0) | New Zealand Daylight Time | | NZST | UtcOffset::from_hms(12, 0, 0) | New Zealand Standard Time | | PDT | UtcOffset::from_hms(-7, 0, 0) | Pacific Daylight Time | | PST | UtcOffset::from_hms(-8, 0, 0) | Pacific Standard Time | | UTC | UtcOffset::from_hms(0, 0, 0) | Coordinated Universal Time | | WADT | UtcOffset::from_hms(8, 45, 0) | West Australian Daylight Time | | WAST | UtcOffset::from_hms(7, 0, 0) | West Australian Standard Time | | WEDT | UtcOffset::from_hms(1, 0, 0) | Western European Daylight Time | | WEST | UtcOffset::from_hms(1, 0, 0) | Western European Summer Time | | WET | UtcOffset::from_hms(0, 0, 0) | Western European Time | | WST | UtcOffset::from_hms(8, 0, 0) | Western Standard Time |

Divider

Example 3: Formatting a DateTime object

use dtt::DateTime;
use dtt::dtt_print;

fn main() {
    // Create a new DateTime object with the current UTC time
    let now = DateTime::new();

    // Format the DateTime object as a string
    let formatted_time = now.format("%Y-%m-%d %H:%M:%S");
    dtt_print!("Formatted time: {}", formatted_time);
}

Example 4: Parsing a string into a DateTime object

use dtt::DateTime;
use dtt::dtt_print;

fn main() {
    // Parse a string into a DateTime object
    let date_string = "2023-05-12T12:00:00+00:00";
    match DateTime::parse(date_string) {
        Ok(datetime) => dtt_print!("Parsed DateTime: {}", datetime),
        Err(err) => dtt_print!("Error parsing DateTime: {}", err),
    }
}

Divider

Documentation

For comprehensive information and resources related to DateTime (DTT), we invite you to explore our extensive documentation.

Detailed guides, API references, and examples are available on docs.rs ⧉, where you'll find in-depth material to support your development needs.

For library-specific details and to access our collection of Rust libraries, visit lib.rs ⧉.

Additionally, you can explore crates.io ⧉ to find a wide range of Rust crates, which include the necessary tools and libraries to enhance your projects.

These resources are designed to provide you with the most up-to-date and thorough information to assist in your development endeavours.

Divider