1
1
//! Types related to a time zone.
2
2
3
+ use super :: rule:: { AlternateTime , TransitionRule } ;
4
+ use super :: { parser, Error , DAYS_PER_WEEK , SECONDS_PER_DAY } ;
5
+ use crate :: NaiveDateTime ;
3
6
use std:: fs:: { self , File } ;
4
7
use std:: io:: { self , Read } ;
5
8
use std:: path:: { Path , PathBuf } ;
6
9
use std:: { cmp:: Ordering , fmt, str} ;
7
10
8
- use super :: rule:: { AlternateTime , TransitionRule } ;
9
- use super :: { parser, Error , DAYS_PER_WEEK , SECONDS_PER_DAY } ;
10
-
11
11
#[ cfg( target_env = "ohos" ) ]
12
12
use crate :: offset:: local:: tz_info:: parser:: Cursor ;
13
13
@@ -133,13 +133,11 @@ impl TimeZone {
133
133
self . as_ref ( ) . find_local_time_type ( unix_time)
134
134
}
135
135
136
- // should we pass NaiveDateTime all the way through to this fn?
137
136
pub ( crate ) fn find_local_time_type_from_local (
138
137
& self ,
139
- local_time : i64 ,
140
- year : i32 ,
138
+ local_time : NaiveDateTime ,
141
139
) -> Result < crate :: MappedLocalTime < LocalTimeType > , Error > {
142
- self . as_ref ( ) . find_local_time_type_from_local ( local_time, year )
140
+ self . as_ref ( ) . find_local_time_type_from_local ( local_time)
143
141
}
144
142
145
143
/// Returns a reference to the time zone
@@ -225,8 +223,7 @@ impl<'a> TimeZoneRef<'a> {
225
223
226
224
pub ( crate ) fn find_local_time_type_from_local (
227
225
& self ,
228
- local_time : i64 ,
229
- year : i32 ,
226
+ local_time : NaiveDateTime ,
230
227
) -> Result < crate :: MappedLocalTime < LocalTimeType > , Error > {
231
228
// #TODO: this is wrong as we need 'local_time_to_local_leap_time ?
232
229
// but ... does the local time even include leap seconds ??
@@ -235,10 +232,10 @@ impl<'a> TimeZoneRef<'a> {
235
232
// Err(Error::OutOfRange(error)) => return Err(Error::FindLocalTimeType(error)),
236
233
// Err(err) => return Err(err),
237
234
// };
238
- let local_leap_time = local_time;
235
+ let local_leap_time = local_time. and_utc ( ) . timestamp ( ) ;
239
236
240
237
// if we have at least one transition,
241
- // we must check _all_ of them, incase of any Overlapping (MappedLocalTime::Ambiguous) or Skipping (MappedLocalTime::None) transitions
238
+ // we must check _all_ of them, in case of any Overlapping (MappedLocalTime::Ambiguous) or Skipping (MappedLocalTime::None) transitions
242
239
let offset_after_last = if !self . transitions . is_empty ( ) {
243
240
let mut prev = self . local_time_types [ 0 ] ;
244
241
@@ -301,7 +298,7 @@ impl<'a> TimeZoneRef<'a> {
301
298
} ;
302
299
303
300
if let Some ( extra_rule) = self . extra_rule {
304
- match extra_rule. find_local_time_type_from_local ( local_time, year ) {
301
+ match extra_rule. find_local_time_type_from_local ( local_time) {
305
302
Ok ( local_time_type) => Ok ( local_time_type) ,
306
303
Err ( Error :: OutOfRange ( error) ) => Err ( Error :: FindLocalTimeType ( error) ) ,
307
304
err => err,
0 commit comments