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