1#![warn(clippy::style)]
30#![warn(clippy::nursery)]
31#![warn(clippy::pedantic)]
32
33#[cfg(feature = "with-chrono")]
34pub mod chrono;
35pub mod duration;
36pub mod error;
37pub mod parser;
38pub mod stdtime;
39#[cfg(feature = "with-time")]
40pub mod time;
41
42#[cfg(test)]
43mod tests {
44 use super::*;
45
46 #[test]
47 fn test_stdtime_duration_parse_year() {
48 use std::time;
49
50 let duration_compare = time::Duration::from_secs(31_556_952);
51
52 if let Ok(duration) = parser::stdtime::parse("1 years") {
53 assert_eq!(duration_compare, duration);
54 } else {
55 panic!("Parse failure");
56 }
57
58 if let Ok(duration) = parser::stdtime::parse("1 year") {
59 assert_eq!(duration_compare, duration);
60 } else {
61 panic!("Parse failure");
62 }
63
64 if let Ok(duration) = parser::stdtime::parse("1 yrs") {
65 assert_eq!(duration_compare, duration);
66 } else {
67 panic!("Parse failure");
68 }
69
70 if let Ok(duration) = parser::stdtime::parse("1 yr") {
71 assert_eq!(duration_compare, duration);
72 } else {
73 panic!("Parse failure");
74 }
75
76 if let Ok(duration) = parser::stdtime::parse("1 y") {
77 assert_eq!(duration_compare, duration);
78 } else {
79 panic!("Parse failure");
80 }
81
82 if let Ok(duration) = parser::stdtime::parse("1y") {
83 assert_eq!(duration_compare, duration);
84 } else {
85 panic!("Parse failure");
86 }
87
88 if let Ok(duration) = parser::stdtime::parse("52.1775w") {
89 assert_eq!(duration_compare, duration);
90 } else {
91 panic!("Parse failure");
92 }
93
94 if let Ok(duration) = parser::stdtime::parse("365d5h49m12s") {
95 assert_eq!(duration_compare, duration);
96 } else {
97 panic!("Parse failure");
98 }
99
100 if let Ok(duration) = parser::stdtime::parse("365.2425d") {
101 assert_eq!(duration_compare, duration);
102 } else {
103 panic!("Parse failure");
104 }
105 }
106
107 #[test]
108 fn test_stdtime_duration_parse_month() {
109 use std::time;
110
111 let duration_compare = time::Duration::from_secs(2_629_746);
112
113 if let Ok(duration) = parser::stdtime::parse("1 months") {
114 assert_eq!(duration_compare, duration);
115 } else {
116 panic!("Parse failure");
117 }
118
119 if let Ok(duration) = parser::stdtime::parse("1 month") {
120 assert_eq!(duration_compare, duration);
121 } else {
122 panic!("Parse failure");
123 }
124
125 if let Ok(duration) = parser::stdtime::parse("1 mos") {
126 assert_eq!(duration_compare, duration);
127 } else {
128 panic!("Parse failure");
129 }
130
131 if let Ok(duration) = parser::stdtime::parse("1 mo") {
132 assert_eq!(duration_compare, duration);
133 } else {
134 panic!("Parse failure");
135 }
136
137 if let Ok(duration) = parser::stdtime::parse("1 M") {
138 assert_eq!(duration_compare, duration);
139 } else {
140 panic!("Parse failure");
141 }
142
143 if let Ok(duration) = parser::stdtime::parse("30d10h29m6s") {
144 assert_eq!(duration_compare, duration);
145 } else {
146 panic!("Parse failure");
147 }
148 }
149
150 #[test]
151 fn test_stdtime_duration_parse_week() {
152 use std::time;
153
154 let duration_compare = time::Duration::from_secs(604_800);
155
156 if let Ok(duration) = parser::stdtime::parse("1 weeks") {
157 assert_eq!(duration_compare, duration);
158 } else {
159 panic!("Parse failure");
160 }
161
162 if let Ok(duration) = parser::stdtime::parse("1 week") {
163 assert_eq!(duration_compare, duration);
164 } else {
165 panic!("Parse failure");
166 }
167
168 if let Ok(duration) = parser::stdtime::parse("1 w") {
169 assert_eq!(duration_compare, duration);
170 } else {
171 panic!("Parse failure");
172 }
173
174 if let Ok(duration) = parser::stdtime::parse("7d") {
175 assert_eq!(duration_compare, duration);
176 } else {
177 panic!("Parse failure");
178 }
179
180 if let Ok(duration) = parser::stdtime::parse("168h") {
181 assert_eq!(duration_compare, duration);
182 } else {
183 panic!("Parse failure");
184 }
185
186 if let Ok(duration) = parser::stdtime::parse("10080m") {
187 assert_eq!(duration_compare, duration);
188 } else {
189 panic!("Parse failure");
190 }
191 }
192
193 #[test]
194 fn test_stdtime_duration_parse_day() {
195 use std::time;
196
197 let duration_compare = time::Duration::from_secs(86_400);
198
199 if let Ok(duration) = parser::stdtime::parse("1 days") {
200 assert_eq!(duration_compare, duration);
201 } else {
202 panic!("Parse failure");
203 }
204
205 if let Ok(duration) = parser::stdtime::parse("1 day") {
206 assert_eq!(duration_compare, duration);
207 } else {
208 panic!("Parse failure");
209 }
210
211 if let Ok(duration) = parser::stdtime::parse("1 d") {
212 assert_eq!(duration_compare, duration);
213 } else {
214 panic!("Parse failure");
215 }
216
217 if let Ok(duration) = parser::stdtime::parse("24h") {
218 assert_eq!(duration_compare, duration);
219 } else {
220 panic!("Parse failure");
221 }
222
223 if let Ok(duration) = parser::stdtime::parse("1440m") {
224 assert_eq!(duration_compare, duration);
225 } else {
226 panic!("Parse failure");
227 }
228
229 if let Ok(duration) = parser::stdtime::parse("86400s") {
230 assert_eq!(duration_compare, duration);
231 } else {
232 panic!("Parse failure");
233 }
234 }
235
236 #[test]
237 fn test_stdtime_duration_parse_hour() {
238 use std::time;
239
240 let duration_compare = time::Duration::from_secs(3600);
241
242 if let Ok(duration) = parser::stdtime::parse("1 hours") {
243 assert_eq!(duration_compare, duration);
244 } else {
245 panic!("Parse failure");
246 }
247
248 if let Ok(duration) = parser::stdtime::parse("1 hour") {
249 assert_eq!(duration_compare, duration);
250 } else {
251 panic!("Parse failure");
252 }
253
254 if let Ok(duration) = parser::stdtime::parse("1 hrs") {
255 assert_eq!(duration_compare, duration);
256 } else {
257 panic!("Parse failure");
258 }
259
260 if let Ok(duration) = parser::stdtime::parse("1 hr") {
261 assert_eq!(duration_compare, duration);
262 } else {
263 panic!("Parse failure");
264 }
265
266 if let Ok(duration) = parser::stdtime::parse("1 h") {
267 assert_eq!(duration_compare, duration);
268 } else {
269 panic!("Parse failure");
270 }
271
272 if let Ok(duration) = parser::stdtime::parse("60m") {
273 assert_eq!(duration_compare, duration);
274 } else {
275 panic!("Parse failure");
276 }
277
278 if let Ok(duration) = parser::stdtime::parse("3600s") {
279 assert_eq!(duration_compare, duration);
280 } else {
281 panic!("Parse failure");
282 }
283
284 if let Ok(duration) = parser::stdtime::parse("3600000ms") {
285 assert_eq!(duration_compare, duration);
286 } else {
287 panic!("Parse failure");
288 }
289 }
290
291 #[test]
292 fn test_stdtime_duration_parse_minute() {
293 use std::time;
294
295 let duration_compare = time::Duration::from_secs(60);
296
297 if let Ok(duration) = parser::stdtime::parse("1 minutes") {
298 assert_eq!(duration_compare, duration);
299 } else {
300 panic!("Parse failure");
301 }
302
303 if let Ok(duration) = parser::stdtime::parse("1 minute") {
304 assert_eq!(duration_compare, duration);
305 } else {
306 panic!("Parse failure");
307 }
308
309 if let Ok(duration) = parser::stdtime::parse("1 mins") {
310 assert_eq!(duration_compare, duration);
311 } else {
312 panic!("Parse failure");
313 }
314
315 if let Ok(duration) = parser::stdtime::parse("1 min") {
316 assert_eq!(duration_compare, duration);
317 } else {
318 panic!("Parse failure");
319 }
320
321 if let Ok(duration) = parser::stdtime::parse("1 m") {
322 assert_eq!(duration_compare, duration);
323 } else {
324 panic!("Parse failure");
325 }
326
327 if let Ok(duration) = parser::stdtime::parse("60s") {
328 assert_eq!(duration_compare, duration);
329 } else {
330 panic!("Parse failure");
331 }
332
333 if let Ok(duration) = parser::stdtime::parse("60000ms") {
334 assert_eq!(duration_compare, duration);
335 } else {
336 panic!("Parse failure");
337 }
338 }
339
340 #[test]
341 fn test_stdtime_duration_parse_second() {
342 use std::time;
343
344 let duration_compare = time::Duration::from_secs(1);
345
346 if let Ok(duration) = parser::stdtime::parse("1 seconds") {
347 assert_eq!(duration_compare, duration);
348 } else {
349 panic!("Parse failure");
350 }
351
352 if let Ok(duration) = parser::stdtime::parse("1 second") {
353 assert_eq!(duration_compare, duration);
354 } else {
355 panic!("Parse failure");
356 }
357
358 if let Ok(duration) = parser::stdtime::parse("1 s") {
359 assert_eq!(duration_compare, duration);
360 } else {
361 panic!("Parse failure");
362 }
363
364 if let Ok(duration) = parser::stdtime::parse("1 sec") {
365 assert_eq!(duration_compare, duration);
366 } else {
367 panic!("Parse failure");
368 }
369
370 if let Ok(duration) = parser::stdtime::parse("1000ms") {
371 assert_eq!(duration_compare, duration);
372 } else {
373 panic!("Parse failure");
374 }
375
376 if let Ok(duration) = parser::stdtime::parse("1000000µs") {
377 assert_eq!(duration_compare, duration);
378 } else {
379 panic!("Parse failure");
380 }
381
382 if let Ok(duration) = parser::stdtime::parse("1000000000ns") {
383 assert_eq!(duration_compare, duration);
384 } else {
385 panic!("Parse failure");
386 }
387 }
388
389 #[test]
390 fn test_stdtime_duration_parse_millisecond() {
391 use std::time;
392
393 let duration_compare = time::Duration::from_millis(1);
394
395 if let Ok(duration) = parser::stdtime::parse("1 milliseconds") {
396 assert_eq!(duration_compare, duration);
397 } else {
398 panic!("Parse failure");
399 }
400
401 if let Ok(duration) = parser::stdtime::parse("1 millisecond") {
402 assert_eq!(duration_compare, duration);
403 } else {
404 panic!("Parse failure");
405 }
406
407 if let Ok(duration) = parser::stdtime::parse("1 msecs") {
408 assert_eq!(duration_compare, duration);
409 } else {
410 panic!("Parse failure");
411 }
412
413 if let Ok(duration) = parser::stdtime::parse("1 msec") {
414 assert_eq!(duration_compare, duration);
415 } else {
416 panic!("Parse failure");
417 }
418
419 if let Ok(duration) = parser::stdtime::parse("1 ms") {
420 assert_eq!(duration_compare, duration);
421 } else {
422 panic!("Parse failure");
423 }
424
425 if let Ok(duration) = parser::stdtime::parse("1000µs") {
426 assert_eq!(duration_compare, duration);
427 } else {
428 panic!("Parse failure");
429 }
430
431 if let Ok(duration) = parser::stdtime::parse("1000000ns") {
432 assert_eq!(duration_compare, duration);
433 } else {
434 panic!("Parse failure");
435 }
436 }
437
438 #[test]
439 fn test_stdtime_duration_parse_microsecond() {
440 use std::time;
441
442 let duration_compare = time::Duration::from_micros(1);
443
444 if let Ok(duration) = parser::stdtime::parse("1 microseconds") {
445 assert_eq!(duration_compare, duration);
446 } else {
447 panic!("Parse failure");
448 }
449
450 if let Ok(duration) = parser::stdtime::parse("1 microsecond") {
451 assert_eq!(duration_compare, duration);
452 } else {
453 panic!("Parse failure");
454 }
455
456 if let Ok(duration) = parser::stdtime::parse("1 µsecs") {
457 assert_eq!(duration_compare, duration);
458 } else {
459 panic!("Parse failure");
460 }
461
462 if let Ok(duration) = parser::stdtime::parse("1 µsec") {
463 assert_eq!(duration_compare, duration);
464 } else {
465 panic!("Parse failure");
466 }
467
468 if let Ok(duration) = parser::stdtime::parse("1 µs") {
469 assert_eq!(duration_compare, duration);
470 } else {
471 panic!("Parse failure");
472 }
473
474 if let Ok(duration) = parser::stdtime::parse("1 usecs") {
475 assert_eq!(duration_compare, duration);
476 } else {
477 panic!("Parse failure");
478 }
479
480 if let Ok(duration) = parser::stdtime::parse("1 usec") {
481 assert_eq!(duration_compare, duration);
482 } else {
483 panic!("Parse failure");
484 }
485
486 if let Ok(duration) = parser::stdtime::parse("1 us") {
487 assert_eq!(duration_compare, duration);
488 } else {
489 panic!("Parse failure");
490 }
491
492 if let Ok(duration) = parser::stdtime::parse("1000ns") {
493 assert_eq!(duration_compare, duration);
494 } else {
495 panic!("Parse failure");
496 }
497 }
498
499 #[test]
500 fn test_stdtime_duration_parse_nanosecond() {
501 use std::time;
502
503 let duration_compare = time::Duration::from_nanos(1);
504
505 if let Ok(duration) = parser::stdtime::parse("1 nanoseconds") {
506 assert_eq!(duration_compare, duration);
507 } else {
508 panic!("Parse failure");
509 }
510
511 if let Ok(duration) = parser::stdtime::parse("1 nanosecond") {
512 assert_eq!(duration_compare, duration);
513 } else {
514 panic!("Parse failure");
515 }
516
517 if let Ok(duration) = parser::stdtime::parse("1 ns") {
518 assert_eq!(duration_compare, duration);
519 } else {
520 panic!("Parse failure");
521 }
522 }
523
524 #[test]
525 fn test_stdtime_duration_negative_invalid() {
526 assert!(parser::stdtime::parse("-30d").is_err());
527 }
528
529 #[test]
530 fn test_time_duration_parse_year() {
531 let duration_compare = ::time::Duration::weeks(52)
532 + ::time::Duration::days(1)
533 + ::time::Duration::hours(5)
534 + ::time::Duration::minutes(49)
535 + ::time::Duration::seconds(12);
536
537 if let Ok(duration) = parser::time::parse("1 years") {
538 assert_eq!(duration_compare, duration);
539 } else {
540 panic!("Parse failure");
541 }
542
543 if let Ok(duration) = parser::time::parse("1 year") {
544 assert_eq!(duration_compare, duration);
545 } else {
546 panic!("Parse failure");
547 }
548
549 if let Ok(duration) = parser::time::parse("1 yrs") {
550 assert_eq!(duration_compare, duration);
551 } else {
552 panic!("Parse failure");
553 }
554
555 if let Ok(duration) = parser::time::parse("1 yr") {
556 assert_eq!(duration_compare, duration);
557 } else {
558 panic!("Parse failure");
559 }
560
561 if let Ok(duration) = parser::time::parse("1 y") {
562 assert_eq!(duration_compare, duration);
563 } else {
564 panic!("Parse failure");
565 }
566
567 if let Ok(duration) = parser::time::parse("1y") {
568 assert_eq!(duration_compare, duration);
569 } else {
570 panic!("Parse failure");
571 }
572
573 if let Ok(duration) = parser::time::parse("52.1775w") {
574 assert_eq!(duration_compare, duration);
575 } else {
576 panic!("Parse failure");
577 }
578
579 if let Ok(duration) = parser::time::parse("365d5h49m12s") {
580 assert_eq!(duration_compare, duration);
581 } else {
582 panic!("Parse failure");
583 }
584
585 if let Ok(duration) = parser::time::parse("365.2425d") {
586 assert_eq!(duration_compare, duration);
587 } else {
588 panic!("Parse failure");
589 }
590 }
591
592 #[test]
593 fn test_time_duration_parse_month() {
594 let duration_compare = ::time::Duration::weeks(4)
595 + ::time::Duration::days(2)
596 + ::time::Duration::hours(10)
597 + ::time::Duration::minutes(29)
598 + ::time::Duration::seconds(6);
599
600 if let Ok(duration) = parser::time::parse("1 months") {
601 assert_eq!(duration_compare, duration);
602 } else {
603 panic!("Parse failure");
604 }
605
606 if let Ok(duration) = parser::time::parse("1 month") {
607 assert_eq!(duration_compare, duration);
608 } else {
609 panic!("Parse failure");
610 }
611
612 if let Ok(duration) = parser::time::parse("1 mos") {
613 assert_eq!(duration_compare, duration);
614 } else {
615 panic!("Parse failure");
616 }
617
618 if let Ok(duration) = parser::time::parse("1 mo") {
619 assert_eq!(duration_compare, duration);
620 } else {
621 panic!("Parse failure");
622 }
623
624 if let Ok(duration) = parser::time::parse("1 M") {
625 assert_eq!(duration_compare, duration);
626 } else {
627 panic!("Parse failure");
628 }
629
630 if let Ok(duration) = parser::time::parse("30d10h29m6s") {
631 assert_eq!(duration_compare, duration);
632 } else {
633 panic!("Parse failure");
634 }
635 }
636
637 #[test]
638 fn test_time_duration_parse_week() {
639 let duration_compare = ::time::Duration::weeks(1);
640
641 if let Ok(duration) = parser::time::parse("1 weeks") {
642 assert_eq!(duration_compare, duration);
643 } else {
644 panic!("Parse failure");
645 }
646
647 if let Ok(duration) = parser::time::parse("1 week") {
648 assert_eq!(duration_compare, duration);
649 } else {
650 panic!("Parse failure");
651 }
652
653 if let Ok(duration) = parser::time::parse("1 w") {
654 assert_eq!(duration_compare, duration);
655 } else {
656 panic!("Parse failure");
657 }
658
659 if let Ok(duration) = parser::time::parse("7d") {
660 assert_eq!(duration_compare, duration);
661 } else {
662 panic!("Parse failure");
663 }
664
665 if let Ok(duration) = parser::time::parse("168h") {
666 assert_eq!(duration_compare, duration);
667 } else {
668 panic!("Parse failure");
669 }
670
671 if let Ok(duration) = parser::time::parse("10080m") {
672 assert_eq!(duration_compare, duration);
673 } else {
674 panic!("Parse failure");
675 }
676 }
677
678 #[test]
679 fn test_time_duration_parse_day() {
680 let duration_compare = ::time::Duration::days(1);
681
682 if let Ok(duration) = parser::time::parse("1 days") {
683 assert_eq!(duration_compare, duration);
684 } else {
685 panic!("Parse failure");
686 }
687
688 if let Ok(duration) = parser::time::parse("1 day") {
689 assert_eq!(duration_compare, duration);
690 } else {
691 panic!("Parse failure");
692 }
693
694 if let Ok(duration) = parser::time::parse("1 d") {
695 assert_eq!(duration_compare, duration);
696 } else {
697 panic!("Parse failure");
698 }
699
700 if let Ok(duration) = parser::time::parse("24h") {
701 assert_eq!(duration_compare, duration);
702 } else {
703 panic!("Parse failure");
704 }
705
706 if let Ok(duration) = parser::time::parse("1440m") {
707 assert_eq!(duration_compare, duration);
708 } else {
709 panic!("Parse failure");
710 }
711
712 if let Ok(duration) = parser::time::parse("86400s") {
713 assert_eq!(duration_compare, duration);
714 } else {
715 panic!("Parse failure");
716 }
717 }
718
719 #[test]
720 fn test_time_duration_parse_hour() {
721 let duration_compare = ::time::Duration::hours(1);
722
723 if let Ok(duration) = parser::time::parse("1 hours") {
724 assert_eq!(duration_compare, duration);
725 } else {
726 panic!("Parse failure");
727 }
728
729 if let Ok(duration) = parser::time::parse("1 hour") {
730 assert_eq!(duration_compare, duration);
731 } else {
732 panic!("Parse failure");
733 }
734
735 if let Ok(duration) = parser::time::parse("1 hrs") {
736 assert_eq!(duration_compare, duration);
737 } else {
738 panic!("Parse failure");
739 }
740
741 if let Ok(duration) = parser::time::parse("1 hr") {
742 assert_eq!(duration_compare, duration);
743 } else {
744 panic!("Parse failure");
745 }
746
747 if let Ok(duration) = parser::time::parse("1 h") {
748 assert_eq!(duration_compare, duration);
749 } else {
750 panic!("Parse failure");
751 }
752
753 if let Ok(duration) = parser::time::parse("60m") {
754 assert_eq!(duration_compare, duration);
755 } else {
756 panic!("Parse failure");
757 }
758
759 if let Ok(duration) = parser::time::parse("3600s") {
760 assert_eq!(duration_compare, duration);
761 } else {
762 panic!("Parse failure");
763 }
764
765 if let Ok(duration) = parser::time::parse("3600000ms") {
766 assert_eq!(duration_compare, duration);
767 } else {
768 panic!("Parse failure");
769 }
770 }
771
772 #[test]
773 fn test_time_duration_parse_minute() {
774 let duration_compare = ::time::Duration::minutes(1);
775
776 if let Ok(duration) = parser::time::parse("1 minutes") {
777 assert_eq!(duration_compare, duration);
778 } else {
779 panic!("Parse failure");
780 }
781
782 if let Ok(duration) = parser::time::parse("1 minute") {
783 assert_eq!(duration_compare, duration);
784 } else {
785 panic!("Parse failure");
786 }
787
788 if let Ok(duration) = parser::time::parse("1 mins") {
789 assert_eq!(duration_compare, duration);
790 } else {
791 panic!("Parse failure");
792 }
793
794 if let Ok(duration) = parser::time::parse("1 min") {
795 assert_eq!(duration_compare, duration);
796 } else {
797 panic!("Parse failure");
798 }
799
800 if let Ok(duration) = parser::time::parse("1 m") {
801 assert_eq!(duration_compare, duration);
802 } else {
803 panic!("Parse failure");
804 }
805
806 if let Ok(duration) = parser::time::parse("60s") {
807 assert_eq!(duration_compare, duration);
808 } else {
809 panic!("Parse failure");
810 }
811
812 if let Ok(duration) = parser::time::parse("60000ms") {
813 assert_eq!(duration_compare, duration);
814 } else {
815 panic!("Parse failure");
816 }
817 }
818
819 #[test]
820 fn test_time_duration_parse_second() {
821 let duration_compare = ::time::Duration::seconds(1);
822
823 if let Ok(duration) = parser::time::parse("1 seconds") {
824 assert_eq!(duration_compare, duration);
825 } else {
826 panic!("Parse failure");
827 }
828
829 if let Ok(duration) = parser::time::parse("1 second") {
830 assert_eq!(duration_compare, duration);
831 } else {
832 panic!("Parse failure");
833 }
834
835 if let Ok(duration) = parser::time::parse("1 s") {
836 assert_eq!(duration_compare, duration);
837 } else {
838 panic!("Parse failure");
839 }
840
841 if let Ok(duration) = parser::time::parse("1 sec") {
842 assert_eq!(duration_compare, duration);
843 } else {
844 panic!("Parse failure");
845 }
846
847 if let Ok(duration) = parser::time::parse("1000ms") {
848 assert_eq!(duration_compare, duration);
849 } else {
850 panic!("Parse failure");
851 }
852 }
853
854 #[test]
855 fn test_time_duration_parse_millisecond() {
856 let duration_compare = ::time::Duration::milliseconds(1);
857
858 if let Ok(duration) = parser::time::parse("1 milliseconds") {
859 assert_eq!(duration_compare, duration);
860 } else {
861 panic!("Parse failure");
862 }
863
864 if let Ok(duration) = parser::time::parse("1 millisecond") {
865 assert_eq!(duration_compare, duration);
866 } else {
867 panic!("Parse failure");
868 }
869
870 if let Ok(duration) = parser::time::parse("1 msecs") {
871 assert_eq!(duration_compare, duration);
872 } else {
873 panic!("Parse failure");
874 }
875
876 if let Ok(duration) = parser::time::parse("1 msec") {
877 assert_eq!(duration_compare, duration);
878 } else {
879 panic!("Parse failure");
880 }
881
882 if let Ok(duration) = parser::time::parse("1 ms") {
883 assert_eq!(duration_compare, duration);
884 } else {
885 panic!("Parse failure");
886 }
887
888 if let Ok(duration) = parser::time::parse("1000µs") {
889 assert_eq!(duration_compare, duration);
890 } else {
891 panic!("Parse failure");
892 }
893
894 if let Ok(duration) = parser::time::parse("1000000ns") {
895 assert_eq!(duration_compare, duration);
896 } else {
897 panic!("Parse failure");
898 }
899 }
900
901 #[test]
902 fn test_time_duration_parse_microsecond() {
903 let duration_compare = ::time::Duration::microseconds(1);
904
905 if let Ok(duration) = parser::time::parse("1 microseconds") {
906 assert_eq!(duration_compare, duration);
907 } else {
908 panic!("Parse failure");
909 }
910
911 if let Ok(duration) = parser::time::parse("1 microsecond") {
912 assert_eq!(duration_compare, duration);
913 } else {
914 panic!("Parse failure");
915 }
916
917 if let Ok(duration) = parser::time::parse("1 µsecs") {
918 assert_eq!(duration_compare, duration);
919 } else {
920 panic!("Parse failure");
921 }
922
923 if let Ok(duration) = parser::time::parse("1 µsec") {
924 assert_eq!(duration_compare, duration);
925 } else {
926 panic!("Parse failure");
927 }
928
929 if let Ok(duration) = parser::time::parse("1 µs") {
930 assert_eq!(duration_compare, duration);
931 } else {
932 panic!("Parse failure");
933 }
934
935 if let Ok(duration) = parser::time::parse("1 usecs") {
936 assert_eq!(duration_compare, duration);
937 } else {
938 panic!("Parse failure");
939 }
940
941 if let Ok(duration) = parser::time::parse("1 usec") {
942 assert_eq!(duration_compare, duration);
943 } else {
944 panic!("Parse failure");
945 }
946
947 if let Ok(duration) = parser::time::parse("1 us") {
948 assert_eq!(duration_compare, duration);
949 } else {
950 panic!("Parse failure");
951 }
952
953 if let Ok(duration) = parser::time::parse("1000ns") {
954 assert_eq!(duration_compare, duration);
955 } else {
956 panic!("Parse failure");
957 }
958 }
959
960 #[test]
961 fn test_time_duration_parse_nanosecond() {
962 let duration_compare = ::time::Duration::nanoseconds(1);
963
964 if let Ok(duration) = parser::time::parse("1 nanoseconds") {
965 assert_eq!(duration_compare, duration);
966 } else {
967 panic!("Parse failure");
968 }
969
970 if let Ok(duration) = parser::time::parse("1 nanosecond") {
971 assert_eq!(duration_compare, duration);
972 } else {
973 panic!("Parse failure");
974 }
975
976 if let Ok(duration) = parser::time::parse("1 ns") {
977 assert_eq!(duration_compare, duration);
978 } else {
979 panic!("Parse failure");
980 }
981 }
982
983 #[test]
984 fn test_time_duration_negative() {
985 let duration_compare = ::time::Duration::nanoseconds(-1) + ::time::Duration::seconds(-1);
986 if let Ok(duration) = parser::time::parse("-1s-1ns") {
987 assert_eq!(duration_compare, duration);
988 } else {
989 panic!("Parse failure");
990 }
991 }
992
993 #[test]
994 fn test_chrono_duration_parse_year() {
995 let duration_compare = ::chrono::TimeDelta::weeks(52)
996 + ::chrono::TimeDelta::days(1)
997 + ::chrono::TimeDelta::hours(5)
998 + ::chrono::TimeDelta::minutes(49)
999 + ::chrono::TimeDelta::seconds(12);
1000
1001 if let Ok(duration) = parser::chrono::parse("1 years") {
1002 assert_eq!(duration_compare, duration);
1003 } else {
1004 panic!("Parse failure");
1005 }
1006
1007 if let Ok(duration) = parser::chrono::parse("1 year") {
1008 assert_eq!(duration_compare, duration);
1009 } else {
1010 panic!("Parse failure");
1011 }
1012
1013 if let Ok(duration) = parser::chrono::parse("1 yrs") {
1014 assert_eq!(duration_compare, duration);
1015 } else {
1016 panic!("Parse failure");
1017 }
1018
1019 if let Ok(duration) = parser::chrono::parse("1 yr") {
1020 assert_eq!(duration_compare, duration);
1021 } else {
1022 panic!("Parse failure");
1023 }
1024
1025 if let Ok(duration) = parser::chrono::parse("1 y") {
1026 assert_eq!(duration_compare, duration);
1027 } else {
1028 panic!("Parse failure");
1029 }
1030
1031 if let Ok(duration) = parser::chrono::parse("1y") {
1032 assert_eq!(duration_compare, duration);
1033 } else {
1034 panic!("Parse failure");
1035 }
1036
1037 if let Ok(duration) = parser::chrono::parse("52.1775w") {
1038 assert_eq!(duration_compare, duration);
1039 } else {
1040 panic!("Parse failure");
1041 }
1042
1043 if let Ok(duration) = parser::chrono::parse("365d5h49m12s") {
1044 assert_eq!(duration_compare, duration);
1045 } else {
1046 panic!("Parse failure");
1047 }
1048
1049 if let Ok(duration) = parser::chrono::parse("365.2425d") {
1050 assert_eq!(duration_compare, duration);
1051 } else {
1052 panic!("Parse failure");
1053 }
1054 }
1055
1056 #[test]
1057 fn test_chrono_duration_parse_month() {
1058 let duration_compare = ::chrono::TimeDelta::weeks(4)
1059 + ::chrono::TimeDelta::days(2)
1060 + ::chrono::TimeDelta::hours(10)
1061 + ::chrono::TimeDelta::minutes(29)
1062 + ::chrono::TimeDelta::seconds(6);
1063
1064 if let Ok(duration) = parser::chrono::parse("1 months") {
1065 assert_eq!(duration_compare, duration);
1066 } else {
1067 panic!("Parse failure");
1068 }
1069
1070 if let Ok(duration) = parser::chrono::parse("1 month") {
1071 assert_eq!(duration_compare, duration);
1072 } else {
1073 panic!("Parse failure");
1074 }
1075
1076 if let Ok(duration) = parser::chrono::parse("1 mos") {
1077 assert_eq!(duration_compare, duration);
1078 } else {
1079 panic!("Parse failure");
1080 }
1081
1082 if let Ok(duration) = parser::chrono::parse("1 mo") {
1083 assert_eq!(duration_compare, duration);
1084 } else {
1085 panic!("Parse failure");
1086 }
1087
1088 if let Ok(duration) = parser::chrono::parse("1 M") {
1089 assert_eq!(duration_compare, duration);
1090 } else {
1091 panic!("Parse failure");
1092 }
1093
1094 if let Ok(duration) = parser::chrono::parse("30d10h29m6s") {
1095 assert_eq!(duration_compare, duration);
1096 } else {
1097 panic!("Parse failure");
1098 }
1099 }
1100
1101 #[test]
1102 fn test_chrono_duration_parse_week() {
1103 let duration_compare = ::chrono::TimeDelta::weeks(1);
1104
1105 if let Ok(duration) = parser::chrono::parse("1 weeks") {
1106 assert_eq!(duration_compare, duration);
1107 } else {
1108 panic!("Parse failure");
1109 }
1110
1111 if let Ok(duration) = parser::chrono::parse("1 week") {
1112 assert_eq!(duration_compare, duration);
1113 } else {
1114 panic!("Parse failure");
1115 }
1116
1117 if let Ok(duration) = parser::chrono::parse("1 w") {
1118 assert_eq!(duration_compare, duration);
1119 } else {
1120 panic!("Parse failure");
1121 }
1122
1123 if let Ok(duration) = parser::chrono::parse("7d") {
1124 assert_eq!(duration_compare, duration);
1125 } else {
1126 panic!("Parse failure");
1127 }
1128
1129 if let Ok(duration) = parser::chrono::parse("168h") {
1130 assert_eq!(duration_compare, duration);
1131 } else {
1132 panic!("Parse failure");
1133 }
1134
1135 if let Ok(duration) = parser::chrono::parse("10080m") {
1136 assert_eq!(duration_compare, duration);
1137 } else {
1138 panic!("Parse failure");
1139 }
1140 }
1141
1142 #[test]
1143 fn test_chrono_duration_parse_day() {
1144 let duration_compare = ::chrono::TimeDelta::days(1);
1145
1146 if let Ok(duration) = parser::chrono::parse("1 days") {
1147 assert_eq!(duration_compare, duration);
1148 } else {
1149 panic!("Parse failure");
1150 }
1151
1152 if let Ok(duration) = parser::chrono::parse("1 day") {
1153 assert_eq!(duration_compare, duration);
1154 } else {
1155 panic!("Parse failure");
1156 }
1157
1158 if let Ok(duration) = parser::chrono::parse("1 d") {
1159 assert_eq!(duration_compare, duration);
1160 } else {
1161 panic!("Parse failure");
1162 }
1163
1164 if let Ok(duration) = parser::chrono::parse("24h") {
1165 assert_eq!(duration_compare, duration);
1166 } else {
1167 panic!("Parse failure");
1168 }
1169
1170 if let Ok(duration) = parser::chrono::parse("1440m") {
1171 assert_eq!(duration_compare, duration);
1172 } else {
1173 panic!("Parse failure");
1174 }
1175
1176 if let Ok(duration) = parser::chrono::parse("86400s") {
1177 assert_eq!(duration_compare, duration);
1178 } else {
1179 panic!("Parse failure");
1180 }
1181 }
1182
1183 #[test]
1184 fn test_chrono_duration_parse_hour() {
1185 let duration_compare = ::chrono::TimeDelta::hours(1);
1186
1187 if let Ok(duration) = parser::chrono::parse("1 hours") {
1188 assert_eq!(duration_compare, duration);
1189 } else {
1190 panic!("Parse failure");
1191 }
1192
1193 if let Ok(duration) = parser::chrono::parse("1 hour") {
1194 assert_eq!(duration_compare, duration);
1195 } else {
1196 panic!("Parse failure");
1197 }
1198
1199 if let Ok(duration) = parser::chrono::parse("1 hrs") {
1200 assert_eq!(duration_compare, duration);
1201 } else {
1202 panic!("Parse failure");
1203 }
1204
1205 if let Ok(duration) = parser::chrono::parse("1 hr") {
1206 assert_eq!(duration_compare, duration);
1207 } else {
1208 panic!("Parse failure");
1209 }
1210
1211 if let Ok(duration) = parser::chrono::parse("1 h") {
1212 assert_eq!(duration_compare, duration);
1213 } else {
1214 panic!("Parse failure");
1215 }
1216
1217 if let Ok(duration) = parser::chrono::parse("60m") {
1218 assert_eq!(duration_compare, duration);
1219 } else {
1220 panic!("Parse failure");
1221 }
1222
1223 if let Ok(duration) = parser::chrono::parse("3600s") {
1224 assert_eq!(duration_compare, duration);
1225 } else {
1226 panic!("Parse failure");
1227 }
1228
1229 if let Ok(duration) = parser::chrono::parse("3600000ms") {
1230 assert_eq!(duration_compare, duration);
1231 } else {
1232 panic!("Parse failure");
1233 }
1234 }
1235
1236 #[test]
1237 fn test_chrono_duration_parse_minute() {
1238 let duration_compare = ::chrono::TimeDelta::minutes(1);
1239
1240 if let Ok(duration) = parser::chrono::parse("1 minutes") {
1241 assert_eq!(duration_compare, duration);
1242 } else {
1243 panic!("Parse failure");
1244 }
1245
1246 if let Ok(duration) = parser::chrono::parse("1 minute") {
1247 assert_eq!(duration_compare, duration);
1248 } else {
1249 panic!("Parse failure");
1250 }
1251
1252 if let Ok(duration) = parser::chrono::parse("1 mins") {
1253 assert_eq!(duration_compare, duration);
1254 } else {
1255 panic!("Parse failure");
1256 }
1257
1258 if let Ok(duration) = parser::chrono::parse("1 min") {
1259 assert_eq!(duration_compare, duration);
1260 } else {
1261 panic!("Parse failure");
1262 }
1263
1264 if let Ok(duration) = parser::chrono::parse("1 m") {
1265 assert_eq!(duration_compare, duration);
1266 } else {
1267 panic!("Parse failure");
1268 }
1269
1270 if let Ok(duration) = parser::chrono::parse("60s") {
1271 assert_eq!(duration_compare, duration);
1272 } else {
1273 panic!("Parse failure");
1274 }
1275
1276 if let Ok(duration) = parser::chrono::parse("60000ms") {
1277 assert_eq!(duration_compare, duration);
1278 } else {
1279 panic!("Parse failure");
1280 }
1281 }
1282
1283 #[test]
1284 fn test_chrono_duration_parse_second() {
1285 let duration_compare = ::chrono::TimeDelta::seconds(1);
1286
1287 if let Ok(duration) = parser::chrono::parse("1 seconds") {
1288 assert_eq!(duration_compare, duration);
1289 } else {
1290 panic!("Parse failure");
1291 }
1292
1293 if let Ok(duration) = parser::chrono::parse("1 second") {
1294 assert_eq!(duration_compare, duration);
1295 } else {
1296 panic!("Parse failure");
1297 }
1298
1299 if let Ok(duration) = parser::chrono::parse("1 s") {
1300 assert_eq!(duration_compare, duration);
1301 } else {
1302 panic!("Parse failure");
1303 }
1304
1305 if let Ok(duration) = parser::chrono::parse("1 sec") {
1306 assert_eq!(duration_compare, duration);
1307 } else {
1308 panic!("Parse failure");
1309 }
1310
1311 if let Ok(duration) = parser::chrono::parse("1000ms") {
1312 assert_eq!(duration_compare, duration);
1313 } else {
1314 panic!("Parse failure");
1315 }
1316
1317 if let Ok(duration) = parser::chrono::parse("1000000us") {
1318 assert_eq!(duration_compare, duration);
1319 } else {
1320 panic!("Parse failure");
1321 }
1322
1323 if let Ok(duration) = parser::chrono::parse("1000000000ns") {
1324 assert_eq!(duration_compare, duration);
1325 } else {
1326 panic!("Parse failure");
1327 }
1328 }
1329
1330 #[test]
1331 fn test_chrono_duration_parse_millisecond() {
1332 let duration_compare = ::chrono::TimeDelta::milliseconds(1);
1333
1334 if let Ok(duration) = parser::chrono::parse("1 milliseconds") {
1335 assert_eq!(duration_compare, duration);
1336 } else {
1337 panic!("Parse failure");
1338 }
1339
1340 if let Ok(duration) = parser::chrono::parse("1 millisecond") {
1341 assert_eq!(duration_compare, duration);
1342 } else {
1343 panic!("Parse failure");
1344 }
1345
1346 if let Ok(duration) = parser::chrono::parse("1 msecs") {
1347 assert_eq!(duration_compare, duration);
1348 } else {
1349 panic!("Parse failure");
1350 }
1351
1352 if let Ok(duration) = parser::chrono::parse("1 msec") {
1353 assert_eq!(duration_compare, duration);
1354 } else {
1355 panic!("Parse failure");
1356 }
1357
1358 if let Ok(duration) = parser::chrono::parse("1 ms") {
1359 assert_eq!(duration_compare, duration);
1360 } else {
1361 panic!("Parse failure");
1362 }
1363
1364 if let Ok(duration) = parser::chrono::parse("1000µs") {
1365 assert_eq!(duration_compare, duration);
1366 } else {
1367 panic!("Parse failure");
1368 }
1369
1370 if let Ok(duration) = parser::chrono::parse("1000000ns") {
1371 assert_eq!(duration_compare, duration);
1372 } else {
1373 panic!("Parse failure");
1374 }
1375 }
1376
1377 #[test]
1378 fn test_chrono_duration_parse_microsecond() {
1379 let duration_compare = ::chrono::TimeDelta::microseconds(1);
1380
1381 if let Ok(duration) = parser::chrono::parse("1 microseconds") {
1382 assert_eq!(duration_compare, duration);
1383 } else {
1384 panic!("Parse failure");
1385 }
1386
1387 if let Ok(duration) = parser::chrono::parse("1 microsecond") {
1388 assert_eq!(duration_compare, duration);
1389 } else {
1390 panic!("Parse failure");
1391 }
1392
1393 if let Ok(duration) = parser::chrono::parse("1 µsecs") {
1394 assert_eq!(duration_compare, duration);
1395 } else {
1396 panic!("Parse failure");
1397 }
1398
1399 if let Ok(duration) = parser::chrono::parse("1 µsec") {
1400 assert_eq!(duration_compare, duration);
1401 } else {
1402 panic!("Parse failure");
1403 }
1404
1405 if let Ok(duration) = parser::chrono::parse("1 µs") {
1406 assert_eq!(duration_compare, duration);
1407 } else {
1408 panic!("Parse failure");
1409 }
1410
1411 if let Ok(duration) = parser::chrono::parse("1 usecs") {
1412 assert_eq!(duration_compare, duration);
1413 } else {
1414 panic!("Parse failure");
1415 }
1416
1417 if let Ok(duration) = parser::chrono::parse("1 usec") {
1418 assert_eq!(duration_compare, duration);
1419 } else {
1420 panic!("Parse failure");
1421 }
1422
1423 if let Ok(duration) = parser::chrono::parse("1 us") {
1424 assert_eq!(duration_compare, duration);
1425 } else {
1426 panic!("Parse failure");
1427 }
1428
1429 if let Ok(duration) = parser::chrono::parse("1000ns") {
1430 assert_eq!(duration_compare, duration);
1431 } else {
1432 panic!("Parse failure");
1433 }
1434 }
1435
1436 #[test]
1437 fn test_chrono_duration_parse_nanosecond() {
1438 let duration_compare = ::chrono::TimeDelta::nanoseconds(1);
1439
1440 if let Ok(duration) = parser::chrono::parse("1 nanoseconds") {
1441 assert_eq!(duration_compare, duration);
1442 } else {
1443 panic!("Parse failure");
1444 }
1445
1446 if let Ok(duration) = parser::chrono::parse("1 nanosecond") {
1447 assert_eq!(duration_compare, duration);
1448 } else {
1449 panic!("Parse failure");
1450 }
1451
1452 if let Ok(duration) = parser::chrono::parse("1 ns") {
1453 assert_eq!(duration_compare, duration);
1454 } else {
1455 panic!("Parse failure");
1456 }
1457 }
1458
1459 #[test]
1460 fn test_chrono_duration_negative() {
1461 let duration_compare =
1462 ::chrono::TimeDelta::nanoseconds(-1) + ::chrono::TimeDelta::seconds(-1);
1463 if let Ok(duration) = parser::chrono::parse("-1s-1ns") {
1464 assert_eq!(duration_compare, duration);
1465 } else {
1466 panic!("Parse failure");
1467 }
1468 }
1469
1470 #[test]
1471 fn test_duration_fractional() {
1472 use std::time;
1473
1474 let duration_compare = time::Duration::from_nanos(30_001);
1475
1476 if let Ok(duration) = parser::stdtime::parse("30.001µs") {
1477 assert_eq!(duration_compare, duration);
1478 } else {
1479 panic!("Parse failure");
1480 }
1481
1482 if let Ok(duration) = parser::stdtime::parse("0.000030001s") {
1483 assert_eq!(duration_compare, duration);
1484 } else {
1485 panic!("Parse failure");
1486 }
1487 }
1488
1489 #[test]
1490 fn test_duration_invalid() {
1491 assert!(parser::stdtime::parse("30p").is_err());
1492 }
1493}