From 4cb2d282589c00e3c6eabffbf5623883c463425a Mon Sep 17 00:00:00 2001 From: Alexander Bakanovskii Date: Fri, 19 Sep 2025 11:38:18 +0300 Subject: [PATCH] pinky: fix time format --- src/uu/pinky/src/platform/unix.rs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/uu/pinky/src/platform/unix.rs b/src/uu/pinky/src/platform/unix.rs index 1a749e6b9..57ec6bcdd 100644 --- a/src/uu/pinky/src/platform/unix.rs +++ b/src/uu/pinky/src/platform/unix.rs @@ -136,11 +136,20 @@ fn idle_string(when: i64) -> String { } fn time_string(ut: &UtmpxRecord) -> String { - // "%b %e %H:%M" - let time_format: Vec = + let lc_time: String = std::env::var("LC_ALL") + .or_else(|_| std::env::var("LC_TIME")) + .or_else(|_| std::env::var("LANG")) + .unwrap_or_default(); + + let time_format: Vec = if lc_time == "C" { + // "%b %e %H:%M" time::format_description::parse("[month repr:short] [day padding:space] [hour]:[minute]") - .unwrap(); - ut.login_time().format(&time_format).unwrap() // LC_ALL=C + .unwrap() + } else { + // "%Y-%m-%d %H:%M" + time::format_description::parse("[year]-[month]-[day] [hour]:[minute]").unwrap() + }; + ut.login_time().format(&time_format).unwrap() } fn gecos_to_fullname(pw: &Passwd) -> Option {