From 12435a50b379c011fa6aaf07f1208f8afa7dd1b4 Mon Sep 17 00:00:00 2001 From: robobun <117481402+robobun@users.noreply.github.com> Date: Sat, 15 Aug 2026 17:20:02 +0000 Subject: [PATCH] sql: replace the datetime text parser's two bool parameters with enums parse() took allow_date_only and allow_t_separator as bools, and both of its callers passed bare true/false. Each flag is now a two-variant enum (TimePart::{Optional, Required}, Separator::{Space, SpaceOrT}) so the call sites say which form they accept. No behavior change. Drops the corresponding bare_bool_args entry from mordant-baseline.toml. --- mordant-baseline.toml | 1 - src/sql_jsc/shared/datetime_text.rs | 31 ++++++++++++++++++++++++----- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/mordant-baseline.toml b/mordant-baseline.toml index 109483f7b029..c319791890b3 100644 --- a/mordant-baseline.toml +++ b/mordant-baseline.toml @@ -101,7 +101,6 @@ "bare_bool_args:src/shell_parser/parse.rs" = 1 [bun_sql_jsc] -"bare_bool_args:src/sql_jsc/shared/datetime_text.rs" = 1 "same_match_twice:src/sql_jsc/mysql/protocol/ResultSet.rs" = 1 [bun_sys] diff --git a/src/sql_jsc/shared/datetime_text.rs b/src/sql_jsc/shared/datetime_text.rs index 09f00496aca9..c1113c3ba7df 100644 --- a/src/sql_jsc/shared/datetime_text.rs +++ b/src/sql_jsc/shared/datetime_text.rs @@ -24,10 +24,25 @@ pub struct DateTimeText { pub(crate) microsecond: u32, } +/// Whether the 10-byte date-only form (`YYYY-MM-DD`) parses, or only the full +/// date-and-time shape does. +#[derive(Clone, Copy)] +enum TimePart { + Optional, + Required, +} + +/// Which bytes may separate the date from the time. +#[derive(Clone, Copy)] +enum Separator { + Space, + SpaceOrT, +} + /// MySQL DATE/DATETIME/TIMESTAMP text. Accepts the 10-byte date-only form /// (`YYYY-MM-DD`) and either `' '` or `'T'` as the date/time separator. pub(crate) fn parse_mysql(text: &[u8]) -> Option { - parse(text, true, true) + parse(text, TimePart::Optional, Separator::SpaceOrT) } /// Postgres `timestamp` (WITHOUT TIME ZONE) text. Requires the full @@ -35,10 +50,10 @@ pub(crate) fn parse_mysql(text: &[u8]) -> Option { /// separator, `infinity`, BC dates, 5+ digit years) returns `None` so the /// caller can fall back to `Date.parse`. pub(crate) fn parse_postgres_timestamp(text: &[u8]) -> Option { - parse(text, false, false) + parse(text, TimePart::Required, Separator::Space) } -fn parse(text: &[u8], allow_date_only: bool, allow_t_separator: bool) -> Option { +fn parse(text: &[u8], time_part: TimePart, separator: Separator) -> Option { fn parse_u(bytes: &[u8]) -> Option { if bytes.is_empty() { return None; @@ -63,10 +78,16 @@ fn parse(text: &[u8], allow_date_only: bool, allow_t_separator: bool) -> Option< ..Default::default() }; if text.len() == 10 { - return if allow_date_only { Some(result) } else { None }; + return match time_part { + TimePart::Optional => Some(result), + TimePart::Required => None, + }; } - let separator_ok = text[10] == b' ' || (allow_t_separator && text[10] == b'T'); + let separator_ok = match separator { + Separator::Space => text[10] == b' ', + Separator::SpaceOrT => text[10] == b' ' || text[10] == b'T', + }; if text.len() < 19 || !separator_ok || text[13] != b':' || text[16] != b':' { return None; }