From: Mira Limbeck <m.limbeck@proxmox.com>
To: pmg-devel@lists.proxmox.com
Subject: [pmg-devel] [PATCH log-tracker 1/2] add compatibility with API/Tracking Center
Date: Wed, 28 Jun 2023 10:54:28 +0200 [thread overview]
Message-ID: <20230628085429.324086-1-m.limbeck@proxmox.com> (raw)
The API assumes the timestamps to be in the local timezone rather than
UTC. It then subtracts the timezone offset leading to wrong values when
timestamps are in UTC, but timezone is not.
For compatibility, add the local timezone to those timestamps.
Signed-off-by: Mira Limbeck <m.limbeck@proxmox.com>
---
src/main.rs | 43 ++++++++++++++++++++++++++++++++-----------
1 file changed, 32 insertions(+), 11 deletions(-)
diff --git a/src/main.rs b/src/main.rs
index e7bffd8..e55f17b 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1737,6 +1737,8 @@ struct Parser {
string_match: bool,
lines: u64,
+
+ timezone_offset: time_t,
}
impl Parser {
@@ -1762,6 +1764,7 @@ impl Parser {
ctime: 0,
string_match: false,
lines: 0,
+ timezone_offset: ltime.tm_gmtoff,
})
}
@@ -1836,7 +1839,12 @@ impl Parser {
let line = &buffer[0..size - 1];
let complete_line = line;
- let (time, line) = match parse_time(line, self.current_year, self.current_month) {
+ let (time, line) = match parse_time(
+ line,
+ self.current_year,
+ self.current_month,
+ self.timezone_offset,
+ ) {
Some(t) => t,
None => continue,
};
@@ -1920,9 +1928,12 @@ impl Parser {
if size == 0 {
return count;
}
- if let Some((time, _)) =
- parse_time(&buffer[0..size], self.current_year, self.current_month)
- {
+ if let Some((time, _)) = parse_time(
+ &buffer[0..size],
+ self.current_year,
+ self.current_month,
+ self.timezone_offset,
+ ) {
// found the earliest file in the time frame
if time < self.options.start {
break;
@@ -1937,9 +1948,12 @@ impl Parser {
if size == 0 {
return count;
}
- if let Some((time, _)) =
- parse_time(&buffer[0..size], self.current_year, self.current_month)
- {
+ if let Some((time, _)) = parse_time(
+ &buffer[0..size],
+ self.current_year,
+ self.current_month,
+ self.timezone_offset,
+ ) {
if time < self.options.start {
break;
}
@@ -2235,11 +2249,17 @@ fn parse_number(data: &[u8], max_digits: usize) -> Option<(usize, &[u8])> {
}
/// Parse time. Returns a tuple of (parsed_time, remaining_text) or None.
-fn parse_time(data: &'_ [u8], cur_year: i64, cur_month: i64) -> Option<(time_t, &'_ [u8])> {
- parse_time_with_year(data).or_else(|| parse_time_no_year(data, cur_year, cur_month))
+fn parse_time(
+ data: &'_ [u8],
+ cur_year: i64,
+ cur_month: i64,
+ timezone_offset: time_t,
+) -> Option<(time_t, &'_ [u8])> {
+ parse_time_with_year(data, timezone_offset)
+ .or_else(|| parse_time_no_year(data, cur_year, cur_month))
}
-fn parse_time_with_year(data: &'_ [u8]) -> Option<(time_t, &'_ [u8])> {
+fn parse_time_with_year(data: &'_ [u8], timezone_offset: time_t) -> Option<(time_t, &'_ [u8])> {
let mut timestamp_buffer = [0u8; 25];
let count = data.iter().take_while(|b| **b != b' ').count();
@@ -2266,7 +2286,8 @@ fn parse_time_with_year(data: &'_ [u8]) -> Option<(time_t, &'_ [u8])> {
match proxmox_time::parse_rfc3339(unsafe {
std::str::from_utf8_unchecked(×tamp_buffer[0..timestamp_len])
}) {
- Ok(ltime) => Some((ltime, data)),
+ // TODO handle timezone offset in old code path instead
+ Ok(ltime) => Some((ltime + timezone_offset, data)),
Err(_err) => None,
}
}
--
2.30.2
next reply other threads:[~2023-06-28 8:54 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-28 8:54 Mira Limbeck [this message]
2023-06-28 8:54 ` [pmg-devel] [PATCH log-tracker 2/2] tests: update to match the compatibility changes Mira Limbeck
2023-06-28 9:38 ` [pmg-devel] [PATCH log-tracker 1/2] add compatibility with API/Tracking Center Dominik Csapak
2023-06-28 10:06 ` [pmg-devel] applied-series: " Stoiko Ivanov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230628085429.324086-1-m.limbeck@proxmox.com \
--to=m.limbeck@proxmox.com \
--cc=pmg-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox