From de9d933a6be6997aea00cb54d2aafcc233bd5f94 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Wed, 8 Jun 2016 13:57:35 +0200 Subject: [PATCH] Add DiaryId::now(name) to create DiaryId at current time --- libimagdiary/src/diaryid.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/libimagdiary/src/diaryid.rs b/libimagdiary/src/diaryid.rs index 9393a1ed..fb9c0c34 100644 --- a/libimagdiary/src/diaryid.rs +++ b/libimagdiary/src/diaryid.rs @@ -92,6 +92,17 @@ impl DiaryId { self } + pub fn now(name: String) -> DiaryId { + use chrono::offset::local::Local; + + let now = Local::now(); + let now_date = now.date().naive_local(); + let now_time = now.time(); + let dt = NaiveDateTime::new(now_date, now_time); + + DiaryId::new(name, dt.year(), dt.month(), dt.day(), dt.hour(), dt.minute()) + } + } impl Default for DiaryId {