Skip to content

Commit 16a05d3

Browse files
authored
Update speedate to 0.11.0 (#769)
1 parent 3345f3e commit 16a05d3

File tree

7 files changed

+48
-32
lines changed

7 files changed

+48
-32
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ enum_dispatch = "0.3.8"
3535
serde = { version = "1.0.147", features = ["derive"] }
3636
# disabled for benchmarks since it makes microbenchmark performance more flakey
3737
mimalloc = { version = "0.1.30", optional = true, default-features = false, features = ["local_dynamic_tls"] }
38-
speedate = "0.10.0"
38+
speedate = "0.11.0"
3939
ahash = "0.8.0"
4040
url = "2.3.1"
4141
# idna is already required by url, added here to be explicit

src/input/datetime.rs

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ use speedate::{Date, DateTime, Duration, ParseError, Time, TimeConfig};
66
use std::borrow::Cow;
77
use strum::EnumMessage;
88

9-
use crate::errors::{ErrorType, ValError, ValResult};
10-
119
use super::Input;
10+
use crate::errors::{ErrorType, ValError, ValResult};
1211

1312
#[cfg_attr(debug_assertions, derive(Debug))]
1413
pub enum EitherDate<'a> {
@@ -272,8 +271,9 @@ pub fn bytes_as_time<'a>(
272271
) -> ValResult<'a, EitherTime<'a>> {
273272
match Time::parse_bytes_with_config(
274273
bytes,
275-
TimeConfig {
274+
&TimeConfig {
276275
microseconds_precision_overflow_behavior: microseconds_overflow_behavior,
276+
unix_timestamp_offset: Some(0),
277277
},
278278
) {
279279
Ok(date) => Ok(date.into()),
@@ -293,8 +293,9 @@ pub fn bytes_as_datetime<'a, 'b>(
293293
) -> ValResult<'a, EitherDateTime<'a>> {
294294
match DateTime::parse_bytes_with_config(
295295
bytes,
296-
TimeConfig {
296+
&TimeConfig {
297297
microseconds_precision_overflow_behavior: microseconds_overflow_behavior,
298+
unix_timestamp_offset: Some(0),
298299
},
299300
) {
300301
Ok(dt) => Ok(dt.into()),
@@ -312,7 +313,14 @@ pub fn int_as_datetime<'a>(
312313
timestamp: i64,
313314
timestamp_microseconds: u32,
314315
) -> ValResult<EitherDateTime> {
315-
match DateTime::from_timestamp(timestamp, timestamp_microseconds) {
316+
match DateTime::from_timestamp_with_config(
317+
timestamp,
318+
timestamp_microseconds,
319+
&TimeConfig {
320+
unix_timestamp_offset: Some(0),
321+
..Default::default()
322+
},
323+
) {
316324
Ok(dt) => Ok(dt.into()),
317325
Err(err) => Err(ValError::new(
318326
ErrorType::DatetimeParsing {
@@ -381,7 +389,14 @@ pub fn int_as_time<'a>(
381389
// ok
382390
t => t as u32,
383391
};
384-
match Time::from_timestamp(time_timestamp, timestamp_microseconds) {
392+
match Time::from_timestamp_with_config(
393+
time_timestamp,
394+
timestamp_microseconds,
395+
&TimeConfig {
396+
unix_timestamp_offset: Some(0),
397+
..Default::default()
398+
},
399+
) {
385400
Ok(dt) => Ok(dt.into()),
386401
Err(err) => Err(ValError::new(
387402
ErrorType::TimeParsing {
@@ -415,8 +430,9 @@ pub fn bytes_as_timedelta<'a, 'b>(
415430
) -> ValResult<'a, EitherTimedelta<'a>> {
416431
match Duration::parse_bytes_with_config(
417432
bytes,
418-
TimeConfig {
433+
&TimeConfig {
419434
microseconds_precision_overflow_behavior: microseconds_overflow_behavior,
435+
unix_timestamp_offset: Some(0),
420436
},
421437
) {
422438
Ok(dt) => Ok(dt.into()),

src/validators/date.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ fn date_from_datetime<'data>(
153153
minute: 0,
154154
second: 0,
155155
microsecond: 0,
156-
tz_offset: None,
156+
tz_offset: dt.time.tz_offset,
157157
};
158158
if dt.time == zero_time {
159159
Ok(EitherDate::Raw(dt.date))

tests/test_hypothesis.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def test_datetime_int(datetime_schema, data):
3636
except OverflowError:
3737
pytest.skip('OverflowError, see pyodide/pyodide#2841, this can happen on 32-bit systems')
3838
else:
39-
assert datetime_schema.validate_python(data) == expected, data
39+
assert datetime_schema.validate_python(data).replace(tzinfo=None) == expected, data
4040

4141

4242
@given(strategies.binary())

tests/validators/test_datetime.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,17 @@
1919
(datetime(2022, 6, 8, 12, 13, 14), datetime(2022, 6, 8, 12, 13, 14)),
2020
(date(2022, 6, 8), datetime(2022, 6, 8)),
2121
('2022-06-08T12:13:14', datetime(2022, 6, 8, 12, 13, 14)),
22-
('1000000000000', datetime(2001, 9, 9, 1, 46, 40)),
22+
('1000000000000', datetime(2001, 9, 9, 1, 46, 40, tzinfo=timezone.utc)),
2323
(b'2022-06-08T12:13:14', datetime(2022, 6, 8, 12, 13, 14)),
2424
(b'2022-06-08T12:13:14Z', datetime(2022, 6, 8, 12, 13, 14, tzinfo=timezone.utc)),
2525
((1,), Err('Input should be a valid datetime [type=datetime_type')),
2626
(time(1, 2, 3), Err('Input should be a valid datetime [type=datetime_type')),
27-
(Decimal('1654646400'), datetime(2022, 6, 8)),
28-
('1654646400', datetime(2022, 6, 8)),
29-
(Decimal('1654646400.123456'), datetime(2022, 6, 8, 0, 0, 0, 123456)),
30-
(Decimal('1654646400.1234564'), datetime(2022, 6, 8, 0, 0, 0, 123456)),
31-
(Decimal('1654646400.1234568'), datetime(2022, 6, 8, 0, 0, 0, 123457)),
32-
('1654646400.1234568', datetime(2022, 6, 8, 0, 0, 0, 123457)),
27+
(Decimal('1654646400'), datetime(2022, 6, 8, tzinfo=timezone.utc)),
28+
('1654646400', datetime(2022, 6, 8, tzinfo=timezone.utc)),
29+
(Decimal('1654646400.123456'), datetime(2022, 6, 8, 0, 0, 0, 123456, tzinfo=timezone.utc)),
30+
(Decimal('1654646400.1234564'), datetime(2022, 6, 8, 0, 0, 0, 123456, tzinfo=timezone.utc)),
31+
(Decimal('1654646400.1234568'), datetime(2022, 6, 8, 0, 0, 0, 123457, tzinfo=timezone.utc)),
32+
('1654646400.1234568', datetime(2022, 6, 8, 0, 0, 0, 123457, tzinfo=timezone.utc)),
3333
(253_402_300_800_000, Err('should be a valid datetime, dates after 9999 are not supported as unix timestamps')),
3434
(-20_000_000_000, Err('should be a valid datetime, dates before 1600 are not supported as unix timestamps')),
3535
(float('nan'), Err('Input should be a valid datetime, NaN values not permitted [type=datetime_parsing,')),
@@ -112,8 +112,8 @@ def test_keep_tz_bound():
112112
'2022-06-08T12:13:14+23:59',
113113
datetime(2022, 6, 8, 12, 13, 14, tzinfo=timezone(timedelta(hours=23, minutes=59))),
114114
),
115-
(1655205632, datetime(2022, 6, 14, 11, 20, 32)),
116-
(1655205632.331557, datetime(2022, 6, 14, 11, 20, 32, microsecond=331557)),
115+
(1655205632, datetime(2022, 6, 14, 11, 20, 32, tzinfo=timezone.utc)),
116+
(1655205632.331557, datetime(2022, 6, 14, 11, 20, 32, microsecond=331557, tzinfo=timezone.utc)),
117117
(
118118
'2022-06-08T12:13:14+24:00',
119119
Err('Input should be a valid datetime, timezone offset must be less than 24 hours [type=datetime_parsing,'),
@@ -290,7 +290,7 @@ def test_invalid_constraint():
290290
[
291291
('2022-06-08T12:13:14', datetime(2022, 6, 8, 12, 13, 14)),
292292
('2022-06-08T12:13:14Z', datetime(2022, 6, 8, 12, 13, 14, tzinfo=timezone.utc)),
293-
(1655205632, datetime(2022, 6, 14, 11, 20, 32)),
293+
(1655205632, datetime(2022, 6, 14, 11, 20, 32, tzinfo=timezone.utc)),
294294
('2068-06-08T12:13:14', Err('Input should be in the past [type=datetime_past,')),
295295
(3105730800, Err('Input should be in the past [type=datetime_past,')),
296296
],
@@ -333,7 +333,7 @@ def test_datetime_past_timezone():
333333
[
334334
('2068-06-08T12:13:14', datetime(2068, 6, 8, 12, 13, 14)),
335335
('2068-06-08T12:13:14Z', datetime(2068, 6, 8, 12, 13, 14, tzinfo=timezone.utc)),
336-
(3105730800, datetime(2068, 5, 31, 23, 0)),
336+
(3105730800, datetime(2068, 5, 31, 23, 0, tzinfo=timezone.utc)),
337337
('2022-06-08T12:13:14', Err('Input should be in the future [type=datetime_future,')),
338338
(1655205632, Err('Input should be in the future [type=datetime_future,')),
339339
],

tests/validators/test_time.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@
2222
pytest.param((1,), Err('Input should be a valid time [type=time_type'), id='tuple'),
2323
pytest.param(date(2022, 6, 8), Err('Input should be a valid time [type=time_type'), id='date'),
2424
pytest.param(datetime(2022, 6, 8), Err('Input should be a valid time [type=time_type'), id='datetime'),
25-
pytest.param(123, time(0, 2, 3), id='int'),
25+
pytest.param(123, time(0, 2, 3, tzinfo=timezone.utc), id='int'),
2626
pytest.param(float('nan'), Err('valid time format, NaN values not permitted [type=time_parsing,'), id='nan'),
2727
pytest.param(float('inf'), Err('valid time format, numeric times may not exceed 86,399 seconds'), id='inf'),
2828
pytest.param(float('-inf'), Err('valid time format, time in seconds should be positive'), id='-inf'),
29-
pytest.param(Decimal('123'), time(0, 2, 3), id='decimal'),
30-
pytest.param(Decimal('123.123456'), time(0, 2, 3, 123456), id='decimal-6dig'),
31-
pytest.param(Decimal('123.1234562'), time(0, 2, 3, 123456), id='decimal-7dig-up'),
32-
pytest.param(Decimal('123.1234568'), time(0, 2, 3, 123457), id='decimal-7dig-down'),
29+
pytest.param(Decimal('123'), time(0, 2, 3, tzinfo=timezone.utc), id='decimal'),
30+
pytest.param(Decimal('123.123456'), time(0, 2, 3, 123456, tzinfo=timezone.utc), id='decimal-6dig'),
31+
pytest.param(Decimal('123.1234562'), time(0, 2, 3, 123456, tzinfo=timezone.utc), id='decimal-7dig-up'),
32+
pytest.param(Decimal('123.1234568'), time(0, 2, 3, 123457, tzinfo=timezone.utc), id='decimal-7dig-down'),
3333
],
3434
)
3535
def test_time(input_value, expected):
@@ -50,10 +50,10 @@ def test_time(input_value, expected):
5050
pytest.param('12:13:14.123456', time(12, 13, 14, 123_456), id='str-micro-6dig'),
5151
pytest.param('12:13:14.123456', time(12, 13, 14, 123_456), id='str-micro-6dig'),
5252
pytest.param('12:13:14.1234561', time(12, 13, 14, 123_456), id='str-micro-7dig'),
53-
pytest.param(123, time(0, 2, 3), id='int'),
54-
pytest.param(123.4, time(0, 2, 3, 400_000), id='float'),
55-
pytest.param(123.0, time(0, 2, 3), id='float.0'),
56-
pytest.param(0, time(0), id='int-zero'),
53+
pytest.param(123, time(0, 2, 3, tzinfo=timezone.utc), id='int'),
54+
pytest.param(123.4, time(0, 2, 3, 400_000, tzinfo=timezone.utc), id='float'),
55+
pytest.param(123.0, time(0, 2, 3, tzinfo=timezone.utc), id='float.0'),
56+
pytest.param(0, time(0, tzinfo=timezone.utc), id='int-zero'),
5757
pytest.param(
5858
86400,
5959
Err(

0 commit comments

Comments
 (0)