Crate dtt

source ·
Expand description

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

DTT Banner

Crates.io GitHub Lib.rs License Rust

§Overview 📖

The DateTime (DTT) library is a comprehensive and flexible tool that enables developers to manage dates and times with ease. 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 ✨

The DateTime (DTT) struct includes the following fields and methods:

§Fields

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

§Methods

  • new(): Creates a new DateTime object with the current UTC time.
  • new_with_tz(tz: &str): Creates a new DateTime object with the specified timezone.
  • is_valid_day(input: &str): Checks if the input represents a valid day of the month.
  • is_valid_hour(input: &str): Checks if the input represents a valid hour of the day.
  • is_valid_second(input: &str): Checks if the input represents a valid second of the minute.
  • is_valid_minute(input: &str): Checks if the input represents a valid minute of the hour.
  • is_valid_month(input: &str): Checks if the input represents a valid month of the year.
  • is_valid_ordinal(input: &str): Checks if the input represents a valid ordinal date.
  • is_valid_time(input: &str): Checks if the input represents a valid time.
  • is_valid_iso_week(input: &str): Checks if the input represents a valid ISO week number.
  • is_valid_iso_8601(input: &str): Checks if the input represents a valid ISO 8601 date and time.
  • is_valid_microsecond(input: &str): Checks if the input represents a valid microsecond.
  • update(&mut self): Updates the DateTime object with the current date and time based on the timezone.
  • add_days(&self, days: i32): Creates a new DateTime object with the specified number of days added.
  • next_day(&self): Creates a new DateTime object representing the next day.
  • previous_day(&self): Creates a new DateTime object representing the previous day.
  • relative_delta(&self): Creates a new DateTime object with the relative delta based on the current date and time.
  • format(&self, format_str: &str): Formats the DateTime object as a string using the specified format.

The library also provides various getter methods to extract the individual components of the DateTime object, such as year(), month(), day(), hour(), minute(), second(), microsecond(), weekday(), ordinal(), iso_8601(), iso_week(), time(), tz(), and offset().

Additionally, the DateTime (DTT) struct implements the FromStr trait, allowing for parsing a string into a DateTime object.

§License 📝

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

Modules§

  • The macros module contains functions for generating macros.

Macros§

  • Adds the specified number of days to the given DateTime instance.
  • Asserts that the given expression is true.
  • Creates a deep copy of the provided DateTime object.
  • Calculates the difference in whole days between two DateTime or timestamp instances as Unix timestamps.
  • Calculates the difference in hours between two DateTime instances.
  • Calculates the difference in minutes between two DateTime instances.
  • Calculates the difference in seconds between two DateTime or timestamp instances as Unix timestamps.
  • Formats a DateTime object using the provided format string.
  • This macro takes a vector of strings and joins them together into a single string.
  • Creates a new map of the given key-value pairs.
  • Returns the latest DateTime among the given dates.
  • This macro returns the minimum of the given values.
  • Creates a new DateTime instance with the specified timezone.
  • Creates a new DateTime instance.
  • Parses the input string into a DateTime instance.
  • Prints the arguments to the console.
  • This macro takes a vector of elements and prints them to the console.
  • Subtracts the specified number of days from the given DateTime instance.
  • Creates a new vector of the given elements.
  • This macro generates a function that takes a string as input and returns a boolean. It takes two arguments:

Structs§

  • DateTime struct to ease dates and times manipulation.

Enums§

Functions§

  • This is the main entry point for the DateTime (DTT) library.