Skip to content

Commit

Permalink
build(deps): Bump chrono from 0.4.34 to 0.4.35 (#2797)
Browse files Browse the repository at this point in the history
* build(deps): Bump chrono from 0.4.34 to 0.4.35

Bumps [chrono](https://github.com/chronotope/chrono) from 0.4.34 to 0.4.35.
- [Release notes](https://github.com/chronotope/chrono/releases)
- [Changelog](https://github.com/chronotope/chrono/blob/main/CHANGELOG.md)
- [Commits](chronotope/chrono@v0.4.34...v0.4.35)

---
updated-dependencies:
- dependency-name: chrono
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>

* Fix deprecation warnings

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: David Cook <[email protected]>
  • Loading branch information
dependabot[bot] and divergentdave authored Mar 11, 2024
1 parent 99efe1c commit dd73b37
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 39 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions aggregator/src/binary_utils/job_driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ where
// remains until the expiry time, minus the clock skew allowance. All math saturates, since
// we want to timeout immediately if any of these subtractions would underflow.
Duration::from_secs(
u64::try_from(lease_expiry.timestamp())
u64::try_from(lease_expiry.and_utc().timestamp())
.unwrap_or_default()
.saturating_sub(self.clock.now().as_seconds_since_epoch())
.saturating_sub(self.worker_lease_clock_skew_allowance.as_secs()),
Expand All @@ -265,7 +265,7 @@ where
#[cfg(test)]
mod tests {
use super::JobDriver;
use chrono::NaiveDateTime;
use chrono::{DateTime, NaiveDateTime, Utc};
use janus_aggregator_core::{
datastore::{self, models::Lease},
test_util::noop_meter,
Expand Down Expand Up @@ -330,12 +330,12 @@ mod tests {
IncompleteJob {
task_id: random(),
job_id: random(),
lease_expiry: NaiveDateTime::from_timestamp_opt(100, 0).unwrap(),
lease_expiry: DateTime::<Utc>::from_timestamp(100, 0).unwrap().naive_utc(),
},
IncompleteJob {
task_id: random(),
job_id: random(),
lease_expiry: NaiveDateTime::from_timestamp_opt(200, 0).unwrap(),
lease_expiry: DateTime::<Utc>::from_timestamp(200, 0).unwrap().naive_utc(),
},
]),
// Second job finder call will be immediately after the first: no more jobs
Expand All @@ -347,12 +347,12 @@ mod tests {
IncompleteJob {
task_id: random(),
job_id: random(),
lease_expiry: NaiveDateTime::from_timestamp_opt(300, 0).unwrap(),
lease_expiry: DateTime::<Utc>::from_timestamp(300, 0).unwrap().naive_utc(),
},
IncompleteJob {
task_id: random(),
job_id: random(),
lease_expiry: NaiveDateTime::from_timestamp_opt(400, 0).unwrap(),
lease_expiry: DateTime::<Utc>::from_timestamp(400, 0).unwrap().naive_utc(),
},
]),
]));
Expand Down
12 changes: 8 additions & 4 deletions aggregator_core/src/datastore/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2836,7 +2836,8 @@ async fn run_collection_job_acquire_test_case<Q: CollectableQueryType>(
test_case.query_type,
VdafInstance::Fake,
),
clock.now().as_naive_date_time().unwrap() + chrono::Duration::seconds(100),
clock.now().as_naive_date_time().unwrap()
+ chrono::Duration::try_seconds(100).unwrap(),
)
})
.collect();
Expand Down Expand Up @@ -2969,7 +2970,8 @@ async fn time_interval_collection_job_acquire_release_happy_path(
assert_eq!(acquired_job.leased(), reacquired_job.leased());
assert_eq!(
*acquired_job.lease_expiry_time(),
*reacquired_job.lease_expiry_time() + chrono::Duration::seconds(100),
*reacquired_job.lease_expiry_time()
+ chrono::Duration::try_seconds(100).unwrap(),
);
}

Expand Down Expand Up @@ -3099,7 +3101,8 @@ async fn fixed_size_collection_job_acquire_release_happy_path(
assert_eq!(acquired_job.leased(), reacquired_job.leased());
assert_eq!(
*acquired_job.lease_expiry_time(),
*reacquired_job.lease_expiry_time() + chrono::Duration::seconds(100),
*reacquired_job.lease_expiry_time()
+ chrono::Duration::try_seconds(100).unwrap(),
);
}

Expand Down Expand Up @@ -3563,7 +3566,8 @@ async fn collection_job_acquire_job_max(ephemeral_datastore: EphemeralDatastore)
task::QueryType::TimeInterval,
VdafInstance::Fake,
),
clock.now().as_naive_date_time().unwrap() + chrono::Duration::seconds(100),
clock.now().as_naive_date_time().unwrap()
+ chrono::Duration::try_seconds(100).unwrap(),
)
})
.collect();
Expand Down
36 changes: 13 additions & 23 deletions collector/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ mod tests {
PollResult,
};
use assert_matches::assert_matches;
use chrono::{NaiveDateTime, TimeZone, Utc};
use chrono::{DateTime, TimeZone, Utc};
#[cfg(feature = "fpvec_bounded_l2")]
use fixed_macro::fixed;
use janus_core::{
Expand Down Expand Up @@ -912,10 +912,8 @@ mod tests {
PartialBatchSelector::new_time_interval(),
1,
(
Utc.from_utc_datetime(
&NaiveDateTime::from_timestamp_opt(1_000_000, 0).unwrap(),
),
chrono::Duration::seconds(3600),
DateTime::<Utc>::from_timestamp(1_000_000, 0).unwrap(),
chrono::Duration::try_seconds(3600).unwrap(),
),
1,
),
Expand Down Expand Up @@ -980,10 +978,8 @@ mod tests {
PartialBatchSelector::new_time_interval(),
1,
(
Utc.from_utc_datetime(
&NaiveDateTime::from_timestamp_opt(1_000_000, 0).unwrap(),
),
chrono::Duration::seconds(3600),
DateTime::<Utc>::from_timestamp(1_000_000, 0).unwrap(),
chrono::Duration::try_seconds(3600).unwrap(),
),
144
)
Expand Down Expand Up @@ -1047,10 +1043,8 @@ mod tests {
PartialBatchSelector::new_time_interval(),
1,
(
Utc.from_utc_datetime(
&NaiveDateTime::from_timestamp_opt(1_000_000, 0).unwrap(),
),
chrono::Duration::seconds(3600),
DateTime::<Utc>::from_timestamp(1_000_000, 0).unwrap(),
chrono::Duration::try_seconds(3600).unwrap(),
),
Vec::from([0, 0, 0, 1, 0])
)
Expand Down Expand Up @@ -1123,10 +1117,8 @@ mod tests {
PartialBatchSelector::new_time_interval(),
1,
(
Utc.from_utc_datetime(
&NaiveDateTime::from_timestamp_opt(1_000_000, 0).unwrap(),
),
chrono::Duration::seconds(3600),
DateTime::<Utc>::from_timestamp(1_000_000, 0).unwrap(),
chrono::Duration::try_seconds(3600).unwrap(),
),
Vec::from([0.0625, 0.125, 0.25])
)
Expand Down Expand Up @@ -1192,8 +1184,8 @@ mod tests {
PartialBatchSelector::new_fixed_size(batch_id),
1,
(
Utc.from_utc_datetime(&NaiveDateTime::from_timestamp_opt(0, 0).unwrap()),
chrono::Duration::seconds(1),
DateTime::<Utc>::from_timestamp(0, 0).unwrap(),
chrono::Duration::try_seconds(1).unwrap(),
),
1
)
Expand Down Expand Up @@ -1270,10 +1262,8 @@ mod tests {
PartialBatchSelector::new_time_interval(),
1,
(
Utc.from_utc_datetime(
&NaiveDateTime::from_timestamp_opt(1_000_000, 0).unwrap(),
),
chrono::Duration::seconds(3600),
DateTime::<Utc>::from_timestamp(1_000_000, 0).unwrap(),
chrono::Duration::try_seconds(3600).unwrap(),
),
1,
)
Expand Down
12 changes: 8 additions & 4 deletions core/src/time.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Utilities for timestamps and durations.
use chrono::{NaiveDateTime, Utc};
use chrono::{DateTime, NaiveDateTime, Utc};
use janus_messages::{Duration, Error, Interval, Time};
use std::{
fmt::{Debug, Formatter},
Expand Down Expand Up @@ -114,10 +114,13 @@ pub trait DurationExt: Sized {

impl DurationExt for Duration {
fn as_chrono_duration(&self) -> Result<chrono::Duration, Error> {
Ok(chrono::Duration::seconds(
chrono::Duration::try_seconds(
self.as_seconds()
.try_into()
.map_err(|_| Error::IllegalTimeArithmetic("number of seconds too big for i64"))?,
)
.ok_or(Error::IllegalTimeArithmetic(
"number of milliseconds too big for i64",
))
}

Expand Down Expand Up @@ -220,7 +223,7 @@ impl TimeExt for Time {
}

fn as_naive_date_time(&self) -> Result<NaiveDateTime, Error> {
NaiveDateTime::from_timestamp_opt(
DateTime::<Utc>::from_timestamp(
self.as_seconds_since_epoch()
.try_into()
.map_err(|_| Error::IllegalTimeArithmetic("number of seconds too big for i64"))?,
Expand All @@ -229,10 +232,11 @@ impl TimeExt for Time {
.ok_or(Error::IllegalTimeArithmetic(
"number of seconds is out of range",
))
.map(|dt| dt.naive_utc())
}

fn from_naive_date_time(time: &NaiveDateTime) -> Self {
Self::from_seconds_since_epoch(time.timestamp() as u64)
Self::from_seconds_since_epoch(time.and_utc().timestamp() as u64)
}

fn add(&self, duration: &Duration) -> Result<Self, Error> {
Expand Down

0 comments on commit dd73b37

Please sign in to comment.