Struct mini_functions::date::DateTime
source · pub struct DateTime {}
Expand description
Re-exported main DateTime
type from dtt for date/time handling.
DateTime struct to ease dates and times manipulation.
This module includes date and time types, such as day, hour,ISO 8601 date and time, and many more methods.
Fields§
§day: u8
Day of the month: (1-31)
hour: u8
Hour of the day: (0-23)
iso_8601: String
ISO 8601 date and time: (e.g. “2023-01-01T00:00:00+00:00”)
iso_week: u8
ISO week number: (1-53)
microsecond: u32
Microsecond: (0-999999)
minute: u8
Minute of the hour: (0-59)
month: String
Month: (e.g. “January”)
now: String
Now object: (e.g. “2023-01-01”)
offset: String
Offset from UTC: (e.g. “+00:00”)
ordinal: u16
Ordinal date: (1-366)
second: u8
Second of the minute: (0-59)
time: String
Time object: (e.g. “00:00:00”)
tz: String
Tz object: (e.g. “UTC”)
weekday: String
Weekday object: (e.g. “Monday”)
year: i32
Year object: (e.g. “2023”)
Implementations§
source§impl DateTime
impl DateTime
sourcepub fn parse(input: &str) -> Result<DateTime, &'static str>
pub fn parse(input: &str) -> Result<DateTime, &'static str>
Parse the input string and create a new DateTime
object.
This function takes an input string and attempts to parse it into a DateTime
object.
The input string can be in ISO 8601 format or a date-only format (YYYY-MM-DD).
If the input matches the ISO 8601 format, the resulting DateTime
object will be set
to the current UTC time. If the input matches the date-only format, the resulting DateTime
object will have the time components set to zero and the timezone set to UTC.
Arguments
input
- A string slice that represents the date and time to parse.
Returns
Result<DateTime, &'static str>
- A result indicating either the successfully parsedDateTime
object or an error message if the input format is invalid.
sourcepub fn new_with_tz(tz: &str) -> DateTime
pub fn new_with_tz(tz: &str) -> DateTime
Create a new DateTime object with a custom timezone.
Custom timezones 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 |
Example
use dtt::DateTime;
use dtt::dtt_print;
let paris_time = DateTime::new_with_tz("CEST");
dtt_print!(paris_time);
sourcepub fn is_valid_day(input: &str) -> bool
pub fn is_valid_day(input: &str) -> bool
Check if the input is a valid day. 31 is valid. 32 is not valid.
sourcepub fn is_valid_hour(input: &str) -> bool
pub fn is_valid_hour(input: &str) -> bool
Check if the input is a valid hour. 23:59 is valid. 24:00 is not valid.
sourcepub fn is_valid_minute(input: &str) -> bool
pub fn is_valid_minute(input: &str) -> bool
Check if the input is a valid minute. 59 is valid. 60 is not valid.
sourcepub fn is_valid_month(input: &str) -> bool
pub fn is_valid_month(input: &str) -> bool
Check if the input is a valid month. 12 is valid. 13 is not valid.
sourcepub fn is_valid_ordinal(input: &str) -> bool
pub fn is_valid_ordinal(input: &str) -> bool
Check if the input is a valid ordinal date. 366 is valid. 367 is not valid.
sourcepub fn is_valid_second(input: &str) -> bool
pub fn is_valid_second(input: &str) -> bool
Check if the input is a valid second. 59 is valid. 60 is not valid.
sourcepub fn is_valid_time(input: &str) -> bool
pub fn is_valid_time(input: &str) -> bool
Check if the input is a valid time. 23:59:59 is valid. 24:00:00 is not valid.
sourcepub fn is_valid_iso_8601(input: &str) -> bool
pub fn is_valid_iso_8601(input: &str) -> bool
Check if the input is a valid ISO 8601 date and time. 2023-01-01T00:00:00+00:00 is valid. 2023-01-01T00:00:00+00:00:00 is not valid.
sourcepub fn is_valid_iso_week(input: &str) -> bool
pub fn is_valid_iso_week(input: &str) -> bool
Check if the input is a valid ISO week number. 53 is valid. 54 is not valid.
sourcepub fn is_valid_microsecond(input: &str) -> bool
pub fn is_valid_microsecond(input: &str) -> bool
Check if the input is a valid microsecond. 999999 is valid. 1000000 is not valid.
sourcepub fn next_day(&self) -> DateTime
pub fn next_day(&self) -> DateTime
Calculate the next day. Returns a new DateTime struct. The time zone is not updated.
sourcepub fn relative_delta(&self) -> DateTime
pub fn relative_delta(&self) -> DateTime
Calculates the relative delta based on the current date and time
and the fields of the RelativeDelta
structure.
Returns the DateTime
structure that represents the resulting
date and time.
sourcepub fn previous_day(&self) -> DateTime
pub fn previous_day(&self) -> DateTime
Calculate the previous day.
Returns the DateTime
structure that represents the resulting
date and time.
Trait Implementations§
source§impl<'de> Deserialize<'de> for DateTime
impl<'de> Deserialize<'de> for DateTime
source§fn deserialize<__D>(
__deserializer: __D
) -> Result<DateTime, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D
) -> Result<DateTime, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
source§impl PartialEq for DateTime
impl PartialEq for DateTime
source§impl Serialize for DateTime
impl Serialize for DateTime
source§fn serialize<__S>(
&self,
__serializer: __S
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
impl StructuralPartialEq for DateTime
Auto Trait Implementations§
impl RefUnwindSafe for DateTime
impl Send for DateTime
impl Sync for DateTime
impl Unpin for DateTime
impl UnwindSafe for DateTime
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> FromBase64 for Twhere
T: for<'de> Deserialize<'de>,
impl<T> FromBase64 for Twhere
T: for<'de> Deserialize<'de>,
§impl<T> Pointable for T
impl<T> Pointable for T
source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian()
.