From aad468e8b75ffc3e87ea6dfa22c53a8299fc08da Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sun, 16 Aug 2026 00:29:03 +0900 Subject: feat(php-shim): render human-facing timestamps in the local timezone Split date() into date_utc() and date_local(), the latter resolving the system's local timezone through the tzfile crate ($TZ, then /etc/localtime, falling back to UTC when neither is readable). The timestamps Composer renders for humans -- the GitHub OAuth token note, the GitHub API rate limit reset time, the Perforce client spec fields and the "today" check of the show command -- now go through date_local(). PHP resolves its default timezone from the date.timezone ini setting, which Shirabe does not read, so date_default_timezone_get/set have no input left to model and are dropped from the shim and its callers. The resulting difference is recorded in docs/known-incompatibilities.md. Co-Authored-By: Claude Opus 5 (1M context) --- crates/shirabe/src/command/show_command.rs | 6 +++--- crates/shirabe/src/console/application.rs | 20 ++++++-------------- crates/shirabe/src/util/github.rs | 6 +++--- crates/shirabe/src/util/perforce.rs | 6 +++--- 4 files changed, 15 insertions(+), 23 deletions(-) (limited to 'crates/shirabe/src') diff --git a/crates/shirabe/src/command/show_command.rs b/crates/shirabe/src/command/show_command.rs index e5d5a1f2..f2246cbe 100644 --- a/crates/shirabe/src/command/show_command.rs +++ b/crates/shirabe/src/command/show_command.rs @@ -39,8 +39,8 @@ use indexmap::IndexMap; use shirabe_pcre::{CaptureKey, Preg}; use shirabe_php_shim::{ CmpOp, DATE_ATOM, InvalidArgumentException, LogicException, PhpMixed, UnexpectedValueException, - array_search, date, date_format_to_strftime, extension_loaded, impl_php_class, in_array_loose, - in_array_strict, php_regex, realpath, strtolower, version_compare, + array_search, date_format_to_strftime, date_local, extension_loaded, impl_php_class, + in_array_loose, in_array_strict, php_regex, realpath, strtolower, version_compare, }; use shirabe_semver::Semver; use shirabe_semver::constraint::AnyConstraint; @@ -1484,7 +1484,7 @@ impl ShowCommand { if release_date .format(date_format_to_strftime("Ymd")) .to_string() - == date("Ymd", None) + == date_local("Ymd", None) { return "today".to_string(); } diff --git a/crates/shirabe/src/console/application.rs b/crates/shirabe/src/console/application.rs index 3e4a746b..9a17868c 100644 --- a/crates/shirabe/src/console/application.rs +++ b/crates/shirabe/src/console/application.rs @@ -57,13 +57,12 @@ use crate::util::Silencer; use indexmap::IndexMap; use shirabe_php_shim::Catch as _; use shirabe_php_shim::{ - LogicException as ShimLogicException, PhpMixed, RuntimeException, bin2hex, chdir, - date_default_timezone_get, date_default_timezone_set, defined, dirname, disk_free_space, - extension_loaded, file_exists, file_get_contents, file_put_contents, function_exists, getcwd, - getmypid, glob, ini_set, is_array, is_dir, is_file, is_string, json_decode, - memory_get_peak_usage, memory_get_usage, microtime, php_regex, php_uname, posix_getuid, - random_bytes, realpath, restore_error_handler, round, str_replace, strpos, strtoupper, - sys_get_temp_dir, time, unlink, + LogicException as ShimLogicException, PhpMixed, RuntimeException, bin2hex, chdir, defined, + dirname, disk_free_space, extension_loaded, file_exists, file_get_contents, file_put_contents, + function_exists, getcwd, getmypid, glob, ini_set, is_array, is_dir, is_file, is_string, + json_decode, memory_get_peak_usage, memory_get_usage, microtime, php_regex, php_uname, + posix_getuid, random_bytes, realpath, restore_error_handler, round, str_replace, strpos, + strtoupper, sys_get_temp_dir, time, unlink, }; use shirabe_seld_json_lint::ParsingException; use shirabe_symfony_console::application::Application as BaseApplication; @@ -157,13 +156,6 @@ impl Application { ini_set("xdebug.scream", "0"); } - if function_exists("date_default_timezone_set") - && function_exists("date_default_timezone_get") - { - let tz = Silencer::call(|| Ok(date_default_timezone_get())).unwrap_or_default(); - date_default_timezone_set(&tz); - } - let io: std::rc::Rc> = std::rc::Rc::new(std::cell::RefCell::new(NullIO::new())); diff --git a/crates/shirabe/src/util/github.rs b/crates/shirabe/src/util/github.rs index 26756ed0..25a95e57 100644 --- a/crates/shirabe/src/util/github.rs +++ b/crates/shirabe/src/util/github.rs @@ -10,7 +10,7 @@ use crate::util::ProcessExecutor; use indexmap::IndexMap; use shirabe_pcre::{CaptureKey, Preg}; use shirabe_php_shim::Catch as _; -use shirabe_php_shim::{PhpMixed, date, in_array_loose, php_regex, stripos, strtolower}; +use shirabe_php_shim::{PhpMixed, date_local, in_array_loose, php_regex, stripos, strtolower}; #[derive(Debug)] pub struct GitHub { @@ -106,7 +106,7 @@ impl GitHub { note += &format!(" on {}", output.trim()); } } - note += &format!(" {}", date("Y-m-d Hi", None)); + note += &format!(" {}", date_local("Y-m-d Hi", None)); let (local_name, auth_name): (Option, String) = { let cfg = self.config.borrow(); @@ -309,7 +309,7 @@ impl GitHub { let ts: i64 = value.trim().parse().unwrap_or(0); rate_limit.insert( "reset".to_string(), - PhpMixed::String(date("Y-m-d H:i:s", Some(ts))), + PhpMixed::String(date_local("Y-m-d H:i:s", Some(ts))), ); } _ => {} diff --git a/crates/shirabe/src/util/perforce.rs b/crates/shirabe/src/util/perforce.rs index 1820936c..246e37f5 100644 --- a/crates/shirabe/src/util/perforce.rs +++ b/crates/shirabe/src/util/perforce.rs @@ -8,7 +8,7 @@ use crate::util::ProcessExecutor; use indexmap::IndexMap; use shirabe_pcre::Preg; use shirabe_php_shim::{ - Exception, PHP_EOL, PhpMixed, PhpResource, chdir, date, explode, fclose, feof, fgets, + Exception, PHP_EOL, PhpMixed, PhpResource, chdir, date_local, explode, fclose, feof, fgets, file_get_contents, fopen, fwrite, gethostname, json_decode, php_regex, str_replace_array, strcmp, strlen, strpos, strrpos, substr, time, trim, }; @@ -414,7 +414,7 @@ impl Perforce { spec, format!( "Update: {}{}{}", - date("Y/m/d H:i:s", None), + date_local("Y/m/d H:i:s", None), PHP_EOL, PHP_EOL ), @@ -422,7 +422,7 @@ impl Perforce { ); fwrite( spec, - format!("Access: {}{}", date("Y/m/d H:i:s", None), PHP_EOL), + format!("Access: {}{}", date_local("Y/m/d H:i:s", None), PHP_EOL), None, ); fwrite( -- cgit v1.3.1-4-g156e