aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe-php-shim
diff options
context:
space:
mode:
Diffstat (limited to 'crates/shirabe-php-shim')
-rw-r--r--crates/shirabe-php-shim/src/array.rs17
-rw-r--r--crates/shirabe-php-shim/src/datetime.rs1
2 files changed, 10 insertions, 8 deletions
diff --git a/crates/shirabe-php-shim/src/array.rs b/crates/shirabe-php-shim/src/array.rs
index 280ec64..ace6a72 100644
--- a/crates/shirabe-php-shim/src/array.rs
+++ b/crates/shirabe-php-shim/src/array.rs
@@ -233,20 +233,21 @@ pub fn array_search_mixed(
haystack: &PhpMixed,
strict: bool,
) -> Option<PhpMixed> {
- if !strict {
- // TODO(phase-c): non-strict array_search needs PHP's loose `==` comparison
- // semantics. Only the strict path is implemented; loose comparison is
- // deferred rather than approximated.
- todo!("non-strict array_search (PHP loose comparison)");
- }
+ let matches = |value: &PhpMixed| -> bool {
+ if strict {
+ value == needle
+ } else {
+ loose_eq(value, needle)
+ }
+ };
match haystack {
PhpMixed::List(items) => items
.iter()
- .position(|value| value == needle)
+ .position(matches)
.map(|i| PhpMixed::Int(i as i64)),
PhpMixed::Array(map) => map
.iter()
- .find(|(_, value)| *value == needle)
+ .find(|(_, value)| matches(value))
.map(|(key, _)| php_key_to_mixed(key)),
_ => None,
}
diff --git a/crates/shirabe-php-shim/src/datetime.rs b/crates/shirabe-php-shim/src/datetime.rs
index bddf5da..e41028e 100644
--- a/crates/shirabe-php-shim/src/datetime.rs
+++ b/crates/shirabe-php-shim/src/datetime.rs
@@ -19,6 +19,7 @@ pub const DATE_ATOM: &str = DATE_RFC3339;
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 Hi" => "%Y-%m-%d %H%M",
"Y-m-d" => "%Y-%m-%d",
"Ymd" => "%Y%m%d",
other => panic!("Unsupported PHP date format: {other:?}"),