mirror of
https://github.com/atuinsh/atuin.git
synced 2024-11-22 00:03:49 +01:00
fix(stats): time now_local not working
This commit is contained in:
parent
c7db7838e3
commit
e2a4e9cf13
@ -219,7 +219,13 @@ pub struct Settings {
|
||||
|
||||
// This is automatically loaded when settings is created. Do not set in
|
||||
// config! Keep secrets and settings apart.
|
||||
#[serde(skip)]
|
||||
pub session_token: String,
|
||||
|
||||
// This is determined at startup and cached.
|
||||
// This is due to non-threadsafe get-env limitations.
|
||||
#[serde(skip)]
|
||||
pub local_tz: Option<time::UtcOffset>,
|
||||
}
|
||||
|
||||
impl Settings {
|
||||
@ -488,6 +494,8 @@ impl Settings {
|
||||
settings.session_token = String::from("not logged in");
|
||||
}
|
||||
|
||||
settings.local_tz = time::UtcOffset::current_local_offset().ok();
|
||||
|
||||
Ok(settings)
|
||||
}
|
||||
|
||||
|
@ -83,31 +83,31 @@ impl Cmd {
|
||||
self.period.join(" ")
|
||||
};
|
||||
|
||||
let now = OffsetDateTime::now_utc();
|
||||
let now = settings.local_tz.map_or(now, |local| now.to_offset(local));
|
||||
let last_night = now.replace_time(Time::MIDNIGHT);
|
||||
|
||||
let history = if words.as_str() == "all" {
|
||||
db.list(FilterMode::Global, &context, None, false, false)
|
||||
.await?
|
||||
} else if words.trim() == "today" {
|
||||
let start = OffsetDateTime::now_local()?.replace_time(Time::MIDNIGHT);
|
||||
let start = last_night;
|
||||
let end = start + Duration::days(1);
|
||||
db.range(start, end).await?
|
||||
} else if words.trim() == "month" {
|
||||
let end = OffsetDateTime::now_local()?.replace_time(Time::MIDNIGHT);
|
||||
let end = last_night;
|
||||
let start = end - Duration::days(31);
|
||||
db.range(start, end).await?
|
||||
} else if words.trim() == "week" {
|
||||
let end = OffsetDateTime::now_local()?.replace_time(Time::MIDNIGHT);
|
||||
let end = last_night;
|
||||
let start = end - Duration::days(7);
|
||||
db.range(start, end).await?
|
||||
} else if words.trim() == "year" {
|
||||
let end = OffsetDateTime::now_local()?.replace_time(Time::MIDNIGHT);
|
||||
let end = last_night;
|
||||
let start = end - Duration::days(365);
|
||||
db.range(start, end).await?
|
||||
} else {
|
||||
let start = parse_date_string(
|
||||
&words,
|
||||
OffsetDateTime::now_local()?,
|
||||
settings.dialect.into(),
|
||||
)?;
|
||||
let start = parse_date_string(&words, now, settings.dialect.into())?;
|
||||
let end = start + Duration::days(1);
|
||||
db.range(start, end).await?
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user