Skip to content

Commit f856433

Browse files
committed
style: formatting
1 parent 2cdb4da commit f856433

File tree

2 files changed

+32
-29
lines changed

2 files changed

+32
-29
lines changed

src/serializers/type_serializers/datetime_etc.rs

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,23 @@ pub(crate) fn datetime_to_string(py_dt: &Bound<'_, PyDateTime>) -> PyResult<Stri
1717
}
1818

1919
pub(crate) fn datetime_to_seconds(py_dt: &Bound<'_, PyDateTime>) -> PyResult<f64> {
20-
pydatetime_as_datetime(py_dt).map(|dt|
20+
pydatetime_as_datetime(py_dt).map(|dt| {
2121
dt.date.timestamp() as f64
22-
+ dt.time.hour as f64 * 3600.0
23-
+ dt.time.minute as f64 * 60.0
24-
+ dt.time.second as f64
25-
+ dt.time.microsecond as f64 / 1_000_000.0
26-
)
22+
+ f64::from(dt.time.hour) * 3600.0
23+
+ f64::from(dt.time.minute) * 60.0
24+
+ f64::from(dt.time.second)
25+
+ f64::from(dt.time.microsecond) / 1_000_000.0
26+
})
2727
}
2828

2929
pub(crate) fn datetime_to_milliseconds(py_dt: &Bound<'_, PyDateTime>) -> PyResult<f64> {
30-
pydatetime_as_datetime(py_dt).map(|dt|
30+
pydatetime_as_datetime(py_dt).map(|dt| {
3131
dt.date.timestamp_ms() as f64
32-
+ dt.time.hour as f64 * 3_600_000.0
33-
+ dt.time.minute as f64 * 60_000.0
34-
+ dt.time.second as f64 * 1_000.0
35-
+ dt.time.microsecond as f64 / 1_000.0
36-
)
32+
+ f64::from(dt.time.hour) * 3_600_000.0
33+
+ f64::from(dt.time.minute) * 60_000.0
34+
+ f64::from(dt.time.second) * 1_000.0
35+
+ f64::from(dt.time.microsecond) / 1_000.0
36+
})
3737
}
3838

3939
pub(crate) fn date_to_seconds(py_date: &Bound<'_, PyDate>) -> PyResult<f64> {
@@ -53,16 +53,19 @@ pub(crate) fn time_to_string(py_time: &Bound<'_, PyTime>) -> PyResult<String> {
5353

5454
pub(crate) fn time_to_seconds(py_time: &Bound<'_, PyTime>) -> PyResult<f64> {
5555
pytime_as_time(py_time, None).map(|t| {
56-
t.hour as f64 * 3600.0 + t.minute as f64 * 60.0 + t.second as f64 + t.microsecond as f64 / 1_000_000.0
56+
f64::from(t.hour) * 3600.0
57+
+ f64::from(t.minute) * 60.0
58+
+ f64::from(t.second)
59+
+ f64::from(t.microsecond) / 1_000_000.0
5760
})
5861
}
5962

6063
pub(crate) fn time_to_milliseconds(py_time: &Bound<'_, PyTime>) -> PyResult<f64> {
6164
pytime_as_time(py_time, None).map(|t| {
62-
t.hour as f64 * 3_600_000.0
63-
+ t.minute as f64 * 60_000.0
64-
+ t.second as f64 * 1_000.0
65-
+ t.microsecond as f64 / 1_000.0
65+
f64::from(t.hour) * 3_600_000.0
66+
+ f64::from(t.minute) * 60_000.0
67+
+ f64::from(t.second) * 1_000.0
68+
+ f64::from(t.microsecond) / 1_000.0
6669
})
6770
}
6871

tests/serializers/test_datetime.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -143,20 +143,20 @@ def test_date_datetime_union():
143143
'milliseconds',
144144
),
145145
(
146-
datetime(2024, 1, 1, 1, 1, 1, 23),
147-
1704070861.000023,
148-
b'1704070861.000023',
149-
{'1704070861.000023': 'foo'},
150-
b'{"1704070861.000023":"foo"}',
151-
'seconds',
146+
datetime(2024, 1, 1, 1, 1, 1, 23),
147+
1704070861.000023,
148+
b'1704070861.000023',
149+
{'1704070861.000023': 'foo'},
150+
b'{"1704070861.000023":"foo"}',
151+
'seconds',
152152
),
153153
(
154-
datetime(2024, 1, 1, 1, 1, 1, 23),
155-
1704070861000.023,
156-
b'1704070861000.023',
157-
{'1704070861000.023': 'foo'},
158-
b'{"1704070861000.023":"foo"}',
159-
'milliseconds',
154+
datetime(2024, 1, 1, 1, 1, 1, 23),
155+
1704070861000.023,
156+
b'1704070861000.023',
157+
{'1704070861000.023': 'foo'},
158+
b'{"1704070861000.023":"foo"}',
159+
'milliseconds',
160160
),
161161
],
162162
)

0 commit comments

Comments
 (0)