From cb757209d438afe23b5bdbfa5f62d00b195ad367 Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 1 May 2020 12:51:06 +0200 Subject: fix timestamp handling As it turns out, the "local timestamp" as advertised by arcdps is a bit misleading, because the timestamp is still in UTC. The "local" refers to the fact that it can lag behind the server timestamp a bit (but usually they seem to be within +-1 of each other), not that the timestamp is in the local timezone. This makes date handling a bit harder for raidgrep, but thanks to chrono, not by much. The idea is that we simply deal with Utc pretty much everywhere, except at the user boundary. This means that 1. Input timestamps for -before and -after are converted to Utc right after input 2. When outputting, we convert to a local timestamp first This makes the output consistent with the filenames now (and the "wall time" that the player saw). --- src/main.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index 712da94..b2b578d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,7 +7,7 @@ use std::path::PathBuf; use std::str::FromStr; use anyhow::{anyhow, Error, Result}; -use chrono::{NaiveDateTime, Weekday}; +use chrono::{DateTime, TimeZone, Utc, Weekday}; use colored::Colorize; use itertools::Itertools; use log::debug; @@ -122,7 +122,7 @@ pub struct LogResult { /// The path to the log file. log_file: PathBuf, /// The time of the recording. - time: NaiveDateTime, + time: DateTime, /// The numeric ID of the boss. boss_id: u16, /// The name of the boss. @@ -423,7 +423,7 @@ fn extract_info(entry: &DirEntry, log: &Log) -> LogResult { LogResult { log_file: entry.path().to_path_buf(), - time: NaiveDateTime::from_timestamp(i64::from(log.local_start_timestamp().unwrap_or(0)), 0), + time: Utc.timestamp(i64::from(log.local_start_timestamp().unwrap_or(0)), 0), boss_id: log.encounter_id(), boss_name, players, -- cgit v1.2.3