Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(time_display): time should use /etc/timezone #721

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,4 @@ tests/test_dir

# Miscenallous
.idea
.vscode/
16 changes: 0 additions & 16 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,13 @@ SPDX-License-Identifier: EUPL-1.2
-->
# Changelog

## [0.20.16] - 2025-01-09

### Features

- Add brew icon for brewfile and brewfile.lock.json

### Build

- Update flake inputs 2025-01-08
- Update cargo inputs 2025-01-08
- Bump git2 from 0.19.0 to 0.20.0

## [0.20.15] - 2025-01-02

### Features

- Add icons from nerd fonts 3.3.0 release & more
- Add new icons, extensive list

### Miscellaneous Tasks

- Eza v0.20.15 changelogs, version bump

### Build

- We switch to our own fork of natord
Expand Down
60 changes: 51 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ readme = "README.md"
homepage = "https://github.com/eza-community/eza"
license = "EUPL-1.2"
repository = "https://github.com/eza-community/eza"
version = "0.20.16"
version = "0.20.15"


[package.metadata.deb]
Expand Down Expand Up @@ -86,6 +86,8 @@ name = "eza"
[dependencies]
rayon = "1.10.0"
chrono = { version = "0.4.34", default-features = false, features = ["clock"] }
chrono-tz = "0.10.0"
iana-time-zone = "0.1.58"
nu-ansi-term = { version = "0.50.1", features = [
"serde",
"derive_serde_style",
Expand Down Expand Up @@ -114,7 +116,7 @@ serde_norway = "0.9"
backtrace = "0.3"

[dependencies.git2]
version = "0.20"
version = "0.19"
optional = true
default-features = false

Expand Down
55 changes: 36 additions & 19 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions src/output/icons.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,6 @@ const FILENAME_ICONS: Map<&'static str, char> = phf_map! {
"AUTHORS" => '\u{edca}', // 
"AUTHORS.txt" => '\u{edca}', // 
"bashrc" => Icons::SHELL, // 󱆃
"brewfile" => '\u{f1116}', // 󱄖
"brewfile.lock.json" => '\u{f1116}', // 󱄖
"bspwmrc" => '\u{f355}', // 
"build.gradle.kts" => Icons::GRADLE, // 
"build.zig.zon" => '\u{e6a9}', // 
Expand Down
21 changes: 17 additions & 4 deletions src/output/render/times.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,33 @@ use chrono::prelude::*;
use nu_ansi_term::Style;

pub trait Render {
fn render(self, style: Style, time_offset: FixedOffset, time_format: TimeFormat) -> TextCell;
fn render(self, style: Style, time_format: TimeFormat) -> TextCell;
}

impl Render for Option<NaiveDateTime> {
fn render(self, style: Style, time_offset: FixedOffset, time_format: TimeFormat) -> TextCell {
let datestamp = if let Some(time) = self {
fn render(self, style: Style, time_format: TimeFormat) -> TextCell {
let datestamp = if let Ok(timezone_str) = iana_time_zone::get_timezone() {
let timezone: chrono_tz::Tz = timezone_str.parse().unwrap();
if let Some(time) = self {
let time_offset = timezone.offset_from_utc_datetime(&time).fix();
time_format.format(&DateTime::<FixedOffset>::from_naive_utc_and_offset(
time,
time_offset,
))
} else {
String::from("-")
}
} else if let Some(time) = self {
// This is the next best thing, use the timezone now, instead of at the time of the
// timestamp.
let time_offset: FixedOffset = *Local::now().offset();
time_format.format(&DateTime::<FixedOffset>::from_naive_utc_and_offset(
time,
time_offset,
))
} else {
String::from("-")
};

TextCell::paint(style, datestamp)
}
}
7 changes: 0 additions & 7 deletions src/output/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,9 +363,6 @@ impl Default for TimeTypes {
///
/// Any environment field should be able to be mocked up for test runs.
pub struct Environment {
/// The computer’s current time offset, determined from time zone.
time_offset: FixedOffset,

/// Localisation rules for formatting numbers.
numeric: locale::Numeric,

Expand All @@ -381,16 +378,13 @@ impl Environment {
}

fn load_all() -> Self {
let time_offset = *Local::now().offset();

let numeric =
locale::Numeric::load_user_locale().unwrap_or_else(|_| locale::Numeric::english());

#[cfg(unix)]
let users = Mutex::new(UsersCache::new());

Self {
time_offset,
numeric,
#[cfg(unix)]
users,
Expand Down Expand Up @@ -568,7 +562,6 @@ impl<'a> Table<'a> {
} else {
self.theme.ui.date.unwrap_or_default()
},
self.env.time_offset,
self.time_format.clone(),
),
}
Expand Down
Loading
Loading