@@ -17,11 +17,23 @@ pub(crate) fn datetime_to_string(py_dt: &Bound<'_, PyDateTime>) -> PyResult<Stri
1717}
1818
1919pub ( crate ) fn datetime_to_seconds ( py_dt : & Bound < ' _ , PyDateTime > ) -> PyResult < f64 > {
20- pydatetime_as_datetime ( py_dt) . map ( |dt| dt. timestamp ( ) as f64 )
20+ pydatetime_as_datetime ( py_dt) . map ( |dt|
21+ 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+ )
2127}
2228
2329pub ( crate ) fn datetime_to_milliseconds ( py_dt : & Bound < ' _ , PyDateTime > ) -> PyResult < f64 > {
24- pydatetime_as_datetime ( py_dt) . map ( |dt| dt. timestamp_ms ( ) as f64 )
30+ pydatetime_as_datetime ( py_dt) . map ( |dt|
31+ 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+ )
2537}
2638
2739pub ( crate ) fn date_to_seconds ( py_date : & Bound < ' _ , PyDate > ) -> PyResult < f64 > {
@@ -39,12 +51,19 @@ pub(crate) fn time_to_string(py_time: &Bound<'_, PyTime>) -> PyResult<String> {
3951 pytime_as_time ( py_time, None ) . map ( |dt| dt. to_string ( ) )
4052}
4153
42- pub ( crate ) fn time_to_seconds ( py_time : & Bound < ' _ , PyTime > ) -> PyResult < f32 > {
43- pytime_as_time ( py_time, None ) . map ( |t| t. total_seconds ( ) as f32 )
54+ pub ( crate ) fn time_to_seconds ( py_time : & Bound < ' _ , PyTime > ) -> PyResult < f64 > {
55+ 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
57+ } )
4458}
4559
46- pub ( crate ) fn time_to_milliseconds ( py_time : & Bound < ' _ , PyTime > ) -> PyResult < f32 > {
47- pytime_as_time ( py_time, None ) . map ( |t| t. total_ms ( ) as f32 )
60+ pub ( crate ) fn time_to_milliseconds ( py_time : & Bound < ' _ , PyTime > ) -> PyResult < f64 > {
61+ 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
66+ } )
4867}
4968
5069fn downcast_date_reject_datetime < ' a , ' py > ( py_date : & ' a Bound < ' py , PyAny > ) -> PyResult < & ' a Bound < ' py , PyDate > > {
0 commit comments