Skip to content

Commit

Permalink
feat(dtt): ✨ decoupling DateTime struct to datetime.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastienrousseau committed Aug 29, 2024
1 parent 6d6e150 commit 83e8c75
Show file tree
Hide file tree
Showing 8 changed files with 773 additions and 756 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ You can find these in the `examples` and `tests` directories of the project.

```rust
// Import the DateTime struct and the dtt_print macro
use dtt::DateTime;
use dtt::datetime::DateTime;
use dtt::dtt_print;

#[test]
Expand All @@ -191,7 +191,7 @@ fn example_1() {

```rust
// Import the DateTime struct and the validation macros
use dtt::DateTime;
use dtt::datetime::DateTime;
use dtt::{
is_valid_day,
is_valid_hour,
Expand Down Expand Up @@ -240,11 +240,11 @@ assert!(DateTime::is_valid_iso_8601("2023-05-11T17:30:00+01:00"));
#### Example 3: Validate string to `DateTime` conversion

```rust
use dtt::DateTime;
use dtt::datetime::DateTime;
use std::str::FromStr;

let date_str = "2022-01-01T12:00:00+01:00";
let mut result: Result<DateTime, dtt::DateTimeError> = DateTime::from_str(date_str);
let mut result: Result<DateTime, dtt::datetime::DateTimeError> = DateTime::from_str(date_str);

assert_eq!(result.as_mut().unwrap().iso_8601, date_str);
assert_eq!(result.as_mut().unwrap().year, 2022);
Expand Down
2 changes: 1 addition & 1 deletion benches/criterion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use criterion::{
black_box, criterion_group, criterion_main, Criterion,
};
use dtt::DateTime;
use dtt::datetime::DateTime;

fn new_date(c: &mut Criterion) {
c.bench_function("new", |b| b.iter(|| DateTime::new));
Expand Down
2 changes: 1 addition & 1 deletion examples/dtt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#![allow(missing_docs)]

use self::dtt::DateTime;
use self::dtt::datetime::DateTime;
use dtt;
use std::str::FromStr;

Expand Down
723 changes: 723 additions & 0 deletions src/datetime.rs

Large diffs are not rendered by default.

726 changes: 6 additions & 720 deletions src/lib.rs

Large diffs are not rendered by default.

64 changes: 36 additions & 28 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
#[macro_export]
macro_rules! dtt_now {
() => {{
dtt::DateTime::new()
dtt::datetime::DateTime::new()
}};
}

Expand All @@ -68,7 +68,7 @@ macro_rules! dtt_now {
/// # Examples
///
/// ```
/// use dtt::DateTime;
/// use dtt::datetime::DateTime;
/// use dtt::dtt_parse;
///
/// let input = "2022-01-01T12:00:00+01:00";
Expand All @@ -88,7 +88,7 @@ macro_rules! dtt_now {
#[macro_export]
macro_rules! dtt_parse {
($input:expr) => {{
dtt::DateTime::parse($input)
dtt::datetime::DateTime::parse($input)
}};
}

Expand Down Expand Up @@ -177,7 +177,7 @@ macro_rules! dtt_map {
///
/// # Examples
/// ```
/// use dtt::DateTime;
/// use dtt::datetime::DateTime;
/// use dtt::dtt_assert;
///
/// // Example date components
Expand Down Expand Up @@ -249,7 +249,7 @@ macro_rules! dtt_min {
/// # Examples
///
/// ```rust
/// use dtt::{DateTime, dtt_max, error::DateTimeError};
/// use dtt::{dtt_max, datetime::DateTime, error::DateTimeError};
///
/// let max_int = dtt_max!(10, 20);
/// assert_eq!(max_int, 20);
Expand Down Expand Up @@ -343,7 +343,7 @@ macro_rules! dtt_print_vec {
/// # Examples
/// ```
/// use dtt::is_valid;
/// use dtt::DateTime;
/// use dtt::datetime::DateTime;
///
/// // Validation of a day
/// let input = "31".to_string();
Expand Down Expand Up @@ -405,35 +405,43 @@ macro_rules! is_valid {
fn $name(input: &str) -> bool {
match input.parse::<$type>() {
Ok(parsed_val) => match stringify!($name) {
"day" => dtt::DateTime::is_valid_day(
"day" => dtt::datetime::DateTime::is_valid_day(
&parsed_val.to_string(),
),
"hour" => dtt::DateTime::is_valid_hour(
"hour" => dtt::datetime::DateTime::is_valid_hour(
&parsed_val.to_string(),
),
"minute" => dtt::DateTime::is_valid_minute(
&parsed_val.to_string(),
),
"month" => dtt::DateTime::is_valid_month(
&parsed_val.to_string(),
),
"second" => dtt::DateTime::is_valid_second(
"minute" => {
dtt::datetime::DateTime::is_valid_minute(
&parsed_val.to_string(),
)
}
"month" => dtt::datetime::DateTime::is_valid_month(
&parsed_val.to_string(),
),
"second" => {
dtt::datetime::DateTime::is_valid_second(
&parsed_val.to_string(),
)
}
"microsecond" => {
dtt::DateTime::is_valid_microsecond(
dtt::datetime::DateTime::is_valid_microsecond(
&parsed_val.to_string(),
)
}
"ordinal" => dtt::DateTime::is_valid_ordinal(
&parsed_val.to_string(),
),
"time" => dtt::DateTime::is_valid_time(
&parsed_val.to_string(),
),
"iso_8601" => dtt::DateTime::is_valid_iso_8601(
"ordinal" => {
dtt::datetime::DateTime::is_valid_ordinal(
&parsed_val.to_string(),
)
}
"time" => dtt::datetime::DateTime::is_valid_time(
&parsed_val.to_string(),
),
"iso_8601" => {
dtt::datetime::DateTime::is_valid_iso_8601(
&parsed_val.to_string(),
)
}
_ => false,
},
Err(_) => false,
Expand All @@ -456,7 +464,7 @@ macro_rules! is_valid {
#[doc = "Creates a new DateTime instance with the specified timezone."]
macro_rules! dtt_new_with_tz {
($tz:expr) => {{
dtt::DateTime::new_with_tz($tz).expect(
dtt::datetime::DateTime::new_with_tz($tz).expect(
"Failed to create DateTime with the specified timezone",
)
}};
Expand All @@ -475,7 +483,7 @@ macro_rules! dtt_new_with_tz {
///
/// # Examples
/// ```
/// use dtt::{DateTime, dtt_add_days};
/// use dtt::{datetime::DateTime, dtt_add_days};
///
/// let dt = DateTime::parse("2023-01-01T12:00:00+00:00").unwrap();
/// let future_date = dtt_add_days!(dt, 5);
Expand Down Expand Up @@ -650,7 +658,7 @@ macro_rules! dtt_diff_days {
/// # Examples
///
/// ```rust
/// use dtt::{DateTime, dtt_clone};
/// use dtt::{datetime::DateTime, dtt_clone};
///
/// let dt1 = DateTime::new();
/// let dt2 = dtt_clone!(dt1.clone());
Expand Down Expand Up @@ -697,7 +705,7 @@ macro_rules! dtt_clone {
/// # Examples
///
/// ```rust
/// use dtt::{DateTime, dtt_format};
/// use dtt::{datetime::DateTime, dtt_format};
///
/// let dt = DateTime {
/// day: 1,
Expand Down Expand Up @@ -758,7 +766,7 @@ macro_rules! dtt_format {
///
/// # Examples
/// ```
/// use dtt::{DateTime, dtt_sub_days};
/// use dtt::{datetime::DateTime, dtt_sub_days};
///
/// let dt = DateTime::parse("2023-01-01T12:00:00+00:00").unwrap();
/// let past_date = dtt_sub_days!(dt, 5);
Expand Down
2 changes: 1 addition & 1 deletion tests/test_lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#[cfg(test)]

mod tests {
use dtt::DateTime;
use dtt::datetime::DateTime;
use regex::Regex;
use std::str::FromStr;
use time::UtcOffset;
Expand Down
2 changes: 1 addition & 1 deletion tests/test_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

#[cfg(test)]
mod tests {
use dtt::datetime::DateTime;
use dtt::is_valid;
use dtt::DateTime;
use dtt::*;

#[test]
Expand Down

0 comments on commit 83e8c75

Please sign in to comment.