Display dates with the host's timezone

Fixes #54 using the datetime crate's spiffy new time zone ability.
This commit is contained in:
Ben S 2015-06-04 15:15:39 +01:00
parent 90c77ff3b4
commit cc1d6aa5f1
3 changed files with 53 additions and 26 deletions

68
Cargo.lock generated
View File

@ -2,15 +2,15 @@
name = "exa" name = "exa"
version = "0.2.0" version = "0.2.0"
dependencies = [ dependencies = [
"ansi_term 0.5.2", "ansi_term 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
"bitflags 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "bitflags 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"datetime 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", "datetime 0.2.0",
"getopts 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", "getopts 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
"git2 0.2.11 (git+https://github.com/alexcrichton/git2-rs.git)", "git2 0.2.11 (git+https://github.com/alexcrichton/git2-rs.git)",
"libc 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
"locale 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", "locale 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
"natord 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)", "natord 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)",
"num_cpus 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
"number_prefix 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", "number_prefix 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)",
"pad 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "pad 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
"unicode-width 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-width 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
@ -20,6 +20,7 @@ dependencies = [
[[package]] [[package]]
name = "ansi_term" name = "ansi_term"
version = "0.5.2" version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]] [[package]]
name = "bitflags" name = "bitflags"
@ -27,20 +28,25 @@ version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]] [[package]]
name = "datetime" name = "byteorder"
version = "0.1.7" version = "0.3.10"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "datetime"
version = "0.2.0"
dependencies = [ dependencies = [
"locale 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", "locale 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
"num 0.1.24 (registry+https://github.com/rust-lang/crates.io-index)", "num 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)",
"pad 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "pad 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
"regex 0.1.30 (registry+https://github.com/rust-lang/crates.io-index)", "regex 0.1.33 (registry+https://github.com/rust-lang/crates.io-index)",
"regex_macros 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)", "regex_macros 0.1.19 (registry+https://github.com/rust-lang/crates.io-index)",
"tz 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]] [[package]]
name = "gcc" name = "gcc"
version = "0.3.5" version = "0.3.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]] [[package]]
@ -54,12 +60,12 @@ dependencies = [
[[package]] [[package]]
name = "git2" name = "git2"
version = "0.2.11" version = "0.2.11"
source = "git+https://github.com/alexcrichton/git2-rs.git#49c7a7b3853626180e1767051ed53f0400140ff2" source = "git+https://github.com/alexcrichton/git2-rs.git#f63542fb5d58c138dd3ec32f78ab3f97e2251cfa"
dependencies = [ dependencies = [
"bitflags 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "bitflags 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
"libgit2-sys 0.2.14 (git+https://github.com/alexcrichton/git2-rs.git)", "libgit2-sys 0.2.14 (git+https://github.com/alexcrichton/git2-rs.git)",
"url 0.2.34 (registry+https://github.com/rust-lang/crates.io-index)", "url 0.2.35 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]] [[package]]
@ -70,10 +76,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]] [[package]]
name = "libgit2-sys" name = "libgit2-sys"
version = "0.2.14" version = "0.2.14"
source = "git+https://github.com/alexcrichton/git2-rs.git#49c7a7b3853626180e1767051ed53f0400140ff2" source = "git+https://github.com/alexcrichton/git2-rs.git#f63542fb5d58c138dd3ec32f78ab3f97e2251cfa"
dependencies = [ dependencies = [
"libc 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
"libssh2-sys 0.1.23 (registry+https://github.com/rust-lang/crates.io-index)", "libssh2-sys 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)",
"libz-sys 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "libz-sys 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
"openssl-sys 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", "openssl-sys 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
"pkg-config 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", "pkg-config 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
@ -89,7 +95,7 @@ dependencies = [
[[package]] [[package]]
name = "libssh2-sys" name = "libssh2-sys"
version = "0.1.23" version = "0.1.25"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [ dependencies = [
"libc 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
@ -113,7 +119,7 @@ version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [ dependencies = [
"libc 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
"num 0.1.24 (registry+https://github.com/rust-lang/crates.io-index)", "num 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]] [[package]]
@ -136,7 +142,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]] [[package]]
name = "num" name = "num"
version = "0.1.24" version = "0.1.25"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [ dependencies = [
"rand 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
@ -145,7 +151,7 @@ dependencies = [
[[package]] [[package]]
name = "num_cpus" name = "num_cpus"
version = "0.2.5" version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [ dependencies = [
"libc 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
@ -156,7 +162,7 @@ name = "number_prefix"
version = "0.2.4" version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [ dependencies = [
"num 0.1.24 (registry+https://github.com/rust-lang/crates.io-index)", "num 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]] [[package]]
@ -164,7 +170,7 @@ name = "openssl-sys"
version = "0.6.2" version = "0.6.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [ dependencies = [
"gcc 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", "gcc 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
"libressl-pnacl-sys 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "libressl-pnacl-sys 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
"pkg-config 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", "pkg-config 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
@ -201,15 +207,23 @@ dependencies = [
[[package]] [[package]]
name = "regex" name = "regex"
version = "0.1.30" version = "0.1.33"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"regex-syntax 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "regex-syntax"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]] [[package]]
name = "regex_macros" name = "regex_macros"
version = "0.1.17" version = "0.1.19"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [ dependencies = [
"regex 0.1.30 (registry+https://github.com/rust-lang/crates.io-index)", "regex 0.1.33 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]] [[package]]
@ -225,6 +239,14 @@ dependencies = [
"rand 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]]
name = "tz"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"byteorder 0.3.10 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "unicode-width" name = "unicode-width"
version = "0.1.1" version = "0.1.1"
@ -232,7 +254,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]] [[package]]
name = "url" name = "url"
version = "0.2.34" version = "0.2.35"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [ dependencies = [
"matches 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "matches 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",

View File

@ -9,7 +9,7 @@ name = "exa"
[dependencies] [dependencies]
ansi_term = "0.5.0" ansi_term = "0.5.0"
bitflags = "0.1" bitflags = "0.1"
datetime = "0.1.3" datetime = "0.2.0"
getopts = "0.2.1" getopts = "0.2.1"
libc = "*" libc = "*"
locale = "0.1.2" locale = "0.1.2"

View File

@ -19,6 +19,8 @@ use number_prefix::{binary_prefix, decimal_prefix, Prefixed, Standalone, PrefixN
use datetime::local::{LocalDateTime, DatePiece}; use datetime::local::{LocalDateTime, DatePiece};
use datetime::format::{DateFormat}; use datetime::format::{DateFormat};
use datetime::zoned::{VariableOffset, TimeZone};
/// With the **Details** view, the output gets formatted into columns, with /// With the **Details** view, the output gets formatted into columns, with
/// each `Column` object showing some piece of information about the file, /// each `Column` object showing some piece of information about the file,
@ -128,6 +130,7 @@ pub struct Table<U> {
time: locale::Time, time: locale::Time,
numeric: locale::Numeric, numeric: locale::Numeric,
tz: VariableOffset,
users: U, users: U,
colours: Colours, colours: Colours,
current_year: i64, current_year: i64,
@ -140,6 +143,7 @@ impl Default for Table<MockUsers> {
rows: Vec::new(), rows: Vec::new(),
time: locale::Time::english(), time: locale::Time::english(),
numeric: locale::Numeric::english(), numeric: locale::Numeric::english(),
tz: VariableOffset::localtime().unwrap(),
users: MockUsers::with_current_uid(0), users: MockUsers::with_current_uid(0),
colours: Colours::default(), colours: Colours::default(),
current_year: 1234, current_year: 1234,
@ -158,6 +162,7 @@ impl Table<OSUsers> {
time: locale::Time::load_user_locale().unwrap_or_else(|_| locale::Time::english()), time: locale::Time::load_user_locale().unwrap_or_else(|_| locale::Time::english()),
numeric: locale::Numeric::load_user_locale().unwrap_or_else(|_| locale::Numeric::english()), numeric: locale::Numeric::load_user_locale().unwrap_or_else(|_| locale::Numeric::english()),
tz: VariableOffset::localtime().unwrap(),
users: OSUsers::empty_cache(), users: OSUsers::empty_cache(),
colours: colours, colours: colours,
current_year: LocalDateTime::now().year(), current_year: LocalDateTime::now().year(),
@ -304,7 +309,7 @@ impl<U> Table<U> where U: Users {
} }
fn render_time(&self, timestamp: f::Time) -> Cell { fn render_time(&self, timestamp: f::Time) -> Cell {
let date = LocalDateTime::at(timestamp.0); let date = self.tz.at(LocalDateTime::at(timestamp.0));
let format = if date.year() == self.current_year { let format = if date.year() == self.current_year {
DateFormat::parse("{2>:D} {:M} {2>:h}:{02>:m}").unwrap() DateFormat::parse("{2>:D} {:M} {2>:h}:{02>:m}").unwrap()
@ -313,7 +318,7 @@ impl<U> Table<U> where U: Users {
DateFormat::parse("{2>:D} {:M} {5>:Y}").unwrap() DateFormat::parse("{2>:D} {:M} {5>:Y}").unwrap()
}; };
Cell::paint(self.colours.date, &format.format(date, &self.time)) Cell::paint(self.colours.date, &format.format(&date, &self.time))
} }
fn render_git_status(&self, git: f::Git) -> Cell { fn render_git_status(&self, git: f::Git) -> Cell {