Add DiaryId::now(name) to create DiaryId at current time
This commit is contained in:
parent
857daa1c99
commit
de9d933a6b
1 changed files with 11 additions and 0 deletions
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue