FIX: NOW shows now formatted output
This commit is contained in:
committed by
Nicolás Hatcher Andrés
parent
acf334074f
commit
dd78db3d2b
@@ -75,6 +75,7 @@ mod test_log;
|
|||||||
mod test_log10;
|
mod test_log10;
|
||||||
mod test_mod_quotient;
|
mod test_mod_quotient;
|
||||||
mod test_networkdays;
|
mod test_networkdays;
|
||||||
|
mod test_now;
|
||||||
mod test_percentage;
|
mod test_percentage;
|
||||||
mod test_set_functions_error_handling;
|
mod test_set_functions_error_handling;
|
||||||
mod test_sheet_names;
|
mod test_sheet_names;
|
||||||
|
|||||||
30
base/src/test/test_now.rs
Normal file
30
base/src/test/test_now.rs
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
#![allow(clippy::unwrap_used)]
|
||||||
|
|
||||||
|
use crate::{mock_time, test::util::new_empty_model};
|
||||||
|
|
||||||
|
// 14:44 20 Mar 2023 Berlin
|
||||||
|
const TIMESTAMP_2023: i64 = 1679319865208;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn arguments() {
|
||||||
|
let mut model = new_empty_model();
|
||||||
|
|
||||||
|
model._set("A1", "=NOW(1)");
|
||||||
|
model.evaluate();
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
model._get_text("A1"),
|
||||||
|
"#ERROR!",
|
||||||
|
"NOW should not accept arguments"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn returns_date_time() {
|
||||||
|
mock_time::set_mock_time(TIMESTAMP_2023);
|
||||||
|
let mut model = new_empty_model();
|
||||||
|
model._set("A1", "=NOW()");
|
||||||
|
model.evaluate();
|
||||||
|
let text = model._get_text("A1");
|
||||||
|
assert_eq!(text, *"20/03/2023 13:44:25");
|
||||||
|
}
|
||||||
@@ -33,7 +33,8 @@ fn now_basic_utc() {
|
|||||||
model.evaluate();
|
model.evaluate();
|
||||||
|
|
||||||
assert_eq!(model._get_text("A1"), *"20/03/2023");
|
assert_eq!(model._get_text("A1"), *"20/03/2023");
|
||||||
assert_eq!(model._get_text("A2"), *"45005.572511574");
|
// 45005.572511574
|
||||||
|
assert_eq!(model._get_text("A2"), *"20/03/2023 13:44:25");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -46,5 +47,5 @@ fn now_basic_europe_berlin() {
|
|||||||
|
|
||||||
assert_eq!(model._get_text("A1"), *"20/03/2023");
|
assert_eq!(model._get_text("A1"), *"20/03/2023");
|
||||||
// This is UTC + 1 hour: 45005.572511574 + 1/24
|
// This is UTC + 1 hour: 45005.572511574 + 1/24
|
||||||
assert_eq!(model._get_text("A2"), *"45005.614178241");
|
assert_eq!(model._get_text("A2"), *"20/03/2023 14:44:25");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -329,6 +329,7 @@ impl Model {
|
|||||||
Function::Tbillyield => self.units_fn_percentage_2(args, cell),
|
Function::Tbillyield => self.units_fn_percentage_2(args, cell),
|
||||||
Function::Date => self.units_fn_dates(args, cell),
|
Function::Date => self.units_fn_dates(args, cell),
|
||||||
Function::Today => self.units_fn_dates(args, cell),
|
Function::Today => self.units_fn_dates(args, cell),
|
||||||
|
Function::Now => self.units_fn_date_times(args, cell),
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -375,4 +376,8 @@ impl Model {
|
|||||||
// TODO: update locale and use it here
|
// TODO: update locale and use it here
|
||||||
Some(Units::Date("dd/mm/yyyy".to_string()))
|
Some(Units::Date("dd/mm/yyyy".to_string()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn units_fn_date_times(&self, _args: &[Node], _cell: &CellReferenceIndex) -> Option<Units> {
|
||||||
|
Some(Units::Date("dd/mm/yyyy hh:mm:ss".to_string()))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user