Add offset parameter to date extension. Fix #311
This commit is contained in:
parent
a2a73efe74
commit
537e1360bb
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
* This file is part of espanso.
|
||||
*
|
||||
* Copyright (C) 2019 Federico Terzi
|
||||
* Copyright (C) 2019-2020 Federico Terzi
|
||||
*
|
||||
* espanso is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -17,7 +17,7 @@
|
|||
* along with espanso. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
use chrono::{DateTime, Local};
|
||||
use chrono::{DateTime, Local, Duration};
|
||||
use serde_yaml::{Mapping, Value};
|
||||
use std::collections::HashMap;
|
||||
use crate::extension::ExtensionResult;
|
||||
|
@ -36,7 +36,15 @@ impl super::Extension for DateExtension {
|
|||
}
|
||||
|
||||
fn calculate(&self, params: &Mapping, _: &Vec<String>, _: &HashMap<String, ExtensionResult>) -> Option<ExtensionResult> {
|
||||
let now: DateTime<Local> = Local::now();
|
||||
let mut now: DateTime<Local> = Local::now();
|
||||
|
||||
// Compute the given offset
|
||||
let offset = params.get(&Value::from("offset"));
|
||||
if let Some(offset) = offset {
|
||||
let seconds = offset.as_i64().unwrap_or_else(|| { 0 });
|
||||
let offset = Duration::seconds(seconds);
|
||||
now = now + offset;
|
||||
}
|
||||
|
||||
let format = params.get(&Value::from("format"));
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user