aboutsummaryrefslogtreecommitdiffstats
path: root/atuin-common/src/utils.rs
diff options
context:
space:
mode:
Diffstat (limited to 'atuin-common/src/utils.rs')
-rw-r--r--atuin-common/src/utils.rs17
1 files changed, 17 insertions, 0 deletions
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::*;