Skip to content

Commit

Permalink
build(deps): bump chrono from 0.4.22 to 0.4.23 (#750)
Browse files Browse the repository at this point in the history
* build(deps): bump chrono from 0.4.22 to 0.4.23

Bumps [chrono](https://github.com/chronotope/chrono) from 0.4.22 to 0.4.23.
- [Release notes](https://github.com/chronotope/chrono/releases)
- [Changelog](https://github.com/chronotope/chrono/blob/main/CHANGELOG.md)
- [Commits](chronotope/chrono@v0.4.22...v0.4.23)

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

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

* adopt `chrono 0.4.23`

The new `chrono` deprecates several methods we were using which would
panic if provided invalid inputs. We now instead use `_opt()` versions,
which return `Some(thing)` for valid input or `None` otherwise. Mostly
this affects test code, so we just `.unwrap()` the option (so this
behaves identically to the deprecated methods). THere is one exception
in non-test code:
`janus_aggregator::messages::TimeExt::as_naive_date_time`. Since that
method was only used in a small number of places that are already set up
to propagate errors, it now returns `Result<NaiveDateTime, Error>`.

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Tim Geoghegan <[email protected]>
  • Loading branch information
dependabot[bot] and tgeoghegan authored Nov 16, 2022
1 parent 9343429 commit 1e4eca0
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 31 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.

2 changes: 1 addition & 1 deletion janus_collector/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1027,7 +1027,7 @@ mod tests {
.with_header("Retry-After", "Wed, 21 Oct 2015 07:28:00 GMT")
.expect(1)
.create();
let ref_date_time = Utc.ymd(2015, 10, 21).and_hms(7, 28, 0);
let ref_date_time = Utc.with_ymd_and_hms(2015, 10, 21, 7, 28, 0).unwrap();
assert_matches!(
collector.poll_once(&job).await.unwrap(),
PollResult::NextAttempt(Some(RetryAfter::DateTime(system_time))) => assert_eq!(system_time, ref_date_time.into())
Expand Down
62 changes: 37 additions & 25 deletions janus_server/src/datastore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ impl<C: Clock> Transaction<'_, C> {
.prepare_cached(
"SELECT task_id, aggregator_role, aggregator_endpoints, vdaf,
max_batch_lifetime, min_batch_size, min_batch_duration,
tolerable_clock_skew, collector_hpke_config
tolerable_clock_skew, collector_hpke_config
FROM tasks",
)
.await?;
Expand Down Expand Up @@ -728,7 +728,7 @@ impl<C: Clock> Transaction<'_, C> {
&stmt,
&[
/* task_id */ &task_id.as_bytes(),
/* nonce_time */ &nonce.time().as_naive_date_time(),
/* nonce_time */ &nonce.time().as_naive_date_time()?,
/* nonce_rand */ &&nonce.rand()[..],
],
)
Expand Down Expand Up @@ -857,7 +857,7 @@ impl<C: Clock> Transaction<'_, C> {
/// put_client_report stores a client report.
#[tracing::instrument(skip(self), err)]
pub async fn put_client_report(&self, report: &Report) -> Result<(), Error> {
let nonce_time = report.nonce().time().as_naive_date_time();
let nonce_time = report.nonce().time().as_naive_date_time()?;
let nonce_rand = report.nonce().rand();

let mut encoded_extensions = Vec::new();
Expand Down Expand Up @@ -914,7 +914,7 @@ impl<C: Clock> Transaction<'_, C> {
&stmt,
&[
/* task_id */ &task_id.as_bytes(),
/* nonce_time */ &nonce.time().as_naive_date_time(),
/* nonce_time */ &nonce.time().as_naive_date_time()?,
/* nonce_rand */ &&nonce.rand()[..],
],
)
Expand All @@ -934,7 +934,7 @@ impl<C: Clock> Transaction<'_, C> {
task_id: TaskId,
report_share: &ReportShare,
) -> Result<(), Error> {
let nonce_time = report_share.nonce.time().as_naive_date_time();
let nonce_time = report_share.nonce.time().as_naive_date_time()?;
let nonce_rand = report_share.nonce.rand();

let stmt = self
Expand Down Expand Up @@ -1075,8 +1075,8 @@ impl<C: Clock> Transaction<'_, C> {
.query(
&stmt,
&[
/* lease_expiry */ &lease_expiry_time.as_naive_date_time(),
/* now */ &now.as_naive_date_time(),
/* lease_expiry */ &lease_expiry_time.as_naive_date_time()?,
/* now */ &now.as_naive_date_time()?,
/* limit */ &maximum_acquire_count,
],
)
Expand Down Expand Up @@ -1133,7 +1133,7 @@ impl<C: Clock> Transaction<'_, C> {
/* task_id */ &lease.leased().task_id.as_bytes(),
/* aggregation_job_id */
&lease.leased().aggregation_job_id.as_bytes(),
/* lease_expiry */ &lease.lease_expiry_time().as_naive_date_time(),
/* lease_expiry */ &lease.lease_expiry_time().as_naive_date_time()?,
/* lease_token */ &lease.lease_token.as_bytes(),
],
)
Expand Down Expand Up @@ -1216,7 +1216,7 @@ impl<C: Clock> Transaction<'_, C> {
A::OutputShare: for<'a> TryFrom<&'a [u8]>,
for<'a> &'a A::AggregateShare: Into<Vec<u8>>,
{
let nonce_time = nonce.time().as_naive_date_time();
let nonce_time = nonce.time().as_naive_date_time()?;
let nonce_rand = &nonce.rand()[..];

let stmt = self
Expand Down Expand Up @@ -1304,7 +1304,7 @@ impl<C: Clock> Transaction<'_, C> {
for<'a> &'a A::OutputShare: Into<Vec<u8>>,
for<'a> &'a A::AggregateShare: Into<Vec<u8>>,
{
let nonce_time = report_aggregation.nonce.time().as_naive_date_time();
let nonce_time = report_aggregation.nonce.time().as_naive_date_time()?;
let nonce_rand = &report_aggregation.nonce.rand()[..];
let state_code = report_aggregation.state.state_code();
let encoded_state_values = report_aggregation.state.encoded_values_from_state();
Expand Down Expand Up @@ -1349,7 +1349,7 @@ impl<C: Clock> Transaction<'_, C> {
for<'a> &'a A::OutputShare: Into<Vec<u8>>,
for<'a> &'a A::AggregateShare: Into<Vec<u8>>,
{
let nonce_time = report_aggregation.nonce.time().as_naive_date_time();
let nonce_time = report_aggregation.nonce.time().as_naive_date_time()?;
let nonce_rand = &report_aggregation.nonce.rand()[..];
let state_code = report_aggregation.state.state_code();
let encoded_state_values = report_aggregation.state.encoded_values_from_state();
Expand Down Expand Up @@ -1504,7 +1504,7 @@ impl<C: Clock> Transaction<'_, C> {
&stmt,
&[
/* task_id */ &task_id.as_bytes(),
/* timestamp */ &timestamp.as_naive_date_time(),
/* timestamp */ &timestamp.as_naive_date_time()?,
],
)
.await?
Expand Down Expand Up @@ -1718,8 +1718,8 @@ ORDER BY id DESC
.query(
&stmt,
&[
/* lease_expiry */ &lease_expiry_time.as_naive_date_time(),
/* now */ &now.as_naive_date_time(),
/* lease_expiry */ &lease_expiry_time.as_naive_date_time()?,
/* now */ &now.as_naive_date_time()?,
/* limit */ &maximum_acquire_count,
],
)
Expand Down Expand Up @@ -1774,7 +1774,7 @@ ORDER BY id DESC
&[
/* task_id */ &lease.leased().task_id.as_bytes(),
/* collect_job_id */ &lease.leased().collect_job_id,
/* lease_expiry */ &lease.lease_expiry_time().as_naive_date_time(),
/* lease_expiry */ &lease.lease_expiry_time().as_naive_date_time()?,
/* lease_token */ &lease.lease_token.as_bytes(),
],
)
Expand Down Expand Up @@ -1854,7 +1854,7 @@ ORDER BY id DESC
{
let unit_interval_start = batch_unit_aggregation
.unit_interval_start
.as_naive_date_time();
.as_naive_date_time()?;
let encoded_aggregation_param = batch_unit_aggregation.aggregation_param.get_encoded();
let encoded_aggregate_share: Vec<u8> = (&batch_unit_aggregation.aggregate_share).into();
let report_count = i64::try_from(batch_unit_aggregation.report_count)?;
Expand Down Expand Up @@ -1901,7 +1901,7 @@ ORDER BY id DESC
let encoded_checksum = batch_unit_aggregation.checksum.get_encoded();
let unit_interval_start = batch_unit_aggregation
.unit_interval_start
.as_naive_date_time();
.as_naive_date_time()?;
let encoded_aggregation_param = batch_unit_aggregation.aggregation_param.get_encoded();

let stmt = self
Expand Down Expand Up @@ -1951,8 +1951,8 @@ ORDER BY id DESC
for<'a> <A::AggregateShare as TryFrom<&'a [u8]>>::Error: std::fmt::Display,
for<'a> &'a A::AggregateShare: Into<Vec<u8>>,
{
let unit_interval_start = interval.start().as_naive_date_time();
let unit_interval_end = interval.end().as_naive_date_time();
let unit_interval_start = interval.start().as_naive_date_time()?;
let unit_interval_end = interval.end().as_naive_date_time()?;
let encoded_aggregation_param = aggregation_param.get_encoded();

let stmt = self
Expand Down Expand Up @@ -2078,7 +2078,7 @@ ORDER BY id DESC
&stmt,
&[
/* task_id */ &task_id.as_bytes(),
/* timestamp */ &timestamp.as_naive_date_time(),
/* timestamp */ &timestamp.as_naive_date_time()?,
],
)
.await?
Expand Down Expand Up @@ -4064,7 +4064,7 @@ mod tests {
Box::pin(async move {
let report_share_exists = tx.check_report_share_exists(task_id, report_share.nonce).await?;

let nonce_time = report_share.nonce.time().as_naive_date_time();
let nonce_time = report_share.nonce.time().as_naive_date_time()?;
let nonce_rand = report_share.nonce.rand();
let row = tx
.tx
Expand Down Expand Up @@ -6297,7 +6297,10 @@ mod tests {
.get::<_, SqlInterval>("interval");
let ref_interval = Interval::new(
Time::from_naive_date_time(
NaiveDate::from_ymd(2020, 1, 1).and_hms(10, 0, 0),
NaiveDate::from_ymd_opt(2020, 1, 1)
.unwrap()
.and_hms_opt(10, 0, 0)
.unwrap(),
),
Duration::from_minutes(30).unwrap(),
)
Expand All @@ -6314,7 +6317,10 @@ mod tests {
.get::<_, SqlInterval>("interval");
let ref_interval = Interval::new(
Time::from_naive_date_time(
NaiveDate::from_ymd(1970, 2, 3).and_hms(23, 0, 0),
NaiveDate::from_ymd_opt(1970, 2, 3)
.unwrap()
.and_hms_opt(23, 0, 0)
.unwrap(),
),
Duration::from_hours(1).unwrap(),
)?;
Expand All @@ -6341,7 +6347,10 @@ mod tests {
&[&SqlInterval::from(
Interval::new(
Time::from_naive_date_time(
NaiveDate::from_ymd(1972, 7, 21).and_hms(5, 30, 0),
NaiveDate::from_ymd_opt(1972, 7, 21)
.unwrap()
.and_hms_opt(5, 30, 0)
.unwrap(),
),
Duration::from_minutes(30).unwrap(),
)
Expand All @@ -6363,7 +6372,10 @@ mod tests {
&[&SqlInterval::from(
Interval::new(
Time::from_naive_date_time(
NaiveDate::from_ymd(2021, 10, 5).and_hms(0, 0, 0),
NaiveDate::from_ymd_opt(2021, 10, 5)
.unwrap()
.and_hms_opt(0, 0, 0)
.unwrap(),
),
Duration::from_hours(24).unwrap(),
)
Expand Down
14 changes: 11 additions & 3 deletions janus_server/src/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl DurationExt for Duration {
/// Extension methods on [`Time`].
pub trait TimeExt: Sized {
/// Convert this [`Time`] into a [`NaiveDateTime`], representing an instant in the UTC timezone.
fn as_naive_date_time(&self) -> NaiveDateTime;
fn as_naive_date_time(&self) -> Result<NaiveDateTime, Error>;

/// Convert a [`NaiveDateTime`] representing an instant in the UTC timezone into a [`Time`].
fn from_naive_date_time(time: NaiveDateTime) -> Self;
Expand All @@ -70,8 +70,16 @@ pub trait TimeExt: Sized {
}

impl TimeExt for Time {
fn as_naive_date_time(&self) -> NaiveDateTime {
NaiveDateTime::from_timestamp(self.as_seconds_since_epoch() as i64, 0)
fn as_naive_date_time(&self) -> Result<NaiveDateTime, Error> {
NaiveDateTime::from_timestamp_opt(
self.as_seconds_since_epoch()
.try_into()
.map_err(|_| Error::IllegalTimeArithmetic("number of seconds too big for i64"))?,
0,
)
.ok_or(Error::IllegalTimeArithmetic(
"number of seconds is out of range",
))
}

/// Convert a [`NaiveDateTime`] representing an instant in the UTC timezone into a [`Time`].
Expand Down

0 comments on commit 1e4eca0

Please sign in to comment.