diff options
author | Alex Auvolat <alex@adnab.me> | 2023-08-30 20:02:07 +0200 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2023-08-30 20:02:07 +0200 |
commit | 75ccc5a95c76f31235fcaab8a2c1795693733a4b (patch) | |
tree | 2309b19d04875d991bffdad93cdb050c7477123e /src/model/bucket_table.rs | |
parent | 7200954318a1b248b4194ee9273bcd2502b50d58 (diff) | |
download | garage-75ccc5a95c76f31235fcaab8a2c1795693733a4b.tar.gz garage-75ccc5a95c76f31235fcaab8a2c1795693733a4b.zip |
lifecycle config: store date as given, try to debug
Diffstat (limited to 'src/model/bucket_table.rs')
-rw-r--r-- | src/model/bucket_table.rs | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/src/model/bucket_table.rs b/src/model/bucket_table.rs index e9d574c5..df2e9b4a 100644 --- a/src/model/bucket_table.rs +++ b/src/model/bucket_table.rs @@ -105,7 +105,7 @@ mod v08 { /// Objects expire x days after they were created AfterDays(usize), /// Objects expire at date x (must be in yyyy-mm-dd format) - AtDate(chrono::naive::NaiveDate), + AtDate(String), } #[derive(Default, PartialEq, Eq, PartialOrd, Ord, Clone, Debug, Serialize, Deserialize)] @@ -155,6 +155,20 @@ impl Crdt for BucketParams { } } +pub fn parse_lifecycle_date(date: &str) -> Result<chrono::NaiveDate, &'static str> { + use chrono::prelude::*; + + if let Ok(datetime) = NaiveDateTime::parse_from_str(date, "%Y-%m-%dT%H:%M:%SZ") { + if datetime.time() == NaiveTime::MIN { + Ok(datetime.date()) + } else { + Err("date must be at midnight") + } + } else { + NaiveDate::parse_from_str(date, "%Y-%m-%d").map_err(|_| "date has invalid format") + } +} + impl Default for Bucket { fn default() -> Self { Self::new() |