Skip to content

Commit 14d9626

Browse files
committed
Replace remaining uses of chrono::Duration with chrono::TimeDelta
1 parent ff938d9 commit 14d9626

File tree

6 files changed

+18
-9
lines changed

6 files changed

+18
-9
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Internal Changes
1111

12+
All:
13+
14+
- Replace remaining uses of `chrono::Duration` type alias with the actual type
15+
(`chrono::TimeDelta`)
16+
- This shouldn't be a breaking change even though `cargo-public-api` says
17+
so; I can't imagine any way existing calling code would be broken. The only
18+
changed public api is `FileBackend::create_upload` where it is used as a
19+
parameter.
20+
1221
bobashare:
1322

1423
- Merge many separated module files into inline `pub mod ... {` definitions

bobashare-web/src/api/v1/upload.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use axum::{
1111
};
1212
use axum_extra::{extract::WithRejection, typed_header::TypedHeaderRejection, TypedHeader};
1313
use bobashare::{generate_randomized_id, storage::file::CreateUploadError};
14-
use chrono::{DateTime, Duration, Utc};
14+
use chrono::{DateTime, TimeDelta, Utc};
1515
use displaydoc::Display;
1616
use futures_util::TryStreamExt;
1717
use headers::{ContentLength, ContentType};
@@ -183,7 +183,7 @@ pub async fn put(
183183
None
184184
} else {
185185
Some(
186-
Duration::from_std(str_to_duration(expiry).map_err(|e| {
186+
TimeDelta::from_std(str_to_duration(expiry).map_err(|e| {
187187
UploadError::ParseHeader {
188188
name: String::from("Bobashare-Expiry"),
189189
source: anyhow::Error::new(e).context("error parsing duration string"),

bobashare-web/src/views/display.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use axum::{
88
response::IntoResponse,
99
};
1010
use bobashare::storage::{file::OpenUploadError, handle::UploadHandle};
11-
use chrono::{DateTime, Duration, Utc};
11+
use chrono::{DateTime, TimeDelta, Utc};
1212
use displaydoc::Display;
1313
use hyper::{header, StatusCode};
1414
use mime::Mime;
@@ -68,7 +68,7 @@ pub struct DisplayTemplate<'s> {
6868
pub id: String,
6969
pub filename: String,
7070
pub expiry_date: Option<DateTime<Utc>>,
71-
pub expiry_relative: Option<Duration>,
71+
pub expiry_relative: Option<TimeDelta>,
7272
pub size: u64,
7373
pub mimetype: Mime,
7474
pub contents: DisplayType,

bobashare-web/src/views/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use axum::{
99
routing::get,
1010
Router,
1111
};
12-
use chrono::Duration;
12+
use chrono::TimeDelta;
1313
use hyper::StatusCode;
1414
use tracing::{event, Level};
1515
use url::Url;
@@ -32,7 +32,7 @@ pub struct TemplateState<'s> {
3232
version: &'static str,
3333
base_url: &'s Url,
3434
max_file_size: u64,
35-
max_expiry: Option<Duration>,
35+
max_expiry: Option<TimeDelta>,
3636
extra_footer_text: Option<&'s str>,
3737
about_page: Option<&'s Path>,
3838

bobashare/public-api.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ pub bobashare::storage::file::FileBackend::path: std::path::PathBuf
513513
impl bobashare::storage::file::FileBackend
514514
pub async fn bobashare::storage::file::FileBackend::cleanup(&self) -> core::result::Result<(), bobashare::storage::file::CleanupError>
515515
impl bobashare::storage::file::FileBackend
516-
pub async fn bobashare::storage::file::FileBackend::create_upload<S: core::convert::AsRef<str>>(&self, id: S, filename: S, mimetype: mime::Mime, expiry: core::option::Option<chrono::Duration>, delete_key: core::option::Option<alloc::string::String>) -> core::result::Result<bobashare::storage::handle::UploadHandle, bobashare::storage::file::CreateUploadError>
516+
pub async fn bobashare::storage::file::FileBackend::create_upload<S: core::convert::AsRef<str>>(&self, id: S, filename: S, mimetype: mime::Mime, expiry: core::option::Option<chrono::time_delta::TimeDelta>, delete_key: core::option::Option<alloc::string::String>) -> core::result::Result<bobashare::storage::handle::UploadHandle, bobashare::storage::file::CreateUploadError>
517517
impl bobashare::storage::file::FileBackend
518518
pub async fn bobashare::storage::file::FileBackend::delete_upload<S: core::convert::AsRef<str>>(&self, id: S) -> core::result::Result<(), bobashare::storage::file::DeleteUploadError>
519519
impl bobashare::storage::file::FileBackend

bobashare/src/storage/file.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use std::path::PathBuf;
44

5-
use chrono::{prelude::*, Duration};
5+
use chrono::{prelude::*, TimeDelta};
66
use displaydoc::Display;
77
use mime::Mime;
88
use thiserror::Error;
@@ -97,7 +97,7 @@ impl FileBackend {
9797
id: S,
9898
filename: S,
9999
mimetype: Mime,
100-
expiry: Option<Duration>,
100+
expiry: Option<TimeDelta>,
101101
delete_key: Option<String>,
102102
) -> Result<UploadHandle, CreateUploadError> {
103103
let creation_date = Utc::now();

0 commit comments

Comments
 (0)