Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ ipnet = "2.3.0"
ipnetwork = "0.21.1"
mac_address = "1.1.5"
rust_decimal = { version = "1.36.0", default-features = false, features = ["std"] }
time = { version = "0.3.47", features = ["formatting", "parsing", "macros"] }
time = { version = "0.3.48", features = ["formatting", "parsing", "macros"] }
uuid = "1.12.1"

# Common utility crates
Expand Down
2 changes: 1 addition & 1 deletion examples/postgres/axum-social-with-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ rand = "0.10.1"
regex = "1.6.0"
serde = "1.0.219"
serde_with = { version = "3.18.0", features = ["time_0_3"] }
time = "0.3.47"
time = "0.3.48"
uuid = { version = "1.12.1", features = ["serde"] }
validator = { version = "0.20.0", features = ["derive"] }

Expand Down
2 changes: 1 addition & 1 deletion examples/postgres/multi-database/accounts/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ uuid = { version = "1.12.1", features = ["serde"] }
thiserror = "2.0.18"
rand = "0.10.1"

time = { version = "0.3.47", features = ["serde"] }
time = { version = "0.3.48", features = ["serde"] }

serde = { version = "1.0.219", features = ["derive"] }

Expand Down
2 changes: 1 addition & 1 deletion examples/postgres/multi-database/payments/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ sqlx = { workspace = true, features = ["postgres", "time", "uuid", "rust_decimal

rust_decimal = "1.36.0"

time = "0.3.47"
time = "0.3.48"
uuid = "1.12.1"

[dependencies.accounts]
Expand Down
2 changes: 1 addition & 1 deletion examples/postgres/multi-tenant/accounts/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ uuid = { version = "1.12.1", features = ["serde"] }
thiserror = "2.0.18"
rand = "0.10.1"

time = { version = "0.3.47", features = ["serde"] }
time = { version = "0.3.48", features = ["serde"] }

serde = { version = "1.0.219", features = ["derive"] }

Expand Down
2 changes: 1 addition & 1 deletion examples/postgres/multi-tenant/payments/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ edition = "2021"

rust_decimal = "1.36.0"

time = "0.3.47"
time = "0.3.48"
uuid = "1.12.1"

[dependencies.sqlx]
Expand Down
2 changes: 1 addition & 1 deletion examples/postgres/preferred-crates/uses-time/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ authors.workspace = true

[dependencies]
serde = "1.0.219"
time = "0.3.47"
time = "0.3.48"
uuid = "1.12.1"

[dependencies.sqlx]
Expand Down
141 changes: 12 additions & 129 deletions sqlx-sqlite/src/types/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,12 @@ fn decode_offset_datetime_from_text(value: &str) -> Option<OffsetDateTime> {
return Some(dt);
}

if let Ok(dt) = OffsetDateTime::parse(value, formats::OFFSET_DATE_TIME) {
if let Ok(dt) = OffsetDateTime::parse(
value,
&fd!(
"[year]-[month]-[day][optional [ ]][optional [T]][hour]:[minute][optional [:[second]]][optional [.[subsecond]]][optional [[offset_hour]]][optional [:[offset_minute]]]"
),
) {
return Some(dt);
}

Expand Down Expand Up @@ -181,8 +186,12 @@ fn decode_datetime_from_text(value: &str) -> Option<PrimitiveDateTime> {
}

let formats = [
BorrowedFormatItem::Compound(formats::PRIMITIVE_DATE_TIME_SPACE_SEPARATED),
BorrowedFormatItem::Compound(formats::PRIMITIVE_DATE_TIME_T_SEPARATED),
BorrowedFormatItem::Compound(fd!(
"[year]-[month]-[day] [hour]:[minute][optional [:[second]]][optional [.[subsecond]]][optional [Z]]"
)),
BorrowedFormatItem::Compound(fd!(
"[year]-[month]-[day]T[hour]:[minute][optional [:[second]]][optional [.[subsecond]]][optional [Z]]"
)),
];

if let Ok(dt) = PrimitiveDateTime::parse(value, &BorrowedFormatItem::First(&formats)) {
Expand All @@ -191,129 +200,3 @@ fn decode_datetime_from_text(value: &str) -> Option<PrimitiveDateTime> {

None
}

mod formats {
use time::format_description::BorrowedFormatItem::{Component, Literal, Optional};
use time::format_description::{modifier, BorrowedFormatItem, Component::*};

const YEAR: BorrowedFormatItem<'_> = Component(Year({
let mut value = modifier::Year::default();
value.padding = modifier::Padding::Zero;
value.repr = modifier::YearRepr::Full;
value.iso_week_based = false;
value.sign_is_mandatory = false;
value
}));

const MONTH: BorrowedFormatItem<'_> = Component(Month({
let mut value = modifier::Month::default();
value.padding = modifier::Padding::Zero;
value.repr = modifier::MonthRepr::Numerical;
value.case_sensitive = true;
value
}));

const DAY: BorrowedFormatItem<'_> = Component(Day({
let mut value = modifier::Day::default();
value.padding = modifier::Padding::Zero;
value
}));

const HOUR: BorrowedFormatItem<'_> = Component(Hour({
let mut value = modifier::Hour::default();
value.padding = modifier::Padding::Zero;
value.is_12_hour_clock = false;
value
}));

const MINUTE: BorrowedFormatItem<'_> = Component(Minute({
let mut value = modifier::Minute::default();
value.padding = modifier::Padding::Zero;
value
}));

const SECOND: BorrowedFormatItem<'_> = Component(Second({
let mut value = modifier::Second::default();
value.padding = modifier::Padding::Zero;
value
}));

const SUBSECOND: BorrowedFormatItem<'_> = Component(Subsecond({
let mut value = modifier::Subsecond::default();
value.digits = modifier::SubsecondDigits::OneOrMore;
value
}));

const OFFSET_HOUR: BorrowedFormatItem<'_> = Component(OffsetHour({
let mut value = modifier::OffsetHour::default();
value.sign_is_mandatory = true;
value.padding = modifier::Padding::Zero;
value
}));

const OFFSET_MINUTE: BorrowedFormatItem<'_> = Component(OffsetMinute({
let mut value = modifier::OffsetMinute::default();
value.padding = modifier::Padding::Zero;
value
}));

pub(super) const OFFSET_DATE_TIME: &[BorrowedFormatItem<'_>] = {
&[
YEAR,
Literal(b"-"),
MONTH,
Literal(b"-"),
DAY,
Optional(&Literal(b" ")),
Optional(&Literal(b"T")),
HOUR,
Literal(b":"),
MINUTE,
Optional(&Literal(b":")),
Optional(&SECOND),
Optional(&Literal(b".")),
Optional(&SUBSECOND),
Optional(&OFFSET_HOUR),
Optional(&Literal(b":")),
Optional(&OFFSET_MINUTE),
]
};

pub(super) const PRIMITIVE_DATE_TIME_SPACE_SEPARATED: &[BorrowedFormatItem<'_>] = {
&[
YEAR,
Literal(b"-"),
MONTH,
Literal(b"-"),
DAY,
Literal(b" "),
HOUR,
Literal(b":"),
MINUTE,
Optional(&Literal(b":")),
Optional(&SECOND),
Optional(&Literal(b".")),
Optional(&SUBSECOND),
Optional(&Literal(b"Z")),
]
};

pub(super) const PRIMITIVE_DATE_TIME_T_SEPARATED: &[BorrowedFormatItem<'_>] = {
&[
YEAR,
Literal(b"-"),
MONTH,
Literal(b"-"),
DAY,
Literal(b"T"),
HOUR,
Literal(b":"),
MINUTE,
Optional(&Literal(b":")),
Optional(&SECOND),
Optional(&Literal(b".")),
Optional(&SUBSECOND),
Optional(&Literal(b"Z")),
]
};
}
Loading