use std::io::BufWriter;
use std::io::Write;
-use anyhow::{bail, Error};
+use anyhow::{bail, Context, Error};
use flate2::read;
use libc::time_t;
println!(
"# Start: {} ({})",
- time::strftime(c_str!("%F %T"), &parser.start_tm)?,
+ proxmox_time::strftime_local("%F %T", parser.options.start)?,
parser.options.start
);
println!(
"# End: {} ({})",
- time::strftime(c_str!("%F %T"), &parser.end_tm)?,
+ proxmox_time::strftime_local("%F %T", parser.options.end)?,
parser.options.end
);
string_match: bool,
lines: u64,
-
- timezone_offset: time_t,
}
impl Parser {
ctime: 0,
string_match: false,
lines: 0,
- timezone_offset: ltime.tm_gmtoff,
})
}
line,
self.current_year,
self.current_month,
- self.timezone_offset,
+ // use start time for timezone offset in parse_time_no_year rather than the
+ // timezone offset of the current time
+ // this is required for cases where current time is in standard time, while start
+ // time is in summer time or the other way around
+ self.start_tm.tm_gmtoff,
) {
Some(t) => t,
None => continue,
&buffer[0..size],
self.current_year,
self.current_month,
- self.timezone_offset,
+ self.start_tm.tm_gmtoff,
) {
// found the earliest file in the time frame
if time < self.options.start {
&buffer[0..size],
self.current_year,
self.current_month,
- self.timezone_offset,
+ self.start_tm.tm_gmtoff,
) {
if time < self.options.start {
break;
}
if let Some(start) = args.opt_value_from_str::<_, String>(["-s", "--starttime"])? {
- if let Ok(res) = time::strptime(&start, c_str!("%F %T")) {
- self.options.start = res.as_utc_to_epoch();
- self.start_tm = res;
- } else if let Ok(res) = time::strptime(&start, c_str!("%s")) {
- self.options.start = res.as_utc_to_epoch();
- self.start_tm = res;
+ if let Ok(epoch) = proxmox_time::parse_rfc3339(&start).or_else(|_| {
+ time::date_to_rfc3339(&start).and_then(|s| proxmox_time::parse_rfc3339(&s))
+ }) {
+ self.options.start = epoch;
+ self.start_tm = time::Tm::at_local(epoch).context("failed to parse start time")?;
+ } else if let Ok(epoch) = start.parse::<time_t>() {
+ self.options.start = epoch;
+ self.start_tm = time::Tm::at_local(epoch).context("failed to parse start time")?;
} else {
bail!("failed to parse start time");
}
}
if let Some(end) = args.opt_value_from_str::<_, String>(["-e", "--endtime"])? {
- if let Ok(res) = time::strptime(&end, c_str!("%F %T")) {
- self.options.end = res.as_utc_to_epoch();
- self.end_tm = res;
- } else if let Ok(res) = time::strptime(&end, c_str!("%s")) {
- self.options.end = res.as_utc_to_epoch();
- self.end_tm = res;
+ if let Ok(epoch) = proxmox_time::parse_rfc3339(&end).or_else(|_| {
+ time::date_to_rfc3339(&end).and_then(|s| proxmox_time::parse_rfc3339(&s))
+ }) {
+ self.options.end = epoch;
+ self.end_tm = time::Tm::at_local(epoch).context("failed to parse end time")?;
+ } else if let Ok(epoch) = end.parse::<time_t>() {
+ self.options.end = epoch;
+ self.end_tm = time::Tm::at_local(epoch).context("failed to parse end time")?;
} else {
bail!("failed to parse end time");
}
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))
+ parse_time_with_year(data)
+ .or_else(|| parse_time_no_year(data, cur_year, cur_month, timezone_offset))
}
-fn parse_time_with_year(data: &'_ [u8], timezone_offset: time_t) -> Option<(time_t, &'_ [u8])> {
+fn parse_time_with_year(data: &'_ [u8]) -> Option<(time_t, &'_ [u8])> {
let mut timestamp_buffer = [0u8; 25];
let count = data.iter().take_while(|b| **b != b' ').count();
match proxmox_time::parse_rfc3339(unsafe {
std::str::from_utf8_unchecked(×tamp_buffer[0..timestamp_len])
}) {
- // TODO handle timezone offset in old code path instead
- Ok(ltime) => Some((ltime + timezone_offset, data)),
+ Ok(ltime) => Some((ltime, data)),
Err(_err) => None,
}
}
-fn parse_time_no_year(data: &'_ [u8], cur_year: i64, cur_month: i64) -> Option<(time_t, &'_ [u8])> {
+fn parse_time_no_year(
+ data: &'_ [u8],
+ cur_year: i64,
+ cur_month: i64,
+ timezone_offset: time_t,
+) -> Option<(time_t, &'_ [u8])> {
if data.len() < 15 {
return None;
}
_ => &data[1..],
};
- Some((ltime, data))
+ Some((ltime - timezone_offset, data))
}
type ByteSlice<'a> = &'a [u8];