aboutsummaryrefslogtreecommitdiffstats
path: root/atuin-common/src
diff options
context:
space:
mode:
Diffstat (limited to 'atuin-common/src')
-rw-r--r--atuin-common/src/calendar.rs15
-rw-r--r--atuin-common/src/utils.rs17
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::*;