8
8
9
9
//! This module implements conversion from/to `Value` for `time` v0.3.x crate types.
10
10
11
- #![ cfg( feature = "time03 " ) ]
11
+ #![ cfg( feature = "time " ) ]
12
12
13
13
use std:: { cmp:: Ordering , convert:: TryFrom , str:: from_utf8} ;
14
14
15
- use time03 :: {
15
+ use time :: {
16
16
error:: { Parse , TryFromParsed } ,
17
17
format_description:: {
18
18
modifier:: { self , Subsecond } ,
@@ -121,7 +121,7 @@ lazy_static::lazy_static! {
121
121
} ;
122
122
}
123
123
124
- #[ cfg_attr( docsrs, doc( cfg( feature = "time03 " ) ) ) ]
124
+ #[ cfg_attr( docsrs, doc( cfg( feature = "time " ) ) ) ]
125
125
impl TryFrom < Value > for ParseIr < PrimitiveDateTime > {
126
126
type Error = FromValueError ;
127
127
@@ -142,33 +142,33 @@ impl TryFrom<Value> for ParseIr<PrimitiveDateTime> {
142
142
}
143
143
}
144
144
145
- #[ cfg_attr( docsrs, doc( cfg( feature = "time03 " ) ) ) ]
145
+ #[ cfg_attr( docsrs, doc( cfg( feature = "time " ) ) ) ]
146
146
impl From < ParseIr < PrimitiveDateTime > > for PrimitiveDateTime {
147
147
fn from ( value : ParseIr < PrimitiveDateTime > ) -> Self {
148
148
value. commit ( )
149
149
}
150
150
}
151
151
152
- #[ cfg_attr( docsrs, doc( cfg( feature = "time03 " ) ) ) ]
152
+ #[ cfg_attr( docsrs, doc( cfg( feature = "time " ) ) ) ]
153
153
impl From < ParseIr < PrimitiveDateTime > > for Value {
154
154
fn from ( value : ParseIr < PrimitiveDateTime > ) -> Self {
155
155
value. rollback ( )
156
156
}
157
157
}
158
158
159
- #[ cfg_attr( docsrs, doc( cfg( feature = "time03 " ) ) ) ]
159
+ #[ cfg_attr( docsrs, doc( cfg( feature = "time " ) ) ) ]
160
160
impl FromValue for PrimitiveDateTime {
161
161
type Intermediate = ParseIr < PrimitiveDateTime > ;
162
162
}
163
163
164
- #[ cfg_attr( docsrs, doc( cfg( feature = "time03 " ) ) ) ]
164
+ #[ cfg_attr( docsrs, doc( cfg( feature = "time " ) ) ) ]
165
165
impl TryFrom < Value > for ParseIr < Date > {
166
166
type Error = FromValueError ;
167
167
168
168
fn try_from ( v : Value ) -> Result < Self , Self :: Error > {
169
169
match v {
170
170
Value :: Date ( year, month, day, _, _, _, _) => {
171
- let mon = match time03 :: Month :: try_from ( month) {
171
+ let mon = match time :: Month :: try_from ( month) {
172
172
Ok ( month) => month,
173
173
Err ( _) => return Err ( FromValueError ( v) ) ,
174
174
} ;
@@ -191,26 +191,26 @@ impl TryFrom<Value> for ParseIr<Date> {
191
191
}
192
192
}
193
193
194
- #[ cfg_attr( docsrs, doc( cfg( feature = "time03 " ) ) ) ]
194
+ #[ cfg_attr( docsrs, doc( cfg( feature = "time " ) ) ) ]
195
195
impl From < ParseIr < Date > > for Date {
196
196
fn from ( value : ParseIr < Date > ) -> Self {
197
197
value. commit ( )
198
198
}
199
199
}
200
200
201
- #[ cfg_attr( docsrs, doc( cfg( feature = "time03 " ) ) ) ]
201
+ #[ cfg_attr( docsrs, doc( cfg( feature = "time " ) ) ) ]
202
202
impl From < ParseIr < Date > > for Value {
203
203
fn from ( value : ParseIr < Date > ) -> Self {
204
204
value. rollback ( )
205
205
}
206
206
}
207
207
208
- #[ cfg_attr( docsrs, doc( cfg( feature = "time03 " ) ) ) ]
208
+ #[ cfg_attr( docsrs, doc( cfg( feature = "time " ) ) ) ]
209
209
impl FromValue for Date {
210
210
type Intermediate = ParseIr < Date > ;
211
211
}
212
212
213
- #[ cfg_attr( docsrs, doc( cfg( feature = "time03 " ) ) ) ]
213
+ #[ cfg_attr( docsrs, doc( cfg( feature = "time " ) ) ) ]
214
214
impl TryFrom < Value > for ParseIr < Time > {
215
215
type Error = FromValueError ;
216
216
@@ -229,25 +229,25 @@ impl TryFrom<Value> for ParseIr<Time> {
229
229
}
230
230
}
231
231
232
- #[ cfg_attr( docsrs, doc( cfg( feature = "time03 " ) ) ) ]
232
+ #[ cfg_attr( docsrs, doc( cfg( feature = "time " ) ) ) ]
233
233
impl From < ParseIr < Time > > for Time {
234
234
fn from ( value : ParseIr < Time > ) -> Self {
235
235
value. commit ( )
236
236
}
237
237
}
238
238
239
- #[ cfg_attr( docsrs, doc( cfg( feature = "time03 " ) ) ) ]
239
+ #[ cfg_attr( docsrs, doc( cfg( feature = "time " ) ) ) ]
240
240
impl From < ParseIr < Time > > for Value {
241
241
fn from ( value : ParseIr < Time > ) -> Self {
242
242
value. rollback ( )
243
243
}
244
244
}
245
245
246
- /// Converts a MySQL `TIME` value to a `time03 ::Time`.
247
- /// Note: `time03 ::Time` only allows for time values in the 00:00:00 - 23:59:59 range.
246
+ /// Converts a MySQL `TIME` value to a `time ::Time`.
247
+ /// Note: `time ::Time` only allows for time values in the 00:00:00 - 23:59:59 range.
248
248
/// If you're expecting `TIME` values in MySQL's `TIME` value range of -838:59:59 - 838:59:59,
249
- /// use time03 ::Duration instead.
250
- #[ cfg_attr( docsrs, doc( cfg( feature = "time03 " ) ) ) ]
249
+ /// use time ::Duration instead.
250
+ #[ cfg_attr( docsrs, doc( cfg( feature = "time " ) ) ) ]
251
251
impl FromValue for Time {
252
252
type Intermediate = ParseIr < Time > ;
253
253
}
@@ -261,7 +261,7 @@ fn create_primitive_date_time(
261
261
second : u8 ,
262
262
micros : u32 ,
263
263
) -> Option < PrimitiveDateTime > {
264
- let mon = time03 :: Month :: try_from ( month) . ok ( ) ?;
264
+ let mon = time :: Month :: try_from ( month) . ok ( ) ?;
265
265
if let Ok ( date) = Date :: from_calendar_date ( year as i32 , mon, day) {
266
266
if let Ok ( time) = Time :: from_hms_micro ( hour, minute, second, micros) {
267
267
return Some ( PrimitiveDateTime :: new ( date, time) ) ;
@@ -299,18 +299,18 @@ fn parse_mysql_time_string_with_time(bytes: &[u8]) -> Result<Time, Parse> {
299
299
} )
300
300
}
301
301
302
- #[ cfg_attr( docsrs, doc( cfg( feature = "time03 " ) ) ) ]
303
- impl TryFrom < Value > for ParseIr < time03 :: Duration > {
302
+ #[ cfg_attr( docsrs, doc( cfg( feature = "time " ) ) ) ]
303
+ impl TryFrom < Value > for ParseIr < time :: Duration > {
304
304
type Error = FromValueError ;
305
305
306
306
fn try_from ( v : Value ) -> Result < Self , Self :: Error > {
307
307
match v {
308
308
Value :: Time ( is_neg, days, hours, minutes, seconds, microseconds) => {
309
- let duration = time03 :: Duration :: days ( days. into ( ) )
310
- + time03 :: Duration :: hours ( hours. into ( ) )
311
- + time03 :: Duration :: minutes ( minutes. into ( ) )
312
- + time03 :: Duration :: seconds ( seconds. into ( ) )
313
- + time03 :: Duration :: microseconds ( microseconds. into ( ) ) ;
309
+ let duration = time :: Duration :: days ( days. into ( ) )
310
+ + time :: Duration :: hours ( hours. into ( ) )
311
+ + time :: Duration :: minutes ( minutes. into ( ) )
312
+ + time :: Duration :: seconds ( seconds. into ( ) )
313
+ + time :: Duration :: microseconds ( microseconds. into ( ) ) ;
314
314
Ok ( ParseIr ( if is_neg { -duration } else { duration } , v) )
315
315
}
316
316
Value :: Bytes ( ref val_bytes) => {
@@ -319,10 +319,10 @@ impl TryFrom<Value> for ParseIr<time03::Duration> {
319
319
// as it may contain an hour value that's outside of a day's normal 0-23 hour range.
320
320
let duration = match parse_mysql_time_string ( val_bytes) {
321
321
Some ( ( is_neg, hours, minutes, seconds, microseconds) ) => {
322
- let duration = time03 :: Duration :: hours ( hours. into ( ) )
323
- + time03 :: Duration :: minutes ( minutes. into ( ) )
324
- + time03 :: Duration :: seconds ( seconds. into ( ) )
325
- + time03 :: Duration :: microseconds ( microseconds. into ( ) ) ;
322
+ let duration = time :: Duration :: hours ( hours. into ( ) )
323
+ + time :: Duration :: minutes ( minutes. into ( ) )
324
+ + time :: Duration :: seconds ( seconds. into ( ) )
325
+ + time :: Duration :: microseconds ( microseconds. into ( ) ) ;
326
326
if is_neg {
327
327
-duration
328
328
} else {
@@ -338,26 +338,26 @@ impl TryFrom<Value> for ParseIr<time03::Duration> {
338
338
}
339
339
}
340
340
341
- #[ cfg_attr( docsrs, doc( cfg( feature = "time03 " ) ) ) ]
342
- impl From < ParseIr < time03 :: Duration > > for time03 :: Duration {
343
- fn from ( value : ParseIr < time03 :: Duration > ) -> Self {
341
+ #[ cfg_attr( docsrs, doc( cfg( feature = "time " ) ) ) ]
342
+ impl From < ParseIr < time :: Duration > > for time :: Duration {
343
+ fn from ( value : ParseIr < time :: Duration > ) -> Self {
344
344
value. commit ( )
345
345
}
346
346
}
347
347
348
- #[ cfg_attr( docsrs, doc( cfg( feature = "time03 " ) ) ) ]
349
- impl From < ParseIr < time03 :: Duration > > for Value {
350
- fn from ( value : ParseIr < time03 :: Duration > ) -> Self {
348
+ #[ cfg_attr( docsrs, doc( cfg( feature = "time " ) ) ) ]
349
+ impl From < ParseIr < time :: Duration > > for Value {
350
+ fn from ( value : ParseIr < time :: Duration > ) -> Self {
351
351
value. rollback ( )
352
352
}
353
353
}
354
354
355
- #[ cfg_attr( docsrs, doc( cfg( feature = "time03 " ) ) ) ]
356
- impl FromValue for time03 :: Duration {
357
- type Intermediate = ParseIr < time03 :: Duration > ;
355
+ #[ cfg_attr( docsrs, doc( cfg( feature = "time " ) ) ) ]
356
+ impl FromValue for time :: Duration {
357
+ type Intermediate = ParseIr < time :: Duration > ;
358
358
}
359
359
360
- #[ cfg_attr( docsrs, doc( cfg( feature = "time03 " ) ) ) ]
360
+ #[ cfg_attr( docsrs, doc( cfg( feature = "time " ) ) ) ]
361
361
impl From < PrimitiveDateTime > for Value {
362
362
fn from ( x : PrimitiveDateTime ) -> Value {
363
363
Value :: Date (
@@ -372,14 +372,14 @@ impl From<PrimitiveDateTime> for Value {
372
372
}
373
373
}
374
374
375
- #[ cfg_attr( docsrs, doc( cfg( feature = "time03 " ) ) ) ]
375
+ #[ cfg_attr( docsrs, doc( cfg( feature = "time " ) ) ) ]
376
376
impl From < Date > for Value {
377
377
fn from ( x : Date ) -> Value {
378
378
Value :: Date ( x. year ( ) as u16 , x. month ( ) as u8 , x. day ( ) , 0 , 0 , 0 , 0 )
379
379
}
380
380
}
381
381
382
- #[ cfg_attr( docsrs, doc( cfg( feature = "time03 " ) ) ) ]
382
+ #[ cfg_attr( docsrs, doc( cfg( feature = "time " ) ) ) ]
383
383
impl From < Time > for Value {
384
384
fn from ( x : Time ) -> Value {
385
385
Value :: Time (
@@ -393,23 +393,23 @@ impl From<Time> for Value {
393
393
}
394
394
}
395
395
396
- #[ cfg_attr( docsrs, doc( cfg( feature = "time03 " ) ) ) ]
397
- impl From < time03 :: Duration > for Value {
398
- fn from ( mut x : time03 :: Duration ) -> Value {
399
- let negative = x < time03 :: Duration :: ZERO ;
396
+ #[ cfg_attr( docsrs, doc( cfg( feature = "time " ) ) ) ]
397
+ impl From < time :: Duration > for Value {
398
+ fn from ( mut x : time :: Duration ) -> Value {
399
+ let negative = x < time :: Duration :: ZERO ;
400
400
401
401
if negative {
402
402
x = -x;
403
403
}
404
404
405
405
let days = x. whole_days ( ) as u32 ;
406
- x = x - time03 :: Duration :: days ( x. whole_days ( ) ) ;
406
+ x = x - time :: Duration :: days ( x. whole_days ( ) ) ;
407
407
let hours = x. whole_hours ( ) as u8 ;
408
- x = x - time03 :: Duration :: hours ( x. whole_hours ( ) ) ;
408
+ x = x - time :: Duration :: hours ( x. whole_hours ( ) ) ;
409
409
let minutes = x. whole_minutes ( ) as u8 ;
410
- x = x - time03 :: Duration :: minutes ( x. whole_minutes ( ) ) ;
410
+ x = x - time :: Duration :: minutes ( x. whole_minutes ( ) ) ;
411
411
let seconds = x. whole_seconds ( ) as u8 ;
412
- x = x - time03 :: Duration :: seconds ( x. whole_seconds ( ) ) ;
412
+ x = x - time :: Duration :: seconds ( x. whole_seconds ( ) ) ;
413
413
let microseconds = x. whole_microseconds ( ) as u32 ;
414
414
415
415
Value :: Time ( negative, days, hours, minutes, seconds, microseconds)
@@ -419,7 +419,7 @@ impl From<time03::Duration> for Value {
419
419
#[ cfg( test) ]
420
420
mod tests {
421
421
use proptest:: prelude:: * ;
422
- use time03 :: error:: ParseFromDescription ;
422
+ use time :: error:: ParseFromDescription ;
423
423
424
424
use super :: * ;
425
425
@@ -601,11 +601,11 @@ mod tests {
601
601
// we call `try_from_ymd` and `try_from_hms_micro`
602
602
// for each value separately.
603
603
604
- if Date :: from_calendar_date( y as i32 , time03 :: Month :: January , 1 ) . is_err( ) {
604
+ if Date :: from_calendar_date( y as i32 , time :: Month :: January , 1 ) . is_err( ) {
605
605
assert!( y != 0 && !( 1000 ..=9999 ) . contains( & y) ) ;
606
- } else if time03 :: Month :: try_from( m as u8 ) . is_err( ) {
606
+ } else if time :: Month :: try_from( m as u8 ) . is_err( ) {
607
607
assert!( m < 1000 || m <= 12 ) ;
608
- } else if Date :: from_calendar_date( 0 , time03 :: Month :: January , d as u8 ) . is_err( ) {
608
+ } else if Date :: from_calendar_date( 0 , time :: Month :: January , d as u8 ) . is_err( ) {
609
609
assert!( !( 1 ..=31 ) . contains( & d) ) ;
610
610
} else if Time :: from_hms_micro( h as u8 , 0 , 0 , 0 ) . is_err( ) {
611
611
assert!( /*h < 0 || */ h > 23 ) ;
0 commit comments