@@ -311,90 +311,42 @@ mod weekday;
311
311
312
312
pub use date:: Date ;
313
313
pub use duration:: Duration ;
314
+ pub use error:: Error ;
315
+ #[ deprecated(
316
+ since = "0.2.23" ,
317
+ note = "Errors have been moved to the `error` module."
318
+ ) ]
314
319
pub use error:: {
315
- ComponentRange as ComponentRangeError , ConversionRange as ConversionRangeError , Error ,
320
+ ComponentRange as ComponentRangeError , ConversionRange as ConversionRangeError ,
316
321
IndeterminateOffset as IndeterminateOffsetError , Parse as ParseError ,
317
322
} ;
323
+ #[ deprecated(
324
+ since = "0.2.23" ,
325
+ note = "Extension traits have been moved to the `ext` module."
326
+ ) ]
318
327
pub use ext:: { NumericalDuration , NumericalStdDuration , NumericalStdDurationShort } ;
319
328
pub ( crate ) use format:: DeferredFormat ;
320
329
pub use format:: Format ;
321
330
use format:: ParseResult ;
322
331
#[ cfg( feature = "std" ) ]
323
332
pub use instant:: Instant ;
333
+ #[ deprecated(
334
+ since = "0.2.23" ,
335
+ note = "Macros have been moved to the `macros` module."
336
+ ) ]
337
+ pub use macros:: { date, offset, time} ;
324
338
pub use offset_date_time:: OffsetDateTime ;
325
339
pub use primitive_date_time:: PrimitiveDateTime ;
326
340
#[ allow( deprecated) ]
327
341
pub use sign:: Sign ;
328
342
#[ allow( unused_imports) ]
329
343
use standback:: prelude:: * ;
330
- /// Construct a [`Date`](crate::Date) with a statically known value.
331
- ///
332
- /// The resulting expression can be used in `const` or `static` declarations.
333
- ///
334
- /// Three formats are supported: year-week-weekday, year-ordinal, and
335
- /// year-month-day.
336
- ///
337
- /// ```rust
338
- /// # use time::{Date, date, Weekday::*};
339
- /// # fn main() -> time::Result<()> {
340
- /// assert_eq!(date!(2020-W01-3), Date::try_from_iso_ywd(2020, 1, Wednesday)?);
341
- /// assert_eq!(date!(2020-001), Date::try_from_yo(2020, 1)?);
342
- /// assert_eq!(date!(2020-01-01), Date::try_from_ymd(2020, 1, 1)?);
343
- /// # Ok(())
344
- /// # }
345
- /// ```
346
- pub use time_macros:: date;
347
- /// Construct a [`UtcOffset`](crate::UtcOffset) with a statically known value.
348
- ///
349
- /// The resulting expression can be used in `const` or `static` declarations.
350
- ///
351
- /// A sign and the hour must be provided; minutes and seconds default to zero.
352
- /// `UTC` (both uppercase and lowercase) is also allowed.
353
- ///
354
- /// ```rust
355
- /// # use time::{offset, UtcOffset};
356
- /// assert_eq!(offset!(UTC), UtcOffset::hours(0));
357
- /// assert_eq!(offset!(utc), UtcOffset::hours(0));
358
- /// assert_eq!(offset!(+0), UtcOffset::hours(0));
359
- /// assert_eq!(offset!(+1), UtcOffset::hours(1));
360
- /// assert_eq!(offset!(-1), UtcOffset::hours(-1));
361
- /// assert_eq!(offset!(+1:30), UtcOffset::minutes(90));
362
- /// assert_eq!(offset!(-1:30), UtcOffset::minutes(-90));
363
- /// assert_eq!(offset!(+1:30:59), UtcOffset::seconds(5459));
364
- /// assert_eq!(offset!(-1:30:59), UtcOffset::seconds(-5459));
365
- /// assert_eq!(offset!(+23:59:59), UtcOffset::seconds(86_399));
366
- /// assert_eq!(offset!(-23:59:59), UtcOffset::seconds(-86_399));
367
- /// ```
368
- pub use time_macros:: offset;
369
- /// Construct a [`Time`](crate::Time) with a statically known value.
370
- ///
371
- /// The resulting expression can be used in `const` or `static` declarations.
372
- ///
373
- /// Hours and minutes must be provided, while seconds defaults to zero. AM/PM is
374
- /// allowed (either uppercase or lowercase). Any number of subsecond digits may
375
- /// be provided (though any past nine will be discarded).
376
- ///
377
- /// All components are validated at compile-time. An error will be raised if any
378
- /// value is invalid.
379
- ///
380
- /// ```rust
381
- /// # use time::{Time, time};
382
- /// # fn main() -> time::Result<()> {
383
- /// assert_eq!(time!(0:00), Time::try_from_hms(0, 0, 0)?);
384
- /// assert_eq!(time!(1:02:03), Time::try_from_hms(1, 2, 3)?);
385
- /// assert_eq!(time!(1:02:03.004_005_006), Time::try_from_hms_nano(1, 2, 3, 4_005_006)?);
386
- /// assert_eq!(time!(12:00 am), Time::try_from_hms(0, 0, 0)?);
387
- /// assert_eq!(time!(1:02:03 am), Time::try_from_hms(1, 2, 3)?);
388
- /// assert_eq!(time!(1:02:03.004_005_006 am), Time::try_from_hms_nano(1, 2, 3, 4_005_006)?);
389
- /// assert_eq!(time!(12:00 pm), Time::try_from_hms(12, 0, 0)?);
390
- /// assert_eq!(time!(1:02:03 pm), Time::try_from_hms(13, 2, 3)?);
391
- /// assert_eq!(time!(1:02:03.004_005_006 pm), Time::try_from_hms_nano(13, 2, 3, 4_005_006)?);
392
- /// # Ok(())
393
- /// # }
394
- /// ```
395
- pub use time_macros:: time;
396
344
pub use time_mod:: Time ;
397
345
pub use utc_offset:: UtcOffset ;
346
+ #[ deprecated(
347
+ since = "0.2.23" ,
348
+ note = "This function has been moved to the `util` module."
349
+ ) ]
398
350
pub use util:: { days_in_year, is_leap_year, validate_format_string, weeks_in_year} ;
399
351
pub use weekday:: Weekday ;
400
352
@@ -473,6 +425,77 @@ pub fn parse<T: private::Parsable>(s: impl AsRef<str>, format: impl AsRef<str>)
473
425
private:: Parsable :: parse ( s, format)
474
426
}
475
427
428
+ /// Macros to statically construct values that are known to be valid.
429
+ pub mod macros {
430
+
431
+ /// Construct a [`Date`](crate::Date) with a statically known value.
432
+ ///
433
+ /// The resulting expression can be used in `const` or `static` declarations.
434
+ ///
435
+ /// Three formats are supported: year-week-weekday, year-ordinal, and
436
+ /// year-month-day.
437
+ ///
438
+ /// ```rust
439
+ /// # use time::{Date, macros::date, Weekday::*};
440
+ /// # fn main() -> time::Result<()> {
441
+ /// assert_eq!(date!(2020-W01-3), Date::try_from_iso_ywd(2020, 1, Wednesday)?);
442
+ /// assert_eq!(date!(2020-001), Date::try_from_yo(2020, 1)?);
443
+ /// assert_eq!(date!(2020-01-01), Date::try_from_ymd(2020, 1, 1)?);
444
+ /// # Ok(())
445
+ /// # }
446
+ /// ```
447
+ pub use time_macros:: date;
448
+ /// Construct a [`UtcOffset`](crate::UtcOffset) with a statically known value.
449
+ ///
450
+ /// The resulting expression can be used in `const` or `static` declarations.
451
+ ///
452
+ /// A sign and the hour must be provided; minutes and seconds default to zero.
453
+ /// `UTC` (both uppercase and lowercase) is also allowed.
454
+ ///
455
+ /// ```rust
456
+ /// # use time::{macros::offset, UtcOffset};
457
+ /// assert_eq!(offset!(UTC), UtcOffset::hours(0));
458
+ /// assert_eq!(offset!(utc), UtcOffset::hours(0));
459
+ /// assert_eq!(offset!(+0), UtcOffset::hours(0));
460
+ /// assert_eq!(offset!(+1), UtcOffset::hours(1));
461
+ /// assert_eq!(offset!(-1), UtcOffset::hours(-1));
462
+ /// assert_eq!(offset!(+1:30), UtcOffset::minutes(90));
463
+ /// assert_eq!(offset!(-1:30), UtcOffset::minutes(-90));
464
+ /// assert_eq!(offset!(+1:30:59), UtcOffset::seconds(5459));
465
+ /// assert_eq!(offset!(-1:30:59), UtcOffset::seconds(-5459));
466
+ /// assert_eq!(offset!(+23:59:59), UtcOffset::seconds(86_399));
467
+ /// assert_eq!(offset!(-23:59:59), UtcOffset::seconds(-86_399));
468
+ /// ```
469
+ pub use time_macros:: offset;
470
+ /// Construct a [`Time`](crate::Time) with a statically known value.
471
+ ///
472
+ /// The resulting expression can be used in `const` or `static` declarations.
473
+ ///
474
+ /// Hours and minutes must be provided, while seconds defaults to zero. AM/PM is
475
+ /// allowed (either uppercase or lowercase). Any number of subsecond digits may
476
+ /// be provided (though any past nine will be discarded).
477
+ ///
478
+ /// All components are validated at compile-time. An error will be raised if any
479
+ /// value is invalid.
480
+ ///
481
+ /// ```rust
482
+ /// # use time::{Time, macros::time};
483
+ /// # fn main() -> time::Result<()> {
484
+ /// assert_eq!(time!(0:00), Time::try_from_hms(0, 0, 0)?);
485
+ /// assert_eq!(time!(1:02:03), Time::try_from_hms(1, 2, 3)?);
486
+ /// assert_eq!(time!(1:02:03.004_005_006), Time::try_from_hms_nano(1, 2, 3, 4_005_006)?);
487
+ /// assert_eq!(time!(12:00 am), Time::try_from_hms(0, 0, 0)?);
488
+ /// assert_eq!(time!(1:02:03 am), Time::try_from_hms(1, 2, 3)?);
489
+ /// assert_eq!(time!(1:02:03.004_005_006 am), Time::try_from_hms_nano(1, 2, 3, 4_005_006)?);
490
+ /// assert_eq!(time!(12:00 pm), Time::try_from_hms(12, 0, 0)?);
491
+ /// assert_eq!(time!(1:02:03 pm), Time::try_from_hms(13, 2, 3)?);
492
+ /// assert_eq!(time!(1:02:03.004_005_006 pm), Time::try_from_hms_nano(13, 2, 3, 4_005_006)?);
493
+ /// # Ok(())
494
+ /// # }
495
+ /// ```
496
+ pub use time_macros:: time;
497
+ }
498
+
476
499
// For some back-compatibility, we're also implementing some deprecated types
477
500
// and methods. They will be removed completely in 0.3.
478
501
0 commit comments