Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
adriangb committed Jul 13, 2023
1 parent 2a2888a commit f7570db
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 38 deletions.
4 changes: 2 additions & 2 deletions src/datetime.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::TimeConfigBuilder;
use crate::numbers::{float_parse_bytes, IntFloat};
use crate::{Date, ParseError, Time, time::TimeConfig};
use crate::TimeConfigBuilder;
use crate::{time::TimeConfig, Date, ParseError, Time};
use std::cmp::Ordering;
use std::fmt;
use std::time::SystemTime;
Expand Down
2 changes: 1 addition & 1 deletion src/duration.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::cmp::Ordering;
use std::fmt;

use crate::{ParseError, Time, time::TimeConfig, TimeConfigBuilder};
use crate::{time::TimeConfig, ParseError, Time, TimeConfigBuilder};

/// A Duration
///
Expand Down
6 changes: 5 additions & 1 deletion src/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,11 @@ impl Time {
/// assert_eq!(d.to_string(), "01:02:20.000123");
/// ```
pub fn from_timestamp(timestamp_second: u32, timestamp_microsecond: u32) -> Result<Self, ParseError> {
Time::from_timestamp_with_config(timestamp_second, timestamp_microsecond, &TimeConfigBuilder::new().build())
Time::from_timestamp_with_config(
timestamp_second,
timestamp_microsecond,
&TimeConfigBuilder::new().build(),
)
}

/// Like `from_timestamp` but with a `TimeConfig`
Expand Down
49 changes: 15 additions & 34 deletions tests/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1251,8 +1251,8 @@ fn test_time_parse_truncate_seconds() {
let time = Time::parse_bytes_with_config(
"12:13:12.123456789".as_bytes(),
&(TimeConfigBuilder::new()
.microseconds_precision_overflow_behavior(MicrosecondsPrecisionOverflowBehavior::Truncate)
.build())
.microseconds_precision_overflow_behavior(MicrosecondsPrecisionOverflowBehavior::Truncate)
.build()),
)
.unwrap();
assert_eq!(time.to_string(), "12:13:12.123456");
Expand All @@ -1263,8 +1263,8 @@ fn test_datetime_parse_truncate_seconds() {
let time = DateTime::parse_bytes_with_config(
"2020-01-01T12:13:12.123456789".as_bytes(),
&(TimeConfigBuilder::new()
.microseconds_precision_overflow_behavior(MicrosecondsPrecisionOverflowBehavior::Truncate)
.build())
.microseconds_precision_overflow_behavior(MicrosecondsPrecisionOverflowBehavior::Truncate)
.build()),
)
.unwrap();
assert_eq!(time.to_string(), "2020-01-01T12:13:12.123456");
Expand All @@ -1275,8 +1275,8 @@ fn test_duration_parse_truncate_seconds() {
let time = Duration::parse_bytes_with_config(
"00:00:00.1234567".as_bytes(),
&(TimeConfigBuilder::new()
.microseconds_precision_overflow_behavior(MicrosecondsPrecisionOverflowBehavior::Truncate)
.build())
.microseconds_precision_overflow_behavior(MicrosecondsPrecisionOverflowBehavior::Truncate)
.build()),
)
.unwrap();
assert_eq!(time.to_string(), "PT0.123456S");
Expand All @@ -1286,9 +1286,7 @@ fn test_duration_parse_truncate_seconds() {
fn test_time_parse_bytes_does_not_add_offset_for_rfc3339() {
let time = Time::parse_bytes_with_config(
"12:13:12".as_bytes(),
&(TimeConfigBuilder::new()
.unix_timestamp_offset(Some(0))
.build())
&(TimeConfigBuilder::new().unix_timestamp_offset(Some(0)).build()),
)
.unwrap();
assert_eq!(time.to_string(), "12:13:12");
Expand All @@ -1298,9 +1296,7 @@ fn test_time_parse_bytes_does_not_add_offset_for_rfc3339() {
fn test_datetime_parse_bytes_does_not_add_offset_for_rfc3339() {
let time = DateTime::parse_bytes_with_config(
"2020-01-01T12:13:12".as_bytes(),
&(TimeConfigBuilder::new()
.unix_timestamp_offset(Some(0))
.build())
&(TimeConfigBuilder::new().unix_timestamp_offset(Some(0)).build()),
)
.unwrap();
assert_eq!(time.to_string(), "2020-01-01T12:13:12");
Expand All @@ -1310,9 +1306,7 @@ fn test_datetime_parse_bytes_does_not_add_offset_for_rfc3339() {
fn test_datetime_parse_unix_timestamp_from_bytes_with_utc_offset() {
let time = DateTime::parse_bytes_with_config(
"1689102037.5586429".as_bytes(),
&(TimeConfigBuilder::new()
.unix_timestamp_offset(Some(0))
.build())
&(TimeConfigBuilder::new().unix_timestamp_offset(Some(0)).build()),
)
.unwrap();
assert_eq!(time.to_string(), "2023-07-11T19:00:37.558643Z");
Expand All @@ -1322,36 +1316,23 @@ fn test_datetime_parse_unix_timestamp_from_bytes_with_utc_offset() {
fn test_datetime_parse_unix_timestamp_from_bytes_as_naive() {
let time = DateTime::parse_bytes_with_config(
"1689102037.5586429".as_bytes(),
&(TimeConfigBuilder::new()
.unix_timestamp_offset(None)
.build())
&(TimeConfigBuilder::new().unix_timestamp_offset(None).build()),
)
.unwrap();
assert_eq!(time.to_string(), "2023-07-11T19:00:37.558643");
}

#[test]
fn test_time_parse_unix_timestamp_from_bytes_with_utc_offset() {
let time = Time::from_timestamp_with_config(
1,
2,
&(TimeConfigBuilder::new()
.unix_timestamp_offset(Some(0))
.build())
)
.unwrap();
let time =
Time::from_timestamp_with_config(1, 2, &(TimeConfigBuilder::new().unix_timestamp_offset(Some(0)).build()))
.unwrap();
assert_eq!(time.to_string(), "00:00:01.000002Z");
}

#[test]
fn test_time_parse_unix_timestamp_from_bytes_as_naive() {
let time = Time::from_timestamp_with_config(
1,
2,
&(TimeConfigBuilder::new()
.unix_timestamp_offset(None)
.build())
)
.unwrap();
let time = Time::from_timestamp_with_config(1, 2, &(TimeConfigBuilder::new().unix_timestamp_offset(None).build()))
.unwrap();
assert_eq!(time.to_string(), "00:00:01.000002");
}

0 comments on commit f7570db

Please sign in to comment.