@@ -14,9 +14,6 @@ pub use core_foundation_sys::date::*;
14
14
15
15
use crate :: base:: TCFType ;
16
16
17
- #[ cfg( feature = "with-chrono" ) ]
18
- use chrono:: NaiveDateTime ;
19
-
20
17
declare_TCFType ! {
21
18
/// A date.
22
19
CFDate , CFDateRef
@@ -43,45 +40,13 @@ impl CFDate {
43
40
pub fn abs_time ( & self ) -> CFAbsoluteTime {
44
41
unsafe { CFDateGetAbsoluteTime ( self . 0 ) }
45
42
}
46
-
47
- #[ cfg( feature = "with-chrono" ) ]
48
- pub fn naive_utc ( & self ) -> NaiveDateTime {
49
- let ts = unsafe { self . abs_time ( ) + kCFAbsoluteTimeIntervalSince1970 } ;
50
- let ( secs, nanos) = if ts. is_sign_positive ( ) {
51
- ( ts. trunc ( ) as i64 , ts. fract ( ) )
52
- } else {
53
- // nanoseconds can't be negative in NaiveDateTime
54
- ( ts. trunc ( ) as i64 - 1 , 1.0 - ts. fract ( ) . abs ( ) )
55
- } ;
56
- NaiveDateTime :: from_timestamp ( secs, ( nanos * 1e9 ) . floor ( ) as u32 )
57
- }
58
-
59
- #[ cfg( feature = "with-chrono" ) ]
60
- pub fn from_naive_utc ( time : NaiveDateTime ) -> CFDate {
61
- let secs = time. timestamp ( ) ;
62
- let nanos = time. timestamp_subsec_nanos ( ) ;
63
- let ts = unsafe { secs as f64 + ( nanos as f64 / 1e9 ) - kCFAbsoluteTimeIntervalSince1970 } ;
64
- CFDate :: new ( ts)
65
- }
66
43
}
67
44
68
45
#[ cfg( test) ]
69
46
mod test {
70
47
use super :: CFDate ;
71
48
use std:: cmp:: Ordering ;
72
49
73
- #[ cfg( feature = "with-chrono" ) ]
74
- use chrono:: NaiveDateTime ;
75
-
76
- #[ cfg( feature = "with-chrono" ) ]
77
- fn approx_eq ( a : f64 , b : f64 ) -> bool {
78
- use std:: f64;
79
-
80
- let same_sign = a. is_sign_positive ( ) == b. is_sign_positive ( ) ;
81
- let equal = ( ( a - b) . abs ( ) / f64:: min ( a. abs ( ) + b. abs ( ) , f64:: MAX ) ) < f64:: EPSILON ;
82
- same_sign && equal
83
- }
84
-
85
50
#[ test]
86
51
fn date_comparison ( ) {
87
52
let now = CFDate :: now ( ) ;
@@ -97,25 +62,4 @@ mod test {
97
62
let same_time = CFDate :: new ( now. abs_time ( ) ) ;
98
63
assert_eq ! ( now, same_time) ;
99
64
}
100
-
101
- #[ test]
102
- #[ cfg( feature = "with-chrono" ) ]
103
- fn date_chrono_conversion_positive ( ) {
104
- let date = CFDate :: now ( ) ;
105
- let datetime = date. naive_utc ( ) ;
106
- let converted = CFDate :: from_naive_utc ( datetime) ;
107
- assert ! ( approx_eq( date. abs_time( ) , converted. abs_time( ) ) ) ;
108
- }
109
-
110
- #[ test]
111
- #[ cfg( feature = "with-chrono" ) ]
112
- fn date_chrono_conversion_negative ( ) {
113
- use super :: kCFAbsoluteTimeIntervalSince1970;
114
-
115
- let ts = unsafe { kCFAbsoluteTimeIntervalSince1970 - 420.0 } ;
116
- let date = CFDate :: new ( ts) ;
117
- let datetime: NaiveDateTime = date. naive_utc ( ) ;
118
- let converted = CFDate :: from_naive_utc ( datetime) ;
119
- assert ! ( approx_eq( date. abs_time( ) , converted. abs_time( ) ) ) ;
120
- }
121
65
}
0 commit comments