@@ -11,6 +11,7 @@ use oldtime::Duration as OldDuration;
11
11
use { Weekday , Timelike , Datelike } ;
12
12
use offset:: { TimeZone , Offset } ;
13
13
use offset:: utc:: UTC ;
14
+ #[ cfg( feature="local" ) ]
14
15
use offset:: local:: Local ;
15
16
use offset:: fixed:: FixedOffset ;
16
17
use naive:: time:: NaiveTime ;
@@ -391,6 +392,7 @@ impl str::FromStr for DateTime<UTC> {
391
392
}
392
393
}
393
394
395
+ #[ cfg( feature="local" ) ]
394
396
impl str:: FromStr for DateTime < Local > {
395
397
type Err = ParseError ;
396
398
@@ -414,6 +416,7 @@ fn test_encodable_json<FUTC, FFixed, E>(to_string_utc: FUTC, to_string_fixed: FF
414
416
Some ( r#""2014-07-24T12:34:06+01:00:50""# . into( ) ) ) ;
415
417
}
416
418
419
+ #[ cfg( feature="local" ) ]
417
420
#[ cfg( all( test, any( feature = "rustc-serialize" , feature = "serde" ) ) ) ]
418
421
fn test_decodable_json < FUTC , FFixed , FLocal , E > ( utc_from_str : FUTC ,
419
422
fixed_from_str : FFixed ,
@@ -449,11 +452,40 @@ fn test_decodable_json<FUTC, FFixed, FLocal, E>(utc_from_str: FUTC,
449
452
assert ! ( fixed_from_str( r#""2014-07-32T12:34:06Z""# ) . is_err( ) ) ;
450
453
}
451
454
455
+ #[ cfg( not( feature="local" ) ) ]
456
+ #[ cfg( all( test, any( feature = "rustc-serialize" , feature = "serde" ) ) ) ]
457
+ fn test_decodable_json < FUTC , FFixed , E > ( utc_from_str : FUTC ,
458
+ fixed_from_str : FFixed ,
459
+ _dummy : FFixed )
460
+ where FUTC : Fn ( & str ) -> Result < DateTime < UTC > , E > ,
461
+ FFixed : Fn ( & str ) -> Result < DateTime < FixedOffset > , E > ,
462
+ E : :: std:: fmt:: Debug
463
+ {
464
+ // should check against the offset as well (the normal DateTime comparison will ignore them)
465
+ fn norm < Tz : TimeZone > ( dt : & Option < DateTime < Tz > > ) -> Option < ( & DateTime < Tz > , & Tz :: Offset ) > {
466
+ dt. as_ref ( ) . map ( |dt| ( dt, dt. offset ( ) ) )
467
+ }
468
+
469
+ assert_eq ! ( norm( & utc_from_str( r#""2014-07-24T12:34:06Z""# ) . ok( ) ) ,
470
+ norm( & Some ( UTC . ymd( 2014 , 7 , 24 ) . and_hms( 12 , 34 , 6 ) ) ) ) ;
471
+ assert_eq ! ( norm( & utc_from_str( r#""2014-07-24T13:57:06+01:23""# ) . ok( ) ) ,
472
+ norm( & Some ( UTC . ymd( 2014 , 7 , 24 ) . and_hms( 12 , 34 , 6 ) ) ) ) ;
473
+
474
+ assert_eq ! ( norm( & fixed_from_str( r#""2014-07-24T12:34:06Z""# ) . ok( ) ) ,
475
+ norm( & Some ( FixedOffset :: east( 0 ) . ymd( 2014 , 7 , 24 ) . and_hms( 12 , 34 , 6 ) ) ) ) ;
476
+ assert_eq ! ( norm( & fixed_from_str( r#""2014-07-24T13:57:06+01:23""# ) . ok( ) ) ,
477
+ norm( & Some ( FixedOffset :: east( 60 * 60 + 23 * 60 ) . ymd( 2014 , 7 , 24 ) . and_hms( 13 , 57 , 6 ) ) ) ) ;
478
+
479
+ assert ! ( utc_from_str( r#""2014-07-32T12:34:06Z""# ) . is_err( ) ) ;
480
+ assert ! ( fixed_from_str( r#""2014-07-32T12:34:06Z""# ) . is_err( ) ) ;
481
+ }
482
+
452
483
#[ cfg( feature = "rustc-serialize" ) ]
453
484
mod rustc_serialize {
454
485
use super :: DateTime ;
455
486
use offset:: TimeZone ;
456
487
use offset:: utc:: UTC ;
488
+ #[ cfg( feature="local" ) ]
457
489
use offset:: local:: Local ;
458
490
use offset:: fixed:: FixedOffset ;
459
491
use rustc_serialize:: { Encodable , Encoder , Decodable , Decoder } ;
@@ -482,6 +514,7 @@ mod rustc_serialize {
482
514
}
483
515
}
484
516
517
+ #[ cfg( feature="local" ) ]
485
518
impl Decodable for DateTime < Local > {
486
519
fn decode < D : Decoder > ( d : & mut D ) -> Result < DateTime < Local > , D :: Error > {
487
520
match d. read_str ( ) ?. parse :: < DateTime < FixedOffset > > ( ) {
@@ -510,6 +543,7 @@ mod serde {
510
543
use super :: DateTime ;
511
544
use offset:: TimeZone ;
512
545
use offset:: utc:: UTC ;
546
+ #[ cfg( feature="local" ) ]
513
547
use offset:: local:: Local ;
514
548
use offset:: fixed:: FixedOffset ;
515
549
use serde:: { ser, de} ;
@@ -558,6 +592,7 @@ mod serde {
558
592
}
559
593
}
560
594
595
+ #[ cfg( feature="local" ) ]
561
596
impl de:: Deserialize for DateTime < Local > {
562
597
fn deserialize < D > ( deserializer : D ) -> Result < Self , D :: Error >
563
598
where D : de:: Deserializer
@@ -597,11 +632,13 @@ mod serde {
597
632
#[ cfg( test) ]
598
633
mod tests {
599
634
use super :: DateTime ;
635
+ #[ cfg( feature="local" ) ]
600
636
use Datelike ;
601
637
use naive:: time:: NaiveTime ;
602
638
use naive:: date:: NaiveDate ;
603
639
use offset:: TimeZone ;
604
640
use offset:: utc:: UTC ;
641
+ #[ cfg( feature="local" ) ]
605
642
use offset:: local:: Local ;
606
643
use offset:: fixed:: FixedOffset ;
607
644
use oldtime:: Duration ;
@@ -676,6 +713,7 @@ mod tests {
676
713
}
677
714
678
715
#[ test]
716
+ #[ cfg( feature="local" ) ]
679
717
fn test_datetime_with_timezone ( ) {
680
718
let local_now = Local :: now ( ) ;
681
719
let utc_now = local_now. with_timezone ( & UTC ) ;
@@ -741,13 +779,15 @@ mod tests {
741
779
}
742
780
743
781
#[ test]
782
+ #[ cfg( feature="local" ) ]
744
783
fn test_datetime_format_with_local ( ) {
745
784
// if we are not around the year boundary, local and UTC date should have the same year
746
785
let dt = Local :: now ( ) . with_month ( 5 ) . unwrap ( ) ;
747
786
assert_eq ! ( dt. format( "%Y" ) . to_string( ) , dt. with_timezone( & UTC ) . format( "%Y" ) . to_string( ) ) ;
748
787
}
749
788
750
789
#[ test]
790
+ #[ cfg( feature="local" ) ]
751
791
fn test_datetime_is_copy ( ) {
752
792
// UTC is known to be `Copy`.
753
793
let a = UTC :: now ( ) ;
@@ -756,6 +796,7 @@ mod tests {
756
796
}
757
797
758
798
#[ test]
799
+ #[ cfg( feature="local" ) ]
759
800
fn test_datetime_is_send ( ) {
760
801
use std:: thread;
761
802
0 commit comments