Skip to content

Commit 62b14c0

Browse files
authored
Merge pull request #86 from thed0ct0r/fix/time03
time03->time
2 parents 48af363 + bab0318 commit 62b14c0

File tree

1 file changed

+54
-54
lines changed

1 file changed

+54
-54
lines changed

src/value/convert/time.rs

+54-54
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88

99
//! This module implements conversion from/to `Value` for `time` v0.3.x crate types.
1010
11-
#![cfg(feature = "time03")]
11+
#![cfg(feature = "time")]
1212

1313
use std::{cmp::Ordering, convert::TryFrom, str::from_utf8};
1414

15-
use time03::{
15+
use time::{
1616
error::{Parse, TryFromParsed},
1717
format_description::{
1818
modifier::{self, Subsecond},
@@ -121,7 +121,7 @@ lazy_static::lazy_static! {
121121
};
122122
}
123123

124-
#[cfg_attr(docsrs, doc(cfg(feature = "time03")))]
124+
#[cfg_attr(docsrs, doc(cfg(feature = "time")))]
125125
impl TryFrom<Value> for ParseIr<PrimitiveDateTime> {
126126
type Error = FromValueError;
127127

@@ -142,33 +142,33 @@ impl TryFrom<Value> for ParseIr<PrimitiveDateTime> {
142142
}
143143
}
144144

145-
#[cfg_attr(docsrs, doc(cfg(feature = "time03")))]
145+
#[cfg_attr(docsrs, doc(cfg(feature = "time")))]
146146
impl From<ParseIr<PrimitiveDateTime>> for PrimitiveDateTime {
147147
fn from(value: ParseIr<PrimitiveDateTime>) -> Self {
148148
value.commit()
149149
}
150150
}
151151

152-
#[cfg_attr(docsrs, doc(cfg(feature = "time03")))]
152+
#[cfg_attr(docsrs, doc(cfg(feature = "time")))]
153153
impl From<ParseIr<PrimitiveDateTime>> for Value {
154154
fn from(value: ParseIr<PrimitiveDateTime>) -> Self {
155155
value.rollback()
156156
}
157157
}
158158

159-
#[cfg_attr(docsrs, doc(cfg(feature = "time03")))]
159+
#[cfg_attr(docsrs, doc(cfg(feature = "time")))]
160160
impl FromValue for PrimitiveDateTime {
161161
type Intermediate = ParseIr<PrimitiveDateTime>;
162162
}
163163

164-
#[cfg_attr(docsrs, doc(cfg(feature = "time03")))]
164+
#[cfg_attr(docsrs, doc(cfg(feature = "time")))]
165165
impl TryFrom<Value> for ParseIr<Date> {
166166
type Error = FromValueError;
167167

168168
fn try_from(v: Value) -> Result<Self, Self::Error> {
169169
match v {
170170
Value::Date(year, month, day, _, _, _, _) => {
171-
let mon = match time03::Month::try_from(month) {
171+
let mon = match time::Month::try_from(month) {
172172
Ok(month) => month,
173173
Err(_) => return Err(FromValueError(v)),
174174
};
@@ -191,26 +191,26 @@ impl TryFrom<Value> for ParseIr<Date> {
191191
}
192192
}
193193

194-
#[cfg_attr(docsrs, doc(cfg(feature = "time03")))]
194+
#[cfg_attr(docsrs, doc(cfg(feature = "time")))]
195195
impl From<ParseIr<Date>> for Date {
196196
fn from(value: ParseIr<Date>) -> Self {
197197
value.commit()
198198
}
199199
}
200200

201-
#[cfg_attr(docsrs, doc(cfg(feature = "time03")))]
201+
#[cfg_attr(docsrs, doc(cfg(feature = "time")))]
202202
impl From<ParseIr<Date>> for Value {
203203
fn from(value: ParseIr<Date>) -> Self {
204204
value.rollback()
205205
}
206206
}
207207

208-
#[cfg_attr(docsrs, doc(cfg(feature = "time03")))]
208+
#[cfg_attr(docsrs, doc(cfg(feature = "time")))]
209209
impl FromValue for Date {
210210
type Intermediate = ParseIr<Date>;
211211
}
212212

213-
#[cfg_attr(docsrs, doc(cfg(feature = "time03")))]
213+
#[cfg_attr(docsrs, doc(cfg(feature = "time")))]
214214
impl TryFrom<Value> for ParseIr<Time> {
215215
type Error = FromValueError;
216216

@@ -229,25 +229,25 @@ impl TryFrom<Value> for ParseIr<Time> {
229229
}
230230
}
231231

232-
#[cfg_attr(docsrs, doc(cfg(feature = "time03")))]
232+
#[cfg_attr(docsrs, doc(cfg(feature = "time")))]
233233
impl From<ParseIr<Time>> for Time {
234234
fn from(value: ParseIr<Time>) -> Self {
235235
value.commit()
236236
}
237237
}
238238

239-
#[cfg_attr(docsrs, doc(cfg(feature = "time03")))]
239+
#[cfg_attr(docsrs, doc(cfg(feature = "time")))]
240240
impl From<ParseIr<Time>> for Value {
241241
fn from(value: ParseIr<Time>) -> Self {
242242
value.rollback()
243243
}
244244
}
245245

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.
248248
/// 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")))]
251251
impl FromValue for Time {
252252
type Intermediate = ParseIr<Time>;
253253
}
@@ -261,7 +261,7 @@ fn create_primitive_date_time(
261261
second: u8,
262262
micros: u32,
263263
) -> Option<PrimitiveDateTime> {
264-
let mon = time03::Month::try_from(month).ok()?;
264+
let mon = time::Month::try_from(month).ok()?;
265265
if let Ok(date) = Date::from_calendar_date(year as i32, mon, day) {
266266
if let Ok(time) = Time::from_hms_micro(hour, minute, second, micros) {
267267
return Some(PrimitiveDateTime::new(date, time));
@@ -299,18 +299,18 @@ fn parse_mysql_time_string_with_time(bytes: &[u8]) -> Result<Time, Parse> {
299299
})
300300
}
301301

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> {
304304
type Error = FromValueError;
305305

306306
fn try_from(v: Value) -> Result<Self, Self::Error> {
307307
match v {
308308
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());
314314
Ok(ParseIr(if is_neg { -duration } else { duration }, v))
315315
}
316316
Value::Bytes(ref val_bytes) => {
@@ -319,10 +319,10 @@ impl TryFrom<Value> for ParseIr<time03::Duration> {
319319
// as it may contain an hour value that's outside of a day's normal 0-23 hour range.
320320
let duration = match parse_mysql_time_string(val_bytes) {
321321
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());
326326
if is_neg {
327327
-duration
328328
} else {
@@ -338,26 +338,26 @@ impl TryFrom<Value> for ParseIr<time03::Duration> {
338338
}
339339
}
340340

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 {
344344
value.commit()
345345
}
346346
}
347347

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 {
351351
value.rollback()
352352
}
353353
}
354354

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>;
358358
}
359359

360-
#[cfg_attr(docsrs, doc(cfg(feature = "time03")))]
360+
#[cfg_attr(docsrs, doc(cfg(feature = "time")))]
361361
impl From<PrimitiveDateTime> for Value {
362362
fn from(x: PrimitiveDateTime) -> Value {
363363
Value::Date(
@@ -372,14 +372,14 @@ impl From<PrimitiveDateTime> for Value {
372372
}
373373
}
374374

375-
#[cfg_attr(docsrs, doc(cfg(feature = "time03")))]
375+
#[cfg_attr(docsrs, doc(cfg(feature = "time")))]
376376
impl From<Date> for Value {
377377
fn from(x: Date) -> Value {
378378
Value::Date(x.year() as u16, x.month() as u8, x.day(), 0, 0, 0, 0)
379379
}
380380
}
381381

382-
#[cfg_attr(docsrs, doc(cfg(feature = "time03")))]
382+
#[cfg_attr(docsrs, doc(cfg(feature = "time")))]
383383
impl From<Time> for Value {
384384
fn from(x: Time) -> Value {
385385
Value::Time(
@@ -393,23 +393,23 @@ impl From<Time> for Value {
393393
}
394394
}
395395

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;
400400

401401
if negative {
402402
x = -x;
403403
}
404404

405405
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());
407407
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());
409409
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());
411411
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());
413413
let microseconds = x.whole_microseconds() as u32;
414414

415415
Value::Time(negative, days, hours, minutes, seconds, microseconds)
@@ -419,7 +419,7 @@ impl From<time03::Duration> for Value {
419419
#[cfg(test)]
420420
mod tests {
421421
use proptest::prelude::*;
422-
use time03::error::ParseFromDescription;
422+
use time::error::ParseFromDescription;
423423

424424
use super::*;
425425

@@ -601,11 +601,11 @@ mod tests {
601601
// we call `try_from_ymd` and `try_from_hms_micro`
602602
// for each value separately.
603603

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() {
605605
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() {
607607
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() {
609609
assert!(!(1..=31).contains(&d));
610610
} else if Time::from_hms_micro(h as u8, 0, 0, 0).is_err() {
611611
assert!(/*h < 0 || */h > 23);

0 commit comments

Comments
 (0)