From 1c0eb589741de4aa52ef941ff9315b34dbe48aa0 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Tue, 9 Jun 2026 00:00:12 +0900 Subject: feat(datetime): resolve datetime TODOs Introduce shim functions and constants, replacing the ad-hoc chrono format strings and parse helpers used as phase-b placeholders. Co-Authored-By: Claude Opus 4.8 (1M context) --- crates/shirabe-php-shim/Cargo.toml | 1 + crates/shirabe-php-shim/src/lib.rs | 24 +++++++++++++++++++++--- 2 files changed, 22 insertions(+), 3 deletions(-) (limited to 'crates/shirabe-php-shim') diff --git a/crates/shirabe-php-shim/Cargo.toml b/crates/shirabe-php-shim/Cargo.toml index 30e132f..b2a2077 100644 --- a/crates/shirabe-php-shim/Cargo.toml +++ b/crates/shirabe-php-shim/Cargo.toml @@ -5,6 +5,7 @@ edition.workspace = true [dependencies] anyhow.workspace = true +chrono.workspace = true indexmap.workspace = true serde.workspace = true zip.workspace = true diff --git a/crates/shirabe-php-shim/src/lib.rs b/crates/shirabe-php-shim/src/lib.rs index 835e1c1..433b8db 100644 --- a/crates/shirabe-php-shim/src/lib.rs +++ b/crates/shirabe-php-shim/src/lib.rs @@ -1740,8 +1740,6 @@ pub fn abs(_value: i64) -> i64 { todo!() } -pub const DATE_ATOM: &str = "Y-m-d\\TH:i:sP"; - pub fn ucfirst(_s: &str) -> String { todo!() } @@ -2409,7 +2407,6 @@ pub const OPENSSL_VERSION_NUMBER: i64 = 0; pub const OPENSSL_VERSION_TEXT: &str = ""; pub const PHP_BINARY: &str = ""; pub const PHP_WINDOWS_VERSION_BUILD: i64 = 0; -pub const DATE_RFC3339: &str = "Y-m-d\\TH:i:sP"; pub const PREG_BACKTRACK_LIMIT_ERROR: i64 = 2; #[derive(Debug, Clone)] @@ -2459,3 +2456,24 @@ pub fn zlib_decode(_data: &str) -> Option { pub const STREAM_NOTIFY_FAILURE: i64 = 9; pub const STREAM_NOTIFY_FILE_SIZE_IS: i64 = 5; pub const STREAM_NOTIFY_PROGRESS: i64 = 7; + +pub fn date_create(s: &str) -> chrono::ParseResult> { + todo!() +} + +/// PHP: \DATE_RFC3339 ("Y-m-d\TH:i:sP"). +pub const DATE_RFC3339: &str = "%Y-%m-%dT%H:%M:%S%:z"; + +/// PHP: \DATE_ATOM (equivalent to \DATE_RFC3339). +pub const DATE_ATOM: &str = DATE_RFC3339; + +/// Convert PHP-compatible date time format to strftime-compatible format. +/// Only the patterns Composer actually passes are supported; anything else panics. +pub fn date_format_to_strftime(format: &str) -> &'static str { + match format { + "Y-m-d H:i:s" => "%Y-%m-%d %H:%M:%S", + "Y-m-d" => "%Y-%m-%d", + "Ymd" => "%Y%m%d", + other => panic!("Unsupported PHP date format: {other:?}"), + } +} -- cgit v1.3.1