@@ -206,13 +206,10 @@ impl Date {
206206 /// assert_eq!(d.to_string(), "2022-06-07");
207207 /// ```
208208 pub fn from_timestamp ( timestamp : i64 , require_exact : bool ) -> Result < Self , ParseError > {
209- let ( timestamp_second, _) = Self :: timestamp_watershed ( timestamp) ?;
210- let d = Self :: from_timestamp_calc ( timestamp_second) ?;
211- if require_exact {
212- let time_second = timestamp_second. rem_euclid ( 86_400 ) ;
213- if time_second != 0 {
214- return Err ( ParseError :: DateNotExact ) ;
215- }
209+ let ( seconds, microseconds) = Self :: timestamp_watershed ( timestamp) ?;
210+ let ( d, remaining_seconds) = Self :: from_timestamp_calc ( seconds) ?;
211+ if require_exact && ( remaining_seconds != 0 || microseconds != 0 ) {
212+ return Err ( ParseError :: DateNotExact ) ;
216213 }
217214 Ok ( d)
218215 }
@@ -287,7 +284,7 @@ impl Date {
287284 Ok ( ( seconds, microseconds as u32 ) )
288285 }
289286
290- pub ( crate ) fn from_timestamp_calc ( timestamp_second : i64 ) -> Result < Self , ParseError > {
287+ pub ( crate ) fn from_timestamp_calc ( timestamp_second : i64 ) -> Result < ( Self , u32 ) , ParseError > {
291288 if timestamp_second < UNIX_1600 {
292289 return Err ( ParseError :: DateTooSmall ) ;
293290 }
@@ -312,7 +309,7 @@ impl Date {
312309 true => leap_year_month_day ( ordinal_day) ,
313310 false => common_year_month_day ( ordinal_day) ,
314311 } ;
315- Ok ( Self { year, month, day } )
312+ Ok ( ( Self { year, month, day } , ( timestamp_second . rem_euclid ( 86_400 ) ) as u32 ) )
316313 }
317314
318315 /// Parse a date from bytes, no check is performed for extract characters at the end of the string
0 commit comments