mirror of
https://github.com/Llewellynvdm/exa.git
synced 2024-11-22 12:05:11 +00:00
Merge pull request #837 from ariasuni/fix-month-name-not-translated
Fix month name not following locale when date is in current year
This commit is contained in:
commit
e86f2b938b
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
use std::time::{SystemTime, UNIX_EPOCH};
|
use std::time::{SystemTime, UNIX_EPOCH};
|
||||||
|
|
||||||
use datetime::{LocalDateTime, TimeZone, DatePiece, TimePiece, Month};
|
use datetime::{LocalDateTime, TimeZone, DatePiece, TimePiece};
|
||||||
use datetime::fmt::DateFormat;
|
use datetime::fmt::DateFormat;
|
||||||
|
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
@ -75,41 +75,26 @@ impl TimeFormat {
|
|||||||
#[allow(trivial_numeric_casts)]
|
#[allow(trivial_numeric_casts)]
|
||||||
fn default_local(time: SystemTime) -> String {
|
fn default_local(time: SystemTime) -> String {
|
||||||
let date = LocalDateTime::at(systemtime_epoch(time));
|
let date = LocalDateTime::at(systemtime_epoch(time));
|
||||||
|
let date_format = get_dateformat(&date);
|
||||||
if date.year() == *CURRENT_YEAR {
|
|
||||||
format!("{:2} {} {:02}:{:02}",
|
|
||||||
date.day(), month_to_abbrev(date.month()),
|
|
||||||
date.hour(), date.minute())
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
let date_format = match *MAXIMUM_MONTH_WIDTH {
|
|
||||||
4 => &*FOUR_WIDE_DATE_TIME,
|
|
||||||
5 => &*FIVE_WIDE_DATE_TIME,
|
|
||||||
_ => &*OTHER_WIDE_DATE_TIME,
|
|
||||||
};
|
|
||||||
|
|
||||||
date_format.format(&date, &*LOCALE)
|
date_format.format(&date, &*LOCALE)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(trivial_numeric_casts)]
|
#[allow(trivial_numeric_casts)]
|
||||||
fn default_zoned(time: SystemTime, zone: &TimeZone) -> String {
|
fn default_zoned(time: SystemTime, zone: &TimeZone) -> String {
|
||||||
let date = zone.to_zoned(LocalDateTime::at(systemtime_epoch(time)));
|
let date = zone.to_zoned(LocalDateTime::at(systemtime_epoch(time)));
|
||||||
|
let date_format = get_dateformat(&date);
|
||||||
if date.year() == *CURRENT_YEAR {
|
|
||||||
format!("{:2} {} {:02}:{:02}",
|
|
||||||
date.day(), month_to_abbrev(date.month()),
|
|
||||||
date.hour(), date.minute())
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
let date_format = match *MAXIMUM_MONTH_WIDTH {
|
|
||||||
4 => &*FOUR_WIDE_DATE_YEAR,
|
|
||||||
5 => &*FIVE_WIDE_DATE_YEAR,
|
|
||||||
_ => &*OTHER_WIDE_DATE_YEAR,
|
|
||||||
};
|
|
||||||
|
|
||||||
date_format.format(&date, &*LOCALE)
|
date_format.format(&date, &*LOCALE)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_dateformat(date: &LocalDateTime) -> &'static DateFormat<'static> {
|
||||||
|
match (is_recent(&date), *MAXIMUM_MONTH_WIDTH) {
|
||||||
|
(true, 4) => &FOUR_WIDE_DATE_TIME,
|
||||||
|
(true, 5) => &FIVE_WIDE_DATE_TIME,
|
||||||
|
(true, _) => &OTHER_WIDE_DATE_TIME,
|
||||||
|
(false, 4) => &FOUR_WIDE_DATE_YEAR,
|
||||||
|
(false, 5) => &FIVE_WIDE_DATE_YEAR,
|
||||||
|
(false, _) => &OTHER_WIDE_DATE_YEAR,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(trivial_numeric_casts)]
|
#[allow(trivial_numeric_casts)]
|
||||||
@ -153,7 +138,7 @@ fn full_zoned(time: SystemTime, zone: &TimeZone) -> String {
|
|||||||
fn iso_local(time: SystemTime) -> String {
|
fn iso_local(time: SystemTime) -> String {
|
||||||
let date = LocalDateTime::at(systemtime_epoch(time));
|
let date = LocalDateTime::at(systemtime_epoch(time));
|
||||||
|
|
||||||
if is_recent(date) {
|
if is_recent(&date) {
|
||||||
format!("{:02}-{:02} {:02}:{:02}",
|
format!("{:02}-{:02} {:02}:{:02}",
|
||||||
date.month() as usize, date.day(),
|
date.month() as usize, date.day(),
|
||||||
date.hour(), date.minute())
|
date.hour(), date.minute())
|
||||||
@ -168,7 +153,7 @@ fn iso_local(time: SystemTime) -> String {
|
|||||||
fn iso_zoned(time: SystemTime, zone: &TimeZone) -> String {
|
fn iso_zoned(time: SystemTime, zone: &TimeZone) -> String {
|
||||||
let date = zone.to_zoned(LocalDateTime::at(systemtime_epoch(time)));
|
let date = zone.to_zoned(LocalDateTime::at(systemtime_epoch(time)));
|
||||||
|
|
||||||
if is_recent(date) {
|
if is_recent(&date) {
|
||||||
format!("{:02}-{:02} {:02}:{:02}",
|
format!("{:02}-{:02} {:02}:{:02}",
|
||||||
date.month() as usize, date.day(),
|
date.month() as usize, date.day(),
|
||||||
date.hour(), date.minute())
|
date.hour(), date.minute())
|
||||||
@ -206,27 +191,10 @@ fn systemtime_nanos(time: SystemTime) -> u32 {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_recent(date: LocalDateTime) -> bool {
|
fn is_recent(date: &LocalDateTime) -> bool {
|
||||||
date.year() == *CURRENT_YEAR
|
date.year() == *CURRENT_YEAR
|
||||||
}
|
}
|
||||||
|
|
||||||
fn month_to_abbrev(month: Month) -> &'static str {
|
|
||||||
match month {
|
|
||||||
Month::January => "Jan",
|
|
||||||
Month::February => "Feb",
|
|
||||||
Month::March => "Mar",
|
|
||||||
Month::April => "Apr",
|
|
||||||
Month::May => "May",
|
|
||||||
Month::June => "Jun",
|
|
||||||
Month::July => "Jul",
|
|
||||||
Month::August => "Aug",
|
|
||||||
Month::September => "Sep",
|
|
||||||
Month::October => "Oct",
|
|
||||||
Month::November => "Nov",
|
|
||||||
Month::December => "Dec",
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
|
|
||||||
@ -250,15 +218,15 @@ lazy_static! {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static ref FOUR_WIDE_DATE_TIME: DateFormat<'static> = DateFormat::parse(
|
static ref FOUR_WIDE_DATE_TIME: DateFormat<'static> = DateFormat::parse(
|
||||||
"{2>:D} {4<:M} {2>:h}:{02>:m}"
|
"{2>:D} {4<:M} {02>:h}:{02>:m}"
|
||||||
).unwrap();
|
).unwrap();
|
||||||
|
|
||||||
static ref FIVE_WIDE_DATE_TIME: DateFormat<'static> = DateFormat::parse(
|
static ref FIVE_WIDE_DATE_TIME: DateFormat<'static> = DateFormat::parse(
|
||||||
"{2>:D} {5<:M} {2>:h}:{02>:m}"
|
"{2>:D} {5<:M} {02>:h}:{02>:m}"
|
||||||
).unwrap();
|
).unwrap();
|
||||||
|
|
||||||
static ref OTHER_WIDE_DATE_TIME: DateFormat<'static> = DateFormat::parse(
|
static ref OTHER_WIDE_DATE_TIME: DateFormat<'static> = DateFormat::parse(
|
||||||
"{2>:D} {:M} {2>:h}:{02>:m}"
|
"{2>:D} {:M} {02>:h}:{02>:m}"
|
||||||
).unwrap();
|
).unwrap();
|
||||||
|
|
||||||
static ref FOUR_WIDE_DATE_YEAR: DateFormat<'static> = DateFormat::parse(
|
static ref FOUR_WIDE_DATE_YEAR: DateFormat<'static> = DateFormat::parse(
|
||||||
|
@ -68,7 +68,7 @@ tags = [ 'long', 'time-style' ]
|
|||||||
[[cmd]]
|
[[cmd]]
|
||||||
name = "‘exa -l’ using a locale with 4-character-long month abbreviations (‘ja_JP’) sizes the date column correctly"
|
name = "‘exa -l’ using a locale with 4-character-long month abbreviations (‘ja_JP’) sizes the date column correctly"
|
||||||
shell = "exa -l /testcases/dates"
|
shell = "exa -l /testcases/dates"
|
||||||
environment = { LC_ALL = "ja_JP.UTF-8", LANG = "ja_JP.UTF-8" }
|
environment = { LC_TIME = "ja_JP.UTF-8", LANG = "ja_JP.UTF-8" }
|
||||||
stdout = { file = "outputs/dates_long_localejp.ansitxt" }
|
stdout = { file = "outputs/dates_long_localejp.ansitxt" }
|
||||||
stderr = { empty = true }
|
stderr = { empty = true }
|
||||||
status = 0
|
status = 0
|
||||||
@ -77,8 +77,17 @@ tags = [ 'long', 'locales' ]
|
|||||||
[[cmd]]
|
[[cmd]]
|
||||||
name = "‘exa -l’ using a locale with 5-character-long month abbreviations (‘fr_FR’) sizes the date column correctly"
|
name = "‘exa -l’ using a locale with 5-character-long month abbreviations (‘fr_FR’) sizes the date column correctly"
|
||||||
shell = "exa -l /testcases/dates"
|
shell = "exa -l /testcases/dates"
|
||||||
environment = { LC_ALL = "fr_FR.UTF-8", LANG = "fr_FR.UTF-8" }
|
environment = { LC_TIME = "fr_FR.UTF-8", LANG = "fr_FR.UTF-8" }
|
||||||
stdout = { file = "outputs/dates_long_localefr.ansitxt" }
|
stdout = { file = "outputs/dates_long_localefr.ansitxt" }
|
||||||
stderr = { empty = true }
|
stderr = { empty = true }
|
||||||
status = 0
|
status = 0
|
||||||
tags = [ 'long', 'locales' ]
|
tags = [ 'long', 'locales' ]
|
||||||
|
|
||||||
|
[[cmd]]
|
||||||
|
name = "‘exa -l’ using a locale (‘fr_FR’) display dates of the current year with localized month name"
|
||||||
|
shell = "exa -l /testcases/files"
|
||||||
|
environment = { LC_TIME = "fr_FR.UTF-8", LANG = "fr_FR.UTF-8" }
|
||||||
|
stdout = { file = "outputs/dates_long_currentyear_localefr.ansitxt" }
|
||||||
|
stderr = { empty = true }
|
||||||
|
status = 0
|
||||||
|
tags = [ 'long', 'locales' ]
|
||||||
|
39
xtests/outputs/dates_long_currentyear_localefr.ansitxt
Normal file
39
xtests/outputs/dates_long_currentyear_localefr.ansitxt
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
.[1;33mr[31mw[0m[38;5;244m-[33mr[38;5;244m--[33mr[38;5;244m--[0m [1;32m1[0m cassowary [34m 1 janv. 12:34[0m 1_bytes
|
||||||
|
.[1;33mr[31mw[0m[38;5;244m-[33mr[38;5;244m--[33mr[38;5;244m--[0m [1;32m1,0[0m[32mk[0m cassowary [34m 1 janv. 12:34[0m 1_KiB
|
||||||
|
.[1;33mr[31mw[0m[38;5;244m-[33mr[38;5;244m--[33mr[38;5;244m--[0m [1;32m1,0[0m[32mM[0m cassowary [34m 1 janv. 12:34[0m 1_MiB
|
||||||
|
.[1;33mr[31mw[0m[38;5;244m-[33mr[38;5;244m--[33mr[38;5;244m--[0m [1;32m2[0m cassowary [34m 1 janv. 12:34[0m 2_bytes
|
||||||
|
.[1;33mr[31mw[0m[38;5;244m-[33mr[38;5;244m--[33mr[38;5;244m--[0m [1;32m2,0[0m[32mk[0m cassowary [34m 1 janv. 12:34[0m 2_KiB
|
||||||
|
.[1;33mr[31mw[0m[38;5;244m-[33mr[38;5;244m--[33mr[38;5;244m--[0m [1;32m2,1[0m[32mM[0m cassowary [34m 1 janv. 12:34[0m 2_MiB
|
||||||
|
.[1;33mr[31mw[0m[38;5;244m-[33mr[38;5;244m--[33mr[38;5;244m--[0m [1;32m3[0m cassowary [34m 1 janv. 12:34[0m 3_bytes
|
||||||
|
.[1;33mr[31mw[0m[38;5;244m-[33mr[38;5;244m--[33mr[38;5;244m--[0m [1;32m3,1[0m[32mk[0m cassowary [34m 1 janv. 12:34[0m 3_KiB
|
||||||
|
.[1;33mr[31mw[0m[38;5;244m-[33mr[38;5;244m--[33mr[38;5;244m--[0m [1;32m3,1[0m[32mM[0m cassowary [34m 1 janv. 12:34[0m 3_MiB
|
||||||
|
.[1;33mr[31mw[0m[38;5;244m-[33mr[38;5;244m--[33mr[38;5;244m--[0m [1;32m4[0m cassowary [34m 1 janv. 12:34[0m 4_bytes
|
||||||
|
.[1;33mr[31mw[0m[38;5;244m-[33mr[38;5;244m--[33mr[38;5;244m--[0m [1;32m4,1[0m[32mk[0m cassowary [34m 1 janv. 12:34[0m 4_KiB
|
||||||
|
.[1;33mr[31mw[0m[38;5;244m-[33mr[38;5;244m--[33mr[38;5;244m--[0m [1;32m4,2[0m[32mM[0m cassowary [34m 1 janv. 12:34[0m 4_MiB
|
||||||
|
.[1;33mr[31mw[0m[38;5;244m-[33mr[38;5;244m--[33mr[38;5;244m--[0m [1;32m5[0m cassowary [34m 1 janv. 12:34[0m 5_bytes
|
||||||
|
.[1;33mr[31mw[0m[38;5;244m-[33mr[38;5;244m--[33mr[38;5;244m--[0m [1;32m5,1[0m[32mk[0m cassowary [34m 1 janv. 12:34[0m 5_KiB
|
||||||
|
.[1;33mr[31mw[0m[38;5;244m-[33mr[38;5;244m--[33mr[38;5;244m--[0m [1;32m5,2[0m[32mM[0m cassowary [34m 1 janv. 12:34[0m 5_MiB
|
||||||
|
.[1;33mr[31mw[0m[38;5;244m-[33mr[38;5;244m--[33mr[38;5;244m--[0m [1;32m6[0m cassowary [34m 1 janv. 12:34[0m 6_bytes
|
||||||
|
.[1;33mr[31mw[0m[38;5;244m-[33mr[38;5;244m--[33mr[38;5;244m--[0m [1;32m6,1[0m[32mk[0m cassowary [34m 1 janv. 12:34[0m 6_KiB
|
||||||
|
.[1;33mr[31mw[0m[38;5;244m-[33mr[38;5;244m--[33mr[38;5;244m--[0m [1;32m6,3[0m[32mM[0m cassowary [34m 1 janv. 12:34[0m 6_MiB
|
||||||
|
.[1;33mr[31mw[0m[38;5;244m-[33mr[38;5;244m--[33mr[38;5;244m--[0m [1;32m7[0m cassowary [34m 1 janv. 12:34[0m 7_bytes
|
||||||
|
.[1;33mr[31mw[0m[38;5;244m-[33mr[38;5;244m--[33mr[38;5;244m--[0m [1;32m7,2[0m[32mk[0m cassowary [34m 1 janv. 12:34[0m 7_KiB
|
||||||
|
.[1;33mr[31mw[0m[38;5;244m-[33mr[38;5;244m--[33mr[38;5;244m--[0m [1;32m7,3[0m[32mM[0m cassowary [34m 1 janv. 12:34[0m 7_MiB
|
||||||
|
.[1;33mr[31mw[0m[38;5;244m-[33mr[38;5;244m--[33mr[38;5;244m--[0m [1;32m8[0m cassowary [34m 1 janv. 12:34[0m 8_bytes
|
||||||
|
.[1;33mr[31mw[0m[38;5;244m-[33mr[38;5;244m--[33mr[38;5;244m--[0m [1;32m8,2[0m[32mk[0m cassowary [34m 1 janv. 12:34[0m 8_KiB
|
||||||
|
.[1;33mr[31mw[0m[38;5;244m-[33mr[38;5;244m--[33mr[38;5;244m--[0m [1;32m8,4[0m[32mM[0m cassowary [34m 1 janv. 12:34[0m 8_MiB
|
||||||
|
.[1;33mr[31mw[0m[38;5;244m-[33mr[38;5;244m--[33mr[38;5;244m--[0m [1;32m9[0m cassowary [34m 1 janv. 12:34[0m 9_bytes
|
||||||
|
.[1;33mr[31mw[0m[38;5;244m-[33mr[38;5;244m--[33mr[38;5;244m--[0m [1;32m9,2[0m[32mk[0m cassowary [34m 1 janv. 12:34[0m 9_KiB
|
||||||
|
.[1;33mr[31mw[0m[38;5;244m-[33mr[38;5;244m--[33mr[38;5;244m--[0m [1;32m9,4[0m[32mM[0m cassowary [34m 1 janv. 12:34[0m 9_MiB
|
||||||
|
.[1;33mr[31mw[0m[38;5;244m-[33mr[38;5;244m--[33mr[38;5;244m--[0m [1;32m10[0m cassowary [34m 1 janv. 12:34[0m 10_bytes
|
||||||
|
.[1;33mr[31mw[0m[38;5;244m-[33mr[38;5;244m--[33mr[38;5;244m--[0m [1;32m10[0m[32mk[0m cassowary [34m 1 janv. 12:34[0m 10_KiB
|
||||||
|
.[1;33mr[31mw[0m[38;5;244m-[33mr[38;5;244m--[33mr[38;5;244m--[0m [1;32m10[0m[32mM[0m cassowary [34m 1 janv. 12:34[0m 10_MiB
|
||||||
|
.[1;33mr[31mw[0m[38;5;244m-[33mr[38;5;244m--[33mr[38;5;244m--[0m [1;32m11[0m cassowary [34m 1 janv. 12:34[0m 11_bytes
|
||||||
|
.[1;33mr[31mw[0m[38;5;244m-[33mr[38;5;244m--[33mr[38;5;244m--[0m [1;32m11[0m[32mk[0m cassowary [34m 1 janv. 12:34[0m 11_KiB
|
||||||
|
.[1;33mr[31mw[0m[38;5;244m-[33mr[38;5;244m--[33mr[38;5;244m--[0m [1;32m12[0m[32mM[0m cassowary [34m 1 janv. 12:34[0m 11_MiB
|
||||||
|
.[1;33mr[31mw[0m[38;5;244m-[33mr[38;5;244m--[33mr[38;5;244m--[0m [1;32m12[0m cassowary [34m 1 janv. 12:34[0m 12_bytes
|
||||||
|
.[1;33mr[31mw[0m[38;5;244m-[33mr[38;5;244m--[33mr[38;5;244m--[0m [1;32m12[0m[32mk[0m cassowary [34m 1 janv. 12:34[0m 12_KiB
|
||||||
|
.[1;33mr[31mw[0m[38;5;244m-[33mr[38;5;244m--[33mr[38;5;244m--[0m [1;32m13[0m[32mM[0m cassowary [34m 1 janv. 12:34[0m 12_MiB
|
||||||
|
.[1;33mr[31mw[0m[38;5;244m-[33mr[38;5;244m--[33mr[38;5;244m--[0m [1;32m13[0m cassowary [34m 1 janv. 12:34[0m 13_bytes
|
||||||
|
.[1;33mr[31mw[0m[38;5;244m-[33mr[38;5;244m--[33mr[38;5;244m--[0m [1;32m13[0m[32mk[0m cassowary [34m 1 janv. 12:34[0m 13_KiB
|
||||||
|
.[1;33mr[31mw[0m[38;5;244m-[33mr[38;5;244m--[33mr[38;5;244m--[0m [1;32m14[0m[32mM[0m cassowary [34m 1 janv. 12:34[0m 13_MiB
|
Loading…
Reference in New Issue
Block a user