Skip to content

Commit

Permalink
fix(stats): time now_local not working
Browse files Browse the repository at this point in the history
  • Loading branch information
conradludgate authored Jan 1, 2024
1 parent c7db783 commit e2a4e9c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
8 changes: 8 additions & 0 deletions atuin-client/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}

Expand Down
18 changes: 9 additions & 9 deletions atuin/src/command/client/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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?
};
Expand Down

1 comment on commit e2a4e9c

@vercel
Copy link

@vercel vercel bot commented on e2a4e9c Jan 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

atuin-docs – ./

atuin-docs.vercel.app
atuin-docs-git-main-atuin.vercel.app
atuin-docs-atuin.vercel.app

Please sign in to comment.