Rename TimeDelta::try_hours to hours

This commit is contained in:
Paul Dicker 2024-03-06 18:52:43 +01:00 committed by Paul Dicker
parent 03e4d7caa8
commit d5ad9f824f
7 changed files with 25 additions and 25 deletions

View File

@ -49,7 +49,7 @@ impl TimeZone for DstTester {
DstTester::TO_WINTER_MONTH_DAY.1,
)
.unwrap()
.and_time(DstTester::transition_start_local() - TimeDelta::try_hours(1).unwrap());
.and_time(DstTester::transition_start_local() - TimeDelta::hours(1).unwrap());
let local_to_summer_transition_start = NaiveDate::from_ymd(
local.year(),
@ -65,7 +65,7 @@ impl TimeZone for DstTester {
DstTester::TO_SUMMER_MONTH_DAY.1,
)
.unwrap()
.and_time(DstTester::transition_start_local() + TimeDelta::try_hours(1).unwrap());
.and_time(DstTester::transition_start_local() + TimeDelta::hours(1).unwrap());
if *local < local_to_winter_transition_end || *local >= local_to_summer_transition_end {
LocalResult::Single(DstTester::summer_offset())
@ -1522,7 +1522,7 @@ fn test_min_max_setters() {
assert_eq!(beyond_min.with_hour(beyond_min.hour()), Some(beyond_min));
assert_eq!(
beyond_min.with_hour(23),
beyond_min.checked_add_signed(TimeDelta::try_hours(1).unwrap())
beyond_min.checked_add_signed(TimeDelta::hours(1).unwrap())
);
assert_eq!(beyond_min.with_hour(5), None);
assert_eq!(beyond_min.with_minute(0), Some(beyond_min));
@ -1546,7 +1546,7 @@ fn test_min_max_setters() {
assert_eq!(beyond_max.with_hour(beyond_max.hour()), Some(beyond_max));
assert_eq!(
beyond_max.with_hour(0),
beyond_max.checked_sub_signed(TimeDelta::try_hours(1).unwrap())
beyond_max.checked_sub_signed(TimeDelta::hours(1).unwrap())
);
assert_eq!(beyond_max.with_hour(5), None);
assert_eq!(beyond_max.with_minute(beyond_max.minute()), Some(beyond_max));

View File

@ -531,15 +531,15 @@ impl NaiveTime {
/// let from_hms = |h, m, s| NaiveTime::from_hms(h, m, s).unwrap();
///
/// assert_eq!(
/// from_hms(3, 4, 5).overflowing_add_signed(TimeDelta::try_hours(11).unwrap()),
/// from_hms(3, 4, 5).overflowing_add_signed(TimeDelta::hours(11).unwrap()),
/// (from_hms(14, 4, 5), 0)
/// );
/// assert_eq!(
/// from_hms(3, 4, 5).overflowing_add_signed(TimeDelta::try_hours(23).unwrap()),
/// from_hms(3, 4, 5).overflowing_add_signed(TimeDelta::hours(23).unwrap()),
/// (from_hms(2, 4, 5), 86_400)
/// );
/// assert_eq!(
/// from_hms(3, 4, 5).overflowing_add_signed(TimeDelta::try_hours(-7).unwrap()),
/// from_hms(3, 4, 5).overflowing_add_signed(TimeDelta::hours(-7).unwrap()),
/// (from_hms(20, 4, 5), -86_400)
/// );
/// ```
@ -593,15 +593,15 @@ impl NaiveTime {
/// let from_hms = |h, m, s| NaiveTime::from_hms(h, m, s).unwrap();
///
/// assert_eq!(
/// from_hms(3, 4, 5).overflowing_sub_signed(TimeDelta::try_hours(2).unwrap()),
/// from_hms(3, 4, 5).overflowing_sub_signed(TimeDelta::hours(2).unwrap()),
/// (from_hms(1, 4, 5), 0)
/// );
/// assert_eq!(
/// from_hms(3, 4, 5).overflowing_sub_signed(TimeDelta::try_hours(17).unwrap()),
/// from_hms(3, 4, 5).overflowing_sub_signed(TimeDelta::hours(17).unwrap()),
/// (from_hms(10, 4, 5), 86_400)
/// );
/// assert_eq!(
/// from_hms(3, 4, 5).overflowing_sub_signed(TimeDelta::try_hours(-22).unwrap()),
/// from_hms(3, 4, 5).overflowing_sub_signed(TimeDelta::hours(-22).unwrap()),
/// (from_hms(1, 4, 5), -86_400)
/// );
/// ```

View File

@ -121,15 +121,15 @@ fn test_time_overflowing_add() {
let hmsm = |h, m, s, ms| NaiveTime::from_hms_milli(h, m, s, ms).unwrap();
assert_eq!(
hmsm(3, 4, 5, 678).overflowing_add_signed(TimeDelta::try_hours(11).unwrap()),
hmsm(3, 4, 5, 678).overflowing_add_signed(TimeDelta::hours(11).unwrap()),
(hmsm(14, 4, 5, 678), 0)
);
assert_eq!(
hmsm(3, 4, 5, 678).overflowing_add_signed(TimeDelta::try_hours(23).unwrap()),
hmsm(3, 4, 5, 678).overflowing_add_signed(TimeDelta::hours(23).unwrap()),
(hmsm(2, 4, 5, 678), 86_400)
);
assert_eq!(
hmsm(3, 4, 5, 678).overflowing_add_signed(TimeDelta::try_hours(-7).unwrap()),
hmsm(3, 4, 5, 678).overflowing_add_signed(TimeDelta::hours(-7).unwrap()),
(hmsm(20, 4, 5, 678), -86_400)
);
@ -148,9 +148,9 @@ fn test_time_overflowing_add() {
fn test_time_addassignment() {
let hms = |h, m, s| NaiveTime::from_hms(h, m, s).unwrap();
let mut time = hms(12, 12, 12);
time += TimeDelta::try_hours(10).unwrap();
time += TimeDelta::hours(10).unwrap();
assert_eq!(time, hms(22, 12, 12));
time += TimeDelta::try_hours(10).unwrap();
time += TimeDelta::hours(10).unwrap();
assert_eq!(time, hms(8, 12, 12));
}
@ -158,9 +158,9 @@ fn test_time_addassignment() {
fn test_time_subassignment() {
let hms = |h, m, s| NaiveTime::from_hms(h, m, s).unwrap();
let mut time = hms(12, 12, 12);
time -= TimeDelta::try_hours(10).unwrap();
time -= TimeDelta::hours(10).unwrap();
assert_eq!(time, hms(2, 12, 12));
time -= TimeDelta::try_hours(10).unwrap();
time -= TimeDelta::hours(10).unwrap();
assert_eq!(time, hms(16, 12, 12));
}

View File

@ -258,7 +258,7 @@ mod tests {
if let Some(our_result) = Local.from_local_datetime(&date).earliest() {
assert_eq!(from_local_time(&date), our_result);
}
date += TimeDelta::try_hours(1).unwrap();
date += TimeDelta::hours(1).unwrap();
}
}
}

View File

@ -498,7 +498,7 @@ mod tests {
"2012-12-12 18:30:00 UTC"
);
assert_eq!(
dt.duration_round(TimeDelta::try_hours(1).unwrap()).unwrap().to_string(),
dt.duration_round(TimeDelta::hours(1).unwrap()).unwrap().to_string(),
"2012-12-12 18:00:00 UTC"
);
assert_eq!(
@ -583,7 +583,7 @@ mod tests {
"2012-12-12 18:30:00"
);
assert_eq!(
dt.duration_round(TimeDelta::try_hours(1).unwrap()).unwrap().to_string(),
dt.duration_round(TimeDelta::hours(1).unwrap()).unwrap().to_string(),
"2012-12-12 18:00:00"
);
assert_eq!(
@ -646,7 +646,7 @@ mod tests {
"2012-12-12 18:00:00 UTC"
);
assert_eq!(
dt.duration_trunc(TimeDelta::try_hours(1).unwrap()).unwrap().to_string(),
dt.duration_trunc(TimeDelta::hours(1).unwrap()).unwrap().to_string(),
"2012-12-12 18:00:00 UTC"
);
assert_eq!(
@ -725,7 +725,7 @@ mod tests {
"2012-12-12 18:00:00"
);
assert_eq!(
dt.duration_trunc(TimeDelta::try_hours(1).unwrap()).unwrap().to_string(),
dt.duration_trunc(TimeDelta::hours(1).unwrap()).unwrap().to_string(),
"2012-12-12 18:00:00"
);
assert_eq!(

View File

@ -126,7 +126,7 @@ impl TimeDelta {
///
/// Returns `None` when the `TimeDelta` would be out of bounds.
#[inline]
pub const fn try_hours(hours: i64) -> Option<TimeDelta> {
pub const fn hours(hours: i64) -> Option<TimeDelta> {
TimeDelta::try_seconds(try_opt!(hours.checked_mul(SECS_PER_HOUR)))
}
@ -1131,7 +1131,7 @@ mod tests {
fn test_duration_const() {
const ONE_WEEK: TimeDelta = expect!(TimeDelta::weeks(1), "");
const ONE_DAY: TimeDelta = expect!(TimeDelta::days(1), "");
const ONE_HOUR: TimeDelta = expect!(TimeDelta::try_hours(1), "");
const ONE_HOUR: TimeDelta = expect!(TimeDelta::hours(1), "");
const ONE_MINUTE: TimeDelta = expect!(TimeDelta::try_minutes(1), "");
const ONE_SECOND: TimeDelta = expect!(TimeDelta::try_seconds(1), "");
const ONE_MILLI: TimeDelta = expect!(TimeDelta::try_milliseconds(1), "");

View File

@ -94,7 +94,7 @@ fn try_verify_against_date_command() {
let end = NaiveDate::from_ymd(*year + 1, 1, 1).unwrap().and_time(NaiveTime::MIN);
while date <= end {
verify_against_date_command_local(DATE_PATH, date);
date += chrono::TimeDelta::try_hours(1).unwrap();
date += chrono::TimeDelta::hours(1).unwrap();
}
}));
}