aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe-php-shim/src/datetime.rs
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2026-06-25 14:39:00 +0900
committernsfisis <nsfisis@gmail.com>2026-06-25 23:47:47 +0900
commitd0336078c5b63b174e7313d54d973a1832228928 (patch)
treeb0ed23c382e7ffd854fd3afb266a6932002e3335 /crates/shirabe-php-shim/src/datetime.rs
parenteebba7ebad103a2f7afe885a25ba2e96efddbd89 (diff)
downloadphp-shirabe-d0336078c5b63b174e7313d54d973a1832228928.tar.gz
php-shirabe-d0336078c5b63b174e7313d54d973a1832228928.tar.zst
php-shirabe-d0336078c5b63b174e7313d54d973a1832228928.zip
feat(external-packages,shim): implement impl todos across components
Port seld/jsonlint JsonParser (+hand-written Lexer), unblocking 10 json_file parse-error tests verified byte-for-byte against PHP. Implement Symfony Finder SplFileInfo, executable finders, String classes (byte/code-point/unicode), ZipArchive shim (via the zip crate), SPDX license validation, and shim date/stream functions. Genuinely-blocked sites (reflection, PHP runtime constants, non-UTF-8 transcoding, recursive PCRE) stay todo!() with reasons. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe-php-shim/src/datetime.rs')
-rw-r--r--crates/shirabe-php-shim/src/datetime.rs21
1 files changed, 19 insertions, 2 deletions
diff --git a/crates/shirabe-php-shim/src/datetime.rs b/crates/shirabe-php-shim/src/datetime.rs
index 9810966..bddf5da 100644
--- a/crates/shirabe-php-shim/src/datetime.rs
+++ b/crates/shirabe-php-shim/src/datetime.rs
@@ -1,6 +1,10 @@
static DEFAULT_TIMEZONE: std::sync::Mutex<Option<String>> = std::sync::Mutex::new(None);
pub fn date_create<Tz: chrono::TimeZone>(s: &str) -> chrono::ParseResult<chrono::DateTime<Tz>> {
+ // TODO(phase-d): PHP `date_create` accepts the full strtotime() grammar (RFC2822, ISO8601,
+ // VCS-specific and relative formats), which requires a dedicated date parser not available
+ // here. The generic `Tz` also has no constructor from a parsed `FixedOffset`/`Utc` value.
+ let _ = s;
todo!()
}
@@ -22,6 +26,8 @@ pub fn date_format_to_strftime(format: &str) -> &'static str {
}
pub fn strtotime(_time: &str) -> Option<i64> {
+ // TODO(phase-d): requires the full strtotime() grammar (absolute, relative and compound
+ // expressions); a partial parser would silently mis-handle unsupported inputs.
todo!()
}
@@ -53,6 +59,17 @@ pub fn date_default_timezone_set(tz: &str) -> bool {
true
}
-pub fn date(_format: &str, _timestamp: Option<i64>) -> String {
- todo!()
+pub fn date(format: &str, timestamp: Option<i64>) -> String {
+ let timestamp = timestamp.unwrap_or_else(time);
+ // PHP `date()` renders in the default timezone. Without a timezone database only "UTC" can be
+ // resolved; any named zone is rejected loudly rather than silently rendered in the wrong zone.
+ let tz = date_default_timezone_get();
+ if tz != "UTC" {
+ panic!(
+ "date() with non-UTC default timezone {tz:?} is not supported (no timezone database)"
+ );
+ }
+ let dt = chrono::DateTime::<chrono::Utc>::from_timestamp(timestamp, 0)
+ .expect("date() timestamp out of range");
+ dt.format(date_format_to_strftime(format)).to_string()
}