@@ -10,7 +10,9 @@ use std::time::{SystemTime, UNIX_EPOCH};
10
10
use oldtime:: Duration as OldDuration ;
11
11
12
12
use { Weekday , Timelike , Datelike } ;
13
- use offset:: { TimeZone , Offset , Utc , Local , FixedOffset } ;
13
+ #[ cfg( feature="clock" ) ]
14
+ use offset:: Local ;
15
+ use offset:: { TimeZone , Offset , Utc , FixedOffset } ;
14
16
use naive:: { NaiveTime , NaiveDateTime , IsoWeek } ;
15
17
use Date ;
16
18
use format:: { Item , Numeric , Pad , Fixed } ;
@@ -532,6 +534,7 @@ impl str::FromStr for DateTime<Utc> {
532
534
}
533
535
}
534
536
537
+ #[ cfg( feature="clock" ) ]
535
538
impl str:: FromStr for DateTime < Local > {
536
539
type Err = ParseError ;
537
540
@@ -558,6 +561,7 @@ impl From<SystemTime> for DateTime<Utc> {
558
561
}
559
562
}
560
563
564
+ #[ cfg( feature="clock" ) ]
561
565
impl From < SystemTime > for DateTime < Local > {
562
566
fn from ( t : SystemTime ) -> DateTime < Local > {
563
567
DateTime :: < Utc > :: from ( t) . with_timezone ( & Local )
@@ -594,7 +598,7 @@ fn test_encodable_json<FUtc, FFixed, E>(to_string_utc: FUtc, to_string_fixed: FF
594
598
Some ( r#""2014-07-24T12:34:06+01:00:50""# . into( ) ) ) ;
595
599
}
596
600
597
- #[ cfg( all( test, any( feature = "rustc-serialize" , feature = "serde" ) ) ) ]
601
+ #[ cfg( all( test, feature= "clock" , any( feature = "rustc-serialize" , feature = "serde" ) ) ) ]
598
602
fn test_decodable_json < FUtc , FFixed , FLocal , E > ( utc_from_str : FUtc ,
599
603
fixed_from_str : FFixed ,
600
604
local_from_str : FLocal )
@@ -631,7 +635,7 @@ fn test_decodable_json<FUtc, FFixed, FLocal, E>(utc_from_str: FUtc,
631
635
assert ! ( fixed_from_str( r#""2014-07-32T12:34:06Z""# ) . is_err( ) ) ;
632
636
}
633
637
634
- #[ cfg( all( test, feature = "rustc-serialize" ) ) ]
638
+ #[ cfg( all( test, feature= "clock" , feature = "rustc-serialize" ) ) ]
635
639
fn test_decodable_json_timestamps < FUtc , FFixed , FLocal , E > ( utc_from_str : FUtc ,
636
640
fixed_from_str : FFixed ,
637
641
local_from_str : FLocal )
@@ -665,7 +669,9 @@ pub mod rustc_serialize {
665
669
use std:: fmt;
666
670
use std:: ops:: Deref ;
667
671
use super :: DateTime ;
668
- use offset:: { TimeZone , LocalResult , Utc , Local , FixedOffset } ;
672
+ #[ cfg( feature="clock" ) ]
673
+ use offset:: Local ;
674
+ use offset:: { TimeZone , LocalResult , Utc , FixedOffset } ;
669
675
use rustc_serialize:: { Encodable , Encoder , Decodable , Decoder } ;
670
676
671
677
impl < Tz : TimeZone > Encodable for DateTime < Tz > {
@@ -739,6 +745,7 @@ pub mod rustc_serialize {
739
745
}
740
746
}
741
747
748
+ #[ cfg( feature="clock" ) ]
742
749
impl Decodable for DateTime < Local > {
743
750
fn decode < D : Decoder > ( d : & mut D ) -> Result < DateTime < Local > , D :: Error > {
744
751
match d. read_str ( ) ?. parse :: < DateTime < FixedOffset > > ( ) {
@@ -748,6 +755,7 @@ pub mod rustc_serialize {
748
755
}
749
756
}
750
757
758
+ #[ cfg( feature="clock" ) ]
751
759
impl Decodable for TsSeconds < Local > {
752
760
fn decode < D : Decoder > ( d : & mut D ) -> Result < TsSeconds < Local > , D :: Error > {
753
761
from ( Utc . timestamp_opt ( d. read_i64 ( ) ?, 0 ) , d)
@@ -762,11 +770,13 @@ pub mod rustc_serialize {
762
770
super :: test_encodable_json ( json:: encode, json:: encode) ;
763
771
}
764
772
773
+ #[ cfg( feature="clock" ) ]
765
774
#[ test]
766
775
fn test_decodable ( ) {
767
776
super :: test_decodable_json ( json:: decode, json:: decode, json:: decode) ;
768
777
}
769
778
779
+ #[ cfg( feature="clock" ) ]
770
780
#[ test]
771
781
fn test_decodable_timestamps ( ) {
772
782
super :: test_decodable_json_timestamps ( json:: decode, json:: decode, json:: decode) ;
@@ -779,7 +789,9 @@ pub mod rustc_serialize {
779
789
pub mod serde {
780
790
use std:: fmt;
781
791
use super :: DateTime ;
782
- use offset:: { TimeZone , Utc , Local , FixedOffset } ;
792
+ #[ cfg( feature="clock" ) ]
793
+ use offset:: Local ;
794
+ use offset:: { TimeZone , Utc , FixedOffset } ;
783
795
use serdelib:: { ser, de} ;
784
796
785
797
/// Ser/de to/from timestamps in seconds
@@ -1015,6 +1027,7 @@ pub mod serde {
1015
1027
///
1016
1028
/// See [the `serde` module](./serde/index.html) for alternate
1017
1029
/// serialization formats.
1030
+ #[ cfg( feature="clock" ) ]
1018
1031
impl < ' de > de:: Deserialize < ' de > for DateTime < Local > {
1019
1032
fn deserialize < D > ( deserializer : D ) -> Result < Self , D :: Error >
1020
1033
where D : de:: Deserializer < ' de >
@@ -1031,6 +1044,7 @@ pub mod serde {
1031
1044
super :: test_encodable_json ( self :: serde_json:: to_string, self :: serde_json:: to_string) ;
1032
1045
}
1033
1046
1047
+ #[ cfg( feature="clock" ) ]
1034
1048
#[ test]
1035
1049
fn test_serde_deserialize ( ) {
1036
1050
super :: test_decodable_json ( |input| self :: serde_json:: from_str ( & input) , |input| self :: serde_json:: from_str ( & input) ,
@@ -1054,9 +1068,12 @@ pub mod serde {
1054
1068
#[ cfg( test) ]
1055
1069
mod tests {
1056
1070
use super :: DateTime ;
1071
+ #[ cfg( feature="clock" ) ]
1057
1072
use Datelike ;
1058
1073
use naive:: { NaiveTime , NaiveDate } ;
1059
- use offset:: { TimeZone , Utc , Local , FixedOffset } ;
1074
+ #[ cfg( feature="clock" ) ]
1075
+ use offset:: Local ;
1076
+ use offset:: { TimeZone , Utc , FixedOffset } ;
1060
1077
use oldtime:: Duration ;
1061
1078
use std:: time:: { SystemTime , UNIX_EPOCH } ;
1062
1079
@@ -1130,6 +1147,7 @@ mod tests {
1130
1147
}
1131
1148
1132
1149
#[ test]
1150
+ #[ cfg( feature="clock" ) ]
1133
1151
fn test_datetime_with_timezone ( ) {
1134
1152
let local_now = Local :: now ( ) ;
1135
1153
let utc_now = local_now. with_timezone ( & Utc ) ;
@@ -1225,13 +1243,15 @@ mod tests {
1225
1243
}
1226
1244
1227
1245
#[ test]
1246
+ #[ cfg( feature="clock" ) ]
1228
1247
fn test_datetime_format_with_local ( ) {
1229
1248
// if we are not around the year boundary, local and UTC date should have the same year
1230
1249
let dt = Local :: now ( ) . with_month ( 5 ) . unwrap ( ) ;
1231
1250
assert_eq ! ( dt. format( "%Y" ) . to_string( ) , dt. with_timezone( & Utc ) . format( "%Y" ) . to_string( ) ) ;
1232
1251
}
1233
1252
1234
1253
#[ test]
1254
+ #[ cfg( feature="clock" ) ]
1235
1255
fn test_datetime_is_copy ( ) {
1236
1256
// UTC is known to be `Copy`.
1237
1257
let a = Utc :: now ( ) ;
@@ -1240,6 +1260,7 @@ mod tests {
1240
1260
}
1241
1261
1242
1262
#[ test]
1263
+ #[ cfg( feature="clock" ) ]
1243
1264
fn test_datetime_is_send ( ) {
1244
1265
use std:: thread;
1245
1266
@@ -1280,7 +1301,9 @@ mod tests {
1280
1301
UNIX_EPOCH - Duration :: new( 999_999_999 , 999_999_999 ) ) ;
1281
1302
1282
1303
// DateTime<any tz> -> SystemTime (via `with_timezone`)
1283
- assert_eq ! ( SystemTime :: from( epoch. with_timezone( & Local ) ) , UNIX_EPOCH ) ;
1304
+ #[ cfg( feature="clock" ) ] {
1305
+ assert_eq ! ( SystemTime :: from( epoch. with_timezone( & Local ) ) , UNIX_EPOCH ) ;
1306
+ }
1284
1307
assert_eq ! ( SystemTime :: from( epoch. with_timezone( & FixedOffset :: east( 32400 ) ) ) , UNIX_EPOCH ) ;
1285
1308
assert_eq ! ( SystemTime :: from( epoch. with_timezone( & FixedOffset :: west( 28800 ) ) ) , UNIX_EPOCH ) ;
1286
1309
}
0 commit comments