diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-06-21 15:49:24 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-06-21 15:49:37 +0900 |
| commit | fcef25f6ef36287a4984ffdaab39df84f5aceeba (patch) | |
| tree | 97ceb2098fbb5642e858929da9578bb41e277ada /crates/shirabe-php-shim/src/datetime.rs | |
| parent | f0f5f084c883dc4f5b6e61603e82cd1c2092fd9d (diff) | |
| download | php-shirabe-fcef25f6ef36287a4984ffdaab39df84f5aceeba.tar.gz php-shirabe-fcef25f6ef36287a4984ffdaab39df84f5aceeba.tar.zst php-shirabe-fcef25f6ef36287a4984ffdaab39df84f5aceeba.zip | |
refactor(php-shim): split lib.rs
Diffstat (limited to 'crates/shirabe-php-shim/src/datetime.rs')
| -rw-r--r-- | crates/shirabe-php-shim/src/datetime.rs | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/crates/shirabe-php-shim/src/datetime.rs b/crates/shirabe-php-shim/src/datetime.rs new file mode 100644 index 0000000..79c5ea2 --- /dev/null +++ b/crates/shirabe-php-shim/src/datetime.rs @@ -0,0 +1,55 @@ +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!() +} + +/// 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:?}"), + } +} + +pub fn strtotime(_time: &str) -> Option<i64> { + todo!() +} + +pub fn time() -> i64 { + std::time::SystemTime::now() + .duration_since(std::time::UNIX_EPOCH) + .unwrap() + .as_secs() as i64 +} + +pub fn microtime(_get_as_float: bool) -> f64 { + todo!() +} + +// PHP defaults to "UTC" when no default timezone has been configured. +pub fn date_default_timezone_get() -> String { + DEFAULT_TIMEZONE + .lock() + .unwrap() + .clone() + .unwrap_or_else(|| "UTC".to_string()) +} + +pub fn date_default_timezone_set(tz: &str) -> bool { + *DEFAULT_TIMEZONE.lock().unwrap() = Some(tz.to_string()); + true +} + +pub fn date(_format: &str, _timestamp: Option<i64>) -> String { + todo!() +} |
