diff options
| author | Ellie Huxtable <ellie@elliehuxtable.com> | 2022-04-13 18:29:18 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-04-13 18:29:18 +0100 |
| commit | f4240aa62b47850020aa8c3e164d6d3544626f53 (patch) | |
| tree | 4a68f85825fe2d1b82e277730f7c270b5049e639 /atuin-common | |
| parent | provide better error messages (#300) (diff) | |
| download | atuin-f4240aa62b47850020aa8c3e164d6d3544626f53.zip | |
Initial implementation of calendar API (#298)
This can be used in the future for sync so that we can be more
intelligent with what we're doing, and only sync up what's needed
I'd like to eventually replace this with something more like a merkle
tree, hence the hash field I've exposed, but that can come later
Although this does include a much larger number of count queries, it
should also be significantly more cache-able. I'll follow up with that
later, and also follow up with using this for sync :)
Diffstat (limited to 'atuin-common')
| -rw-r--r-- | atuin-common/src/calendar.rs | 15 | ||||
| -rw-r--r-- | atuin-common/src/utils.rs | 17 |
2 files changed, 32 insertions, 0 deletions
diff --git a/atuin-common/src/calendar.rs b/atuin-common/src/calendar.rs new file mode 100644 index 00000000..d576f1a7 --- /dev/null +++ b/atuin-common/src/calendar.rs @@ -0,0 +1,15 @@ +// Calendar data + +pub enum TimePeriod { + YEAR, + MONTH, + DAY, +} + +#[derive(Debug, Serialize, Deserialize)] +pub struct TimePeriodInfo { + pub count: u64, + + // TODO: Use this for merkle tree magic + pub hash: String, +} diff --git a/atuin-common/src/utils.rs b/atuin-common/src/utils.rs index 7fe0c300..35647bd4 100644 --- a/atuin-common/src/utils.rs +++ b/atuin-common/src/utils.rs @@ -1,5 +1,6 @@ use std::path::PathBuf; +use chrono::NaiveDate; use crypto::digest::Digest; use crypto::sha2::Sha256; use sodiumoxide::crypto::pwhash::argon2id13; @@ -51,6 +52,22 @@ pub fn data_dir() -> PathBuf { data_dir.join("atuin") } +pub fn get_days_from_month(year: i32, month: u32) -> i64 { + NaiveDate::from_ymd( + match month { + 12 => year + 1, + _ => year, + }, + match month { + 12 => 1, + _ => month + 1, + }, + 1, + ) + .signed_duration_since(NaiveDate::from_ymd(year, month, 1)) + .num_days() +} + #[cfg(test)] mod tests { use super::*; |
