test everything in UTC-6 so time difference makes a difference

This commit is contained in:
Abraham Toriz 2021-08-11 17:54:37 -05:00
parent 98a43ea12f
commit 3a1ef47b21
7 changed files with 97 additions and 63 deletions

View File

@ -12,7 +12,7 @@ use crate::formatters::Formatter;
use crate::config::Config;
use crate::timeparse::parse_time;
use crate::regex::parse_regex;
use crate::old::{entries_or_warning, warn_if_needed};
use crate::old::{entries_or_warning, time_or_warning, warn_if_needed};
use super::Command;
@ -50,6 +50,9 @@ where
O: Write,
E: Write,
{
let start = start.map(|s| time_or_warning(s, db)).transpose()?.map(|s| s.0);
let end = end.map(|e| time_or_warning(e, db)).transpose()?.map(|e| e.0);
let mut entries = match sheet {
Some(Sheet::All) => db.entries_all_visible(start, end)?,
Some(Sheet::Full) => db.entries_full(start, end)?,
@ -136,7 +139,7 @@ mod tests {
#[test]
fn display_as_local_time_if_previous_version() {
std::env::set_var("TZ", "UTC");
std::env::set_var("TZ", "CST+6");
let args = Default::default();
let mut db = SqliteDatabase::from_path("assets/test_old_db.db").unwrap();
let mut out = Vec::new();
@ -179,7 +182,7 @@ mod tests {
DisplayCommand::handle(args, &mut db, &mut out, &mut err, &config, Utc::now()).unwrap();
assert_eq!(Ps(&String::from_utf8_lossy(&out)), Ps("start,end,note,sheet
2021-06-30T10:10:00Z,,hola,default
2021-06-30T10:10:00.000000Z,,hola,default
"));
assert_eq!(
@ -202,7 +205,7 @@ mod tests {
entries_for_display(None, None, None, &mut db, &mut out, &mut err, Formatter::Csv, true, Some("io".parse().unwrap()), Utc::now()).unwrap();
assert_eq!(Ps(&String::from_utf8_lossy(&out)), Ps("id,start,end,note,sheet
2,2021-06-30T10:10:00Z,,adios,default
2,2021-06-30T10:10:00.000000Z,,adios,default
"));
assert_eq!(
@ -221,7 +224,7 @@ mod tests {
let mut out = Vec::new();
let mut err = Vec::new();
let config = Default::default();
std::env::set_var("TZ", "UTC");
std::env::set_var("TZ", "CST+6");
db.init().unwrap();
@ -233,15 +236,15 @@ mod tests {
assert_eq!(Ps(&String::from_utf8_lossy(&out)), Ps("Timesheet: sheet1
Day Start End Duration Notes
Wed Jun 30, 2021 10:00:00 - 11:00:00 1:00:00
12:00:00 - 13:00:00 1:00:00
Wed Jun 30, 2021 04:00:00 - 05:00:00 1:00:00
06:00:00 - 07:00:00 1:00:00
2:00:00
-----------------------------------------------------------
Total 2:00:00
Timesheet: sheet2
Day Start End Duration Notes
Wed Jun 30, 2021 11:00:00 - 12:00:00 1:00:00
Wed Jun 30, 2021 05:00:00 - 06:00:00 1:00:00
1:00:00
-----------------------------------------------------------
Total 1:00:00
@ -260,7 +263,7 @@ Timesheet: sheet2
let mut out = Vec::new();
let mut err = Vec::new();
let config = Default::default();
std::env::set_var("TZ", "UTC");
std::env::set_var("TZ", "CST+6");
db.init().unwrap();
@ -273,15 +276,15 @@ Timesheet: sheet2
assert_eq!(Ps(&String::from_utf8_lossy(&out)), Ps("\
Timesheet: _sheet2
Day Start End Duration Notes
Wed Jun 30, 2021 11:00:00 - 12:00:00 1:00:00
Wed Jun 30, 2021 05:00:00 - 06:00:00 1:00:00
1:00:00
-----------------------------------------------------------
Total 1:00:00
Timesheet: sheet1
Day Start End Duration Notes
Wed Jun 30, 2021 10:00:00 - 11:00:00 1:00:00
12:00:00 - 13:00:00 1:00:00
Wed Jun 30, 2021 04:00:00 - 05:00:00 1:00:00
06:00:00 - 07:00:00 1:00:00
2:00:00
-----------------------------------------------------------
Total 2:00:00
@ -289,4 +292,35 @@ Timesheet: sheet1
Grand total 3:00:00
"));
}
#[test]
fn filter_old_database() {
std::env::set_var("TZ", "CST+6");
let args = Args {
format: Formatter::Csv,
start: Some(Utc.ymd(2021, 6, 29).and_hms(12, 0, 0)),
end: Some(Utc.ymd(2021, 6, 29).and_hms(13, 0, 0)),
..Default::default()
};
let mut db = SqliteDatabase::from_path("assets/test_old_db.db").unwrap();
let mut out = Vec::new();
let mut err = Vec::new();
let config = Default::default();
// item in database:
// start: 2021-06-29 06:26:49.580565
// end: 2021-06-29 07:26:52.816747
DisplayCommand::handle(args, &mut db, &mut out, &mut err, &config, Utc::now()).unwrap();
assert_eq!(Ps(&String::from_utf8_lossy(&out)), Ps("start,end,note,sheet
2021-06-29T12:26:49.580565Z,2021-06-29T13:26:52.816747Z,lets do some rust,default
"));
assert_eq!(
String::from_utf8_lossy(&err),
format!("{} You are using the old timetrap format, it is advised that you update your database using t migrate\n", Yellow.bold().paint("[WARNING]")),
);
}
}

View File

@ -136,7 +136,7 @@ mod tests {
#[test]
fn edit_last_note() {
std::env::set_var("TZ", "UTC");
std::env::set_var("TZ", "CST+6");
let mut db = SqliteDatabase::from_memory().unwrap();
let mut out = Vec::new();
let mut err = Vec::new();
@ -160,7 +160,7 @@ mod tests {
assert_eq!(Ps(&String::from_utf8_lossy(&out)), Ps("Timesheet: default
ID Day Start End Duration Notes
1 Tue Aug 03, 2021 19:29:00 - 20:29:00 1:00:00 new note
1 Tue Aug 03, 2021 13:29:00 - 14:29:00 1:00:00 new note
1:00:00
--------------------------------------------------------------
Total 1:00:00
@ -170,7 +170,7 @@ mod tests {
#[test]
fn edit_with_id() {
std::env::set_var("TZ", "UTC");
std::env::set_var("TZ", "CST+6");
let mut db = SqliteDatabase::from_memory().unwrap();
let mut out = Vec::new();
@ -192,7 +192,7 @@ mod tests {
assert_eq!(Ps(&String::from_utf8_lossy(&out)), Ps("Timesheet: sheet1
ID Day Start End Duration Notes
2 Tue Aug 03, 2021 19:29:00 - 20:29:00 1:00:00 new note
2 Tue Aug 03, 2021 13:29:00 - 14:29:00 1:00:00 new note
1:00:00
--------------------------------------------------------------
Total 1:00:00
@ -202,7 +202,7 @@ mod tests {
#[test]
fn edit_start() {
std::env::set_var("TZ", "UTC");
std::env::set_var("TZ", "CST+6");
let mut db = SqliteDatabase::from_memory().unwrap();
let mut out = Vec::new();
let mut err = Vec::new();
@ -221,7 +221,7 @@ mod tests {
assert_eq!(Ps(&String::from_utf8_lossy(&out)), Ps("Timesheet: default
ID Day Start End Duration Notes
1 Tue Aug 03, 2021 19:59:00 - 20:29:00 0:30:00 a note
1 Tue Aug 03, 2021 13:59:00 - 14:29:00 0:30:00 a note
0:30:00
------------------------------------------------------------
Total 0:30:00
@ -231,7 +231,7 @@ mod tests {
#[test]
fn edit_end() {
std::env::set_var("TZ", "UTC");
std::env::set_var("TZ", "CST+6");
let mut db = SqliteDatabase::from_memory().unwrap();
let mut out = Vec::new();
let mut err = Vec::new();
@ -250,7 +250,7 @@ mod tests {
assert_eq!(Ps(&String::from_utf8_lossy(&out)), Ps("Timesheet: default
ID Day Start End Duration Notes
1 Tue Aug 03, 2021 19:29:00 - 19:59:00 0:30:00 a note
1 Tue Aug 03, 2021 13:29:00 - 13:59:00 0:30:00 a note
0:30:00
------------------------------------------------------------
Total 0:30:00
@ -260,7 +260,7 @@ mod tests {
#[test]
fn edit_append() {
std::env::set_var("TZ", "UTC");
std::env::set_var("TZ", "CST+6");
let mut db = SqliteDatabase::from_memory().unwrap();
let mut out = Vec::new();
let mut err = Vec::new();
@ -280,7 +280,7 @@ mod tests {
assert_eq!(Ps(&String::from_utf8_lossy(&out)), Ps("Timesheet: default
ID Day Start End Duration Notes
1 Tue Aug 03, 2021 19:29:00 - 20:29:00 1:00:00 a note new note
1 Tue Aug 03, 2021 13:29:00 - 14:29:00 1:00:00 a note new note
1:00:00
---------------------------------------------------------------------
Total 1:00:00
@ -290,7 +290,7 @@ mod tests {
#[test]
fn edit_move() {
std::env::set_var("TZ", "UTC");
std::env::set_var("TZ", "CST+6");
let mut db = SqliteDatabase::from_memory().unwrap();
let mut out = Vec::new();
let mut err = Vec::new();
@ -309,7 +309,7 @@ mod tests {
assert_eq!(Ps(&String::from_utf8_lossy(&out)), Ps("Timesheet: new sheet
ID Day Start End Duration Notes
1 Tue Aug 03, 2021 19:29:00 - 20:29:00 1:00:00 a note
1 Tue Aug 03, 2021 13:29:00 - 14:29:00 1:00:00 a note
1:00:00
------------------------------------------------------------
Total 1:00:00
@ -319,7 +319,7 @@ mod tests {
#[test]
fn non_default_delimiter() {
std::env::set_var("TZ", "UTC");
std::env::set_var("TZ", "CST+6");
let mut db = SqliteDatabase::from_memory().unwrap();
let mut out = Vec::new();
@ -344,7 +344,7 @@ mod tests {
assert_eq!(Ps(&String::from_utf8_lossy(&out)), Ps("Timesheet: default
ID Day Start End Duration Notes
1 Tue Aug 03, 2021 19:29:00 - 20:29:00 1:00:00 a note;new note
1 Tue Aug 03, 2021 13:29:00 - 14:29:00 1:00:00 a note;new note
1:00:00
---------------------------------------------------------------------
Total 1:00:00
@ -362,14 +362,14 @@ mod tests {
#[test]
fn warn_old() {
std::env::set_var("TZ", "UTC");
std::env::set_var("TZ", "CST+6");
let database_file = copy_db("assets/test_old_db.db");
let mut db = SqliteDatabase::from_path(&database_file).unwrap();
let mut out = Vec::new();
let mut err = Vec::new();
let now = Utc.ymd(2021, 8, 3).and_hms(20, 29, 0);
let new_end = Utc.ymd(2021, 06, 29).and_hms(8, 26, 52);
let new_end = Utc.ymd(2021, 06, 29).and_hms(14, 26, 52);
let args = Args {
end: Some(new_end),
..Default::default()

View File

@ -142,7 +142,7 @@ mod tests {
#[test]
fn list_sheets() {
std::env::set_var("TZ", "UTC");
std::env::set_var("TZ", "CST+6");
let args = Default::default();
let mut db = SqliteDatabase::from_memory().unwrap();

View File

@ -96,7 +96,7 @@ mod tests {
#[test]
fn list_sheets() {
std::env::set_var("TZ", "UTC");
std::env::set_var("TZ", "CST+6");
let mut db = SqliteDatabase::from_memory().unwrap();
let mut out = Vec::new();

View File

@ -88,7 +88,7 @@ mod tests {
assert_eq!(Ps(&String::from_utf8_lossy(&out)), Ps(&format!("start,end,note,sheet
{},,This!,default
", yesterday.and_hms(1, 2, 3).with_timezone(&Utc).to_rfc3339_opts(chrono::SecondsFormat::Secs, true))));
", yesterday.and_hms(1, 2, 3).with_timezone(&Utc).to_rfc3339_opts(chrono::SecondsFormat::Micros, true))));
assert_eq!(
String::from_utf8_lossy(&err),

View File

@ -19,15 +19,15 @@ pub fn print_formatted<W: Write>(entries: Vec<Entry>, out: &mut W, ids: bool) ->
if ids {
wtr.write_record(&[
entry.id.to_string(),
entry.start.to_rfc3339_opts(SecondsFormat::Secs, true),
entry.end.map(|t| t.to_rfc3339_opts(SecondsFormat::Secs, true)).unwrap_or_else(|| "".into()),
entry.start.to_rfc3339_opts(SecondsFormat::Micros, true),
entry.end.map(|t| t.to_rfc3339_opts(SecondsFormat::Micros, true)).unwrap_or_else(|| "".into()),
entry.note.unwrap_or_else(|| "".into()),
entry.sheet,
])?;
} else {
wtr.write_record(&[
entry.start.to_rfc3339_opts(SecondsFormat::Secs, true),
entry.end.map(|t| t.to_rfc3339_opts(SecondsFormat::Secs, true)).unwrap_or_else(|| "".into()),
entry.start.to_rfc3339_opts(SecondsFormat::Micros, true),
entry.end.map(|t| t.to_rfc3339_opts(SecondsFormat::Micros, true)).unwrap_or_else(|| "".into()),
entry.note.unwrap_or_else(|| "".into()),
entry.sheet,
])?;
@ -56,8 +56,8 @@ mod tests {
print_formatted(entries, &mut out, false).unwrap();
assert_eq!(Ps(&String::from_utf8_lossy(&out)), Ps("start,end,note,sheet
2021-06-30T18:12:34Z,2021-06-30T19:00:00Z,entry 1,default
2021-06-30T18:12:34Z,,entry 2,default
2021-06-30T18:12:34.000000Z,2021-06-30T19:00:00.000000Z,entry 1,default
2021-06-30T18:12:34.000000Z,,entry 2,default
"));
}
@ -72,8 +72,8 @@ mod tests {
print_formatted(entries, &mut out, true).unwrap();
assert_eq!(Ps(&String::from_utf8_lossy(&out)), Ps("id,start,end,note,sheet
1,2021-06-30T18:12:34Z,2021-06-30T19:00:00Z,entry 1,default
2,2021-06-30T18:12:34Z,,entry 2,default
1,2021-06-30T18:12:34.000000Z,2021-06-30T19:00:00.000000Z,entry 1,default
2,2021-06-30T18:12:34.000000Z,,entry 2,default
"));
}
}

View File

@ -141,7 +141,7 @@ mod tests {
#[test]
fn test_text_output() {
std::env::set_var("TZ", "UTC");
std::env::set_var("TZ", "CST+6");
let mut output = Vec::new();
let entries = vec![
Entry::new_sample(1, Utc.ymd(2008, 10, 3).and_hms(12, 0, 0), Some(Utc.ymd(2008, 10, 3).and_hms(14, 0, 0))),
@ -156,11 +156,11 @@ mod tests {
assert_eq!(Ps(&String::from_utf8_lossy(&output)), Ps("Timesheet: default
Day Start End Duration Notes
Fri Oct 03, 2008 12:00:00 - 14:00:00 2:00:00 entry 1
16:00:00 - 18:00:00 2:00:00 entry 2
Fri Oct 03, 2008 06:00:00 - 08:00:00 2:00:00 entry 1
10:00:00 - 12:00:00 2:00:00 entry 2
4:00:00
Sun Oct 05, 2008 16:00:00 - 18:00:00 2:00:00 entry 3
18:00:00 - 2:00:00 entry 4
Sun Oct 05, 2008 10:00:00 - 12:00:00 2:00:00 entry 3
12:00:00 - 2:00:00 entry 4
4:00:00
-------------------------------------------------------------
Total 8:00:00
@ -169,7 +169,7 @@ mod tests {
#[test]
fn test_text_output_with_millis() {
std::env::set_var("TZ", "UTC");
std::env::set_var("TZ", "CST+6");
let mut output = Vec::new();
let entries = vec![
Entry::new_sample(1, Utc.ymd(2008, 10, 3).and_hms_milli(12, 0, 0, 432), Some(Utc.ymd(2008, 10, 3).and_hms_milli(14, 0, 0, 312))),
@ -181,7 +181,7 @@ mod tests {
assert_eq!(Ps(&String::from_utf8_lossy(&output)), Ps("Timesheet: default
Day Start End Duration Notes
Fri Oct 03, 2008 12:00:00 - 14:00:00 1:59:59 entry 1
Fri Oct 03, 2008 06:00:00 - 08:00:00 1:59:59 entry 1
1:59:59
-------------------------------------------------------------
Total 1:59:59
@ -190,7 +190,7 @@ mod tests {
#[test]
fn test_text_output_long_duration() {
std::env::set_var("TZ", "UTC");
std::env::set_var("TZ", "CST+6");
let mut output = Vec::new();
let entries = vec![
Entry::new_sample(1, Utc.ymd(2008, 10, 1).and_hms(12, 0, 0), Some(Utc.ymd(2008, 10, 3).and_hms(14, 0, 0))),
@ -203,9 +203,9 @@ mod tests {
assert_eq!(Ps(&String::from_utf8_lossy(&output)), Ps("Timesheet: default
Day Start End Duration Notes
Wed Oct 01, 2008 12:00:00 - 14:00:00+2d 50:00:00 entry 1
Wed Oct 01, 2008 06:00:00 - 08:00:00+2d 50:00:00 entry 1
50:00:00
Fri Oct 03, 2008 12:00:00 - 14:00:00 2:00:00 entry 2
Fri Oct 03, 2008 06:00:00 - 08:00:00 2:00:00 entry 2
2:00:00
--------------------------------------------------------------
Total 52:00:00
@ -214,7 +214,7 @@ mod tests {
#[test]
fn test_text_output_with_ids() {
std::env::set_var("TZ", "UTC");
std::env::set_var("TZ", "CST+6");
let mut output = Vec::new();
let entries = vec![
Entry::new_sample(1, Utc.ymd(2008, 10, 3).and_hms(12, 0, 0), Some(Utc.ymd(2008, 10, 3).and_hms(14, 0, 0))),
@ -229,11 +229,11 @@ mod tests {
assert_eq!(Ps(&String::from_utf8_lossy(&output)), Ps("Timesheet: default
ID Day Start End Duration Notes
1 Fri Oct 03, 2008 12:00:00 - 14:00:00 2:00:00 entry 1
2 16:00:00 - 18:00:00 2:00:00 entry 2
1 Fri Oct 03, 2008 06:00:00 - 08:00:00 2:00:00 entry 1
2 10:00:00 - 12:00:00 2:00:00 entry 2
4:00:00
3 Sun Oct 05, 2008 16:00:00 - 18:00:00 2:00:00 entry 3
4 18:00:00 - 2:00:00 entry 4
3 Sun Oct 05, 2008 10:00:00 - 12:00:00 2:00:00 entry 3
4 12:00:00 - 2:00:00 entry 4
4:00:00
-------------------------------------------------------------
Total 8:00:00
@ -242,7 +242,7 @@ mod tests {
#[test]
fn test_text_output_long_note_with_ids() {
std::env::set_var("TZ", "UTC");
std::env::set_var("TZ", "CST+6");
let mut output = Vec::new();
let entries = vec![
Entry {
@ -260,7 +260,7 @@ mod tests {
assert_eq!(Ps(&String::from_utf8_lossy(&output)), Ps("Timesheet: default
ID Day Start End Duration Notes
60000 Sun Oct 05, 2008 16:00:00 - 18:00:00 2:00:00 chatting with bob about upcoming task,
60000 Sun Oct 05, 2008 10:00:00 - 12:00:00 2:00:00 chatting with bob about upcoming task,
district sharing of images, how the user
settings currently works etc. Discussing the
fingerprinting / cache busting issue with
@ -276,7 +276,7 @@ mod tests {
#[test]
fn test_text_output_note_with_line_breaks() {
std::env::set_var("TZ", "UTC");
std::env::set_var("TZ", "CST+6");
let mut output = Vec::new();
let entries = vec![
Entry {
@ -294,7 +294,7 @@ mod tests {
assert_eq!(Ps(&String::from_utf8_lossy(&output)), Ps("Timesheet: default
Day Start End Duration Notes
Sun Oct 05, 2008 16:00:00 - 18:00:00 2:00:00 first line
Sun Oct 05, 2008 10:00:00 - 12:00:00 2:00:00 first line
and a second line
2:00:00
-----------------------------------------------------------------------
@ -304,7 +304,7 @@ mod tests {
#[test]
fn note_with_accents() {
std::env::set_var("TZ", "UTC");
std::env::set_var("TZ", "CST+6");
let mut output = Vec::new();
let entries = vec![
Entry {
@ -322,7 +322,7 @@ mod tests {
assert_eq!(Ps(&String::from_utf8_lossy(&output)), Ps("Timesheet: default
Day Start End Duration Notes
Sun Oct 05, 2008 16:00:00 - 18:00:00 2:00:00 quiúbole
Sun Oct 05, 2008 10:00:00 - 12:00:00 2:00:00 quiúbole
2:00:00
--------------------------------------------------------------
Total 2:00:00
@ -331,7 +331,7 @@ mod tests {
#[test]
fn displays_grand_total_when_multiple_sheets() {
std::env::set_var("TZ", "UTC");
std::env::set_var("TZ", "CST+6");
let mut output = Vec::new();
let entries = vec![
@ -357,14 +357,14 @@ mod tests {
assert_eq!(Ps(&String::from_utf8_lossy(&output)), Ps("Timesheet: sheet1
Day Start End Duration Notes
Sun Oct 05, 2008 16:00:00 - 18:00:00 2:00:00 quiúbole
Sun Oct 05, 2008 10:00:00 - 12:00:00 2:00:00 quiúbole
2:00:00
--------------------------------------------------------------
Total 2:00:00
Timesheet: sheet2
Day Start End Duration Notes
Sun Oct 05, 2008 16:00:00 - 18:00:00 2:00:00 quiúbole
Sun Oct 05, 2008 10:00:00 - 12:00:00 2:00:00 quiúbole
2:00:00
--------------------------------------------------------------
Total 2:00:00