|
403 | 403 | (deftest ordering
|
404 | 404 |
|
405 | 405 | (testing "times"
|
406 | | - (is (j/after? (j/local-date-time clock) (j/minus (j/local-date-time clock) (j/days 5)))) |
407 | | - (is (j/before? (j/local-date-time clock) (j/plus (j/local-date-time clock) (j/days 5)))) |
408 | | - |
409 | | - (is (j/after? (j/local-date clock) (j/minus (j/local-date clock) (j/days 5)))) |
410 | | - (is (j/before? (j/local-date clock) (j/plus (j/local-date clock) (j/days 5)))) |
411 | | - |
412 | | - (is (j/after? (j/local-time clock) (j/minus (j/local-time clock) (j/minutes 5)))) |
413 | | - (is (j/before? (j/local-time clock) (j/plus (j/local-time clock) (j/minutes 5)))) |
414 | | - |
415 | | - (is (j/after? (j/zoned-date-time clock) (j/minus (j/zoned-date-time clock) (j/minutes 5)))) |
416 | | - (is (j/before? (j/zoned-date-time clock) (j/plus (j/zoned-date-time clock) (j/minutes 5)))) |
417 | | - |
418 | | - (is (j/after? (j/offset-date-time clock) (j/minus (j/offset-date-time clock) (j/minutes 5)))) |
419 | | - (is (j/before? (j/offset-date-time clock) (j/plus (j/offset-date-time clock) (j/minutes 5)))) |
420 | | - |
421 | | - (is (j/after? (j/offset-time clock) (j/minus (j/offset-time clock) (j/minutes 5)))) |
422 | | - (is (j/before? (j/offset-time clock) (j/plus (j/offset-time clock) (j/minutes 5)))) |
423 | | - |
424 | | - (is (j/after? (j/instant clock) (j/minus (j/instant clock) (j/minutes 5)))) |
425 | | - (is (j/before? (j/instant clock) (j/plus (j/instant clock) (j/minutes 5))))) |
| 406 | + (let [ldt (j/local-date-time clock) |
| 407 | + ldt+5 (j/plus ldt (j/days 5))] |
| 408 | + (is (j/after? ldt+5 ldt)) |
| 409 | + (is (not (j/after? ldt ldt+5))) |
| 410 | + (is (j/before? ldt ldt+5)) |
| 411 | + (is (not (j/before? ldt+5 ldt))) |
| 412 | + (is (j/not-after? ldt ldt)) |
| 413 | + (is (j/not-after? ldt ldt+5)) |
| 414 | + (is (not (j/not-after? ldt+5 ldt))) |
| 415 | + (is (j/not-before? ldt ldt)) |
| 416 | + (is (j/not-before? ldt+5 ldt)) |
| 417 | + (is (not (j/not-before? ldt ldt+5)))) |
| 418 | + |
| 419 | + (let [ld (j/local-date clock) |
| 420 | + ld+5 (j/plus ld (j/days 5))] |
| 421 | + (is (j/after? ld+5 ld)) |
| 422 | + (is (not (j/after? ld ld+5))) |
| 423 | + (is (j/before? ld ld+5)) |
| 424 | + (is (not (j/before? ld+5 ld))) |
| 425 | + (is (j/not-after? ld ld)) |
| 426 | + (is (j/not-after? ld ld+5)) |
| 427 | + (is (not (j/not-after? ld+5 ld))) |
| 428 | + (is (j/not-before? ld ld)) |
| 429 | + (is (j/not-before? ld+5 ld)) |
| 430 | + (is (not (j/not-before? ld ld+5)))) |
| 431 | + |
| 432 | + (let [lt (j/local-time clock) |
| 433 | + lt+5 (j/plus lt (j/minutes 5))] |
| 434 | + (is (j/after? lt+5 lt)) |
| 435 | + (is (not (j/after? lt lt+5))) |
| 436 | + (is (j/before? lt lt+5)) |
| 437 | + (is (not (j/before? lt+5 lt))) |
| 438 | + (is (j/not-after? lt lt)) |
| 439 | + (is (j/not-after? lt lt+5)) |
| 440 | + (is (not (j/not-after? lt+5 lt))) |
| 441 | + (is (j/not-before? lt lt)) |
| 442 | + (is (j/not-before? lt+5 lt)) |
| 443 | + (is (not (j/not-before? lt lt+5)))) |
| 444 | + |
| 445 | + (let [zdt (j/zoned-date-time clock) |
| 446 | + zdt+5 (j/plus zdt (j/minutes 5))] |
| 447 | + (is (j/after? zdt+5 zdt)) |
| 448 | + (is (not (j/after? zdt zdt+5))) |
| 449 | + (is (j/before? zdt zdt+5)) |
| 450 | + (is (not (j/before? zdt+5 zdt))) |
| 451 | + (is (j/not-after? zdt zdt)) |
| 452 | + (is (j/not-after? zdt zdt+5)) |
| 453 | + (is (not (j/not-after? zdt+5 zdt))) |
| 454 | + (is (j/not-before? zdt zdt)) |
| 455 | + (is (j/not-before? zdt+5 zdt)) |
| 456 | + (is (not (j/not-before? zdt zdt+5)))) |
| 457 | + |
| 458 | + (let [odt (j/offset-date-time clock) |
| 459 | + odt+5 (j/plus odt (j/minutes 5))] |
| 460 | + (is (j/after? odt+5 odt)) |
| 461 | + (is (not (j/after? odt odt+5))) |
| 462 | + (is (j/before? odt odt+5)) |
| 463 | + (is (not (j/before? odt+5 odt))) |
| 464 | + (is (j/not-after? odt odt)) |
| 465 | + (is (j/not-after? odt odt+5)) |
| 466 | + (is (not (j/not-after? odt+5 odt))) |
| 467 | + (is (j/not-before? odt odt)) |
| 468 | + (is (j/not-before? odt+5 odt)) |
| 469 | + (is (not (j/not-before? odt odt+5)))) |
| 470 | + |
| 471 | + (let [ot (j/offset-time clock) |
| 472 | + ot+5 (j/plus ot (j/minutes 5))] |
| 473 | + (is (j/after? ot+5 ot)) |
| 474 | + (is (not (j/after? ot ot+5))) |
| 475 | + (is (j/before? ot ot+5)) |
| 476 | + (is (not (j/before? ot+5 ot))) |
| 477 | + (is (j/not-after? ot ot)) |
| 478 | + (is (j/not-after? ot ot+5)) |
| 479 | + (is (not (j/not-after? ot+5 ot))) |
| 480 | + (is (j/not-before? ot ot)) |
| 481 | + (is (j/not-before? ot+5 ot)) |
| 482 | + (is (not (j/not-before? ot ot+5)))) |
| 483 | + |
| 484 | + (let [i (j/instant clock) |
| 485 | + i+5 (j/plus i (j/minutes 5))] |
| 486 | + (is (j/after? i+5 i)) |
| 487 | + (is (not (j/after? i i+5))) |
| 488 | + (is (j/before? i i+5)) |
| 489 | + (is (not (j/before? i+5 i))) |
| 490 | + (is (j/not-after? i i)) |
| 491 | + (is (j/not-after? i i+5)) |
| 492 | + (is (not (j/not-after? i+5 i))) |
| 493 | + (is (j/not-before? i i)) |
| 494 | + (is (j/not-before? i+5 i)) |
| 495 | + (is (not (j/not-before? i i+5))))) |
426 | 496 |
|
427 | 497 | (testing "clocks"
|
428 | | - (is (j/after? (j/fixed-clock 1000) (j/fixed-clock 0))) |
429 | | - (is (j/before? (j/fixed-clock 1000) (j/fixed-clock 5000)))) |
| 498 | + (let [fc (j/fixed-clock 0) |
| 499 | + fc+1000 (j/fixed-clock 1000)] |
| 500 | + (is (j/after? fc+1000 fc)) |
| 501 | + (is (not (j/after? fc fc+1000))) |
| 502 | + (is (j/before? fc fc+1000)) |
| 503 | + (is (not (j/before? fc+1000 fc))) |
| 504 | + (is (j/not-after? fc fc)) |
| 505 | + (is (j/not-after? fc fc+1000)) |
| 506 | + (is (not (j/not-after? fc+1000 fc))) |
| 507 | + (is (j/not-before? fc fc)) |
| 508 | + (is (j/not-before? fc+1000 fc)) |
| 509 | + (is (not (j/not-before? fc fc+1000))))) |
430 | 510 |
|
431 | 511 | (testing "fields"
|
432 | | - (is (j/after? (j/day-of-week :saturday) :thursday)) |
433 | | - (is (j/before? (j/day-of-week :saturday) :sunday)) |
434 | | - |
435 | | - (is (j/after? (j/month :february) :january)) |
436 | | - (is (j/before? (j/month :february) :march)) |
437 | | - |
438 | | - (is (j/after? (j/year 2010) 2009)) |
439 | | - (is (j/before? (j/year 2010) 2011)) |
440 | | - |
441 | | - (is (j/after? (j/month-day 5 1) (j/month-day 4 1))) |
442 | | - (is (j/before? (j/month-day 1 1) (j/month-day 4 1))))) |
| 512 | + (let [thursday (j/day-of-week :thursday) |
| 513 | + saturday (j/day-of-week :saturday) |
| 514 | + sunday (j/day-of-week :sunday)] |
| 515 | + (is (j/after? saturday :thursday)) |
| 516 | + (is (not (j/after? thursday :saturday))) |
| 517 | + (is (j/before? saturday :sunday)) |
| 518 | + (is (not (j/before? sunday :saturday))) |
| 519 | + (is (j/not-after? saturday saturday)) |
| 520 | + (is (j/not-after? saturday sunday)) |
| 521 | + (is (not (j/not-after? sunday saturday))) |
| 522 | + (is (j/not-before? saturday saturday)) |
| 523 | + (is (j/not-before? sunday saturday)) |
| 524 | + (is (not (j/not-before? saturday sunday)))) |
| 525 | + |
| 526 | + (let [january (j/month :january) |
| 527 | + february (j/month :february) |
| 528 | + march (j/month :march)] |
| 529 | + (is (j/after? february :january)) |
| 530 | + (is (not (j/after? january :february))) |
| 531 | + (is (j/before? february :march)) |
| 532 | + (is (not (j/before? march :february))) |
| 533 | + (is (j/not-after? january january)) |
| 534 | + (is (j/not-after? february march)) |
| 535 | + (is (not (j/not-after? march february))) |
| 536 | + (is (j/not-before? january january)) |
| 537 | + (is (j/not-before? february january)) |
| 538 | + (is (not (j/not-before? january february)))) |
| 539 | + |
| 540 | + (let [year-2009 (j/year 2009) |
| 541 | + year-2010 (j/year 2010)] |
| 542 | + (is (j/after? year-2010 2009)) |
| 543 | + (is (not (j/after? year-2009 2010))) |
| 544 | + (is (j/before? year-2009 2010)) |
| 545 | + (is (not (j/before? year-2010 2009))) |
| 546 | + (is (j/not-after? year-2010 year-2010)) |
| 547 | + (is (j/not-after? year-2009 year-2010)) |
| 548 | + (is (not (j/not-after? year-2010 year-2009))) |
| 549 | + (is (j/not-before? year-2010 year-2010)) |
| 550 | + (is (j/not-before? year-2010 year-2009)) |
| 551 | + (is (not (j/not-before? year-2009 year-2010)))) |
| 552 | + |
| 553 | + (let [jan-1 (j/month-day 1 1) |
| 554 | + apr-1 (j/month-day 4 1)] |
| 555 | + (is (j/after? apr-1 jan-1)) |
| 556 | + (is (not (j/after? jan-1 apr-1))) |
| 557 | + (is (j/before? jan-1 apr-1)) |
| 558 | + (is (not (j/before? apr-1 jan-1))) |
| 559 | + (is (j/not-after? jan-1 jan-1)) |
| 560 | + (is (j/not-after? jan-1 apr-1)) |
| 561 | + (is (not (j/not-after? apr-1 jan-1))) |
| 562 | + (is (j/not-before? jan-1 jan-1)) |
| 563 | + (is (j/not-before? apr-1 jan-1)) |
| 564 | + (is (not (j/not-before? jan-1 apr-1)))))) |
443 | 565 |
|
444 | 566 | (deftest mock-clock
|
445 | 567 | (testing "constructors"
|
|
756 | 878 | (is (nil? (j/gap (j/interval 0 1000) (j/interval 500 1500))))))
|
757 | 879 |
|
758 | 880 | (testing "ordering"
|
759 | | - (is (j/before? (j/interval 1000 2000) (j/instant 5000))) |
760 | | - (is (not (j/before? (j/interval 1000 5000) (j/instant 5000)))) |
761 | | - (is (j/before? (j/interval 1000 5000) (j/interval 5001 6000))) |
762 | | - |
763 | | - (is (j/after? (j/interval 1000 5000) (j/instant 100))) |
764 | | - (is (not (j/after? (j/interval 1000 5000) (j/instant 2000)))) |
765 | | - (is (j/after? (j/interval 1000 5000) (j/interval 100 999))))) |
| 881 | + (let [interval-1-2 (j/interval 1 2) |
| 882 | + interval-3-4 (j/interval 3 4) |
| 883 | + instant-1 (j/instant 1) |
| 884 | + instant-3 (j/instant 3)] |
| 885 | + (is (j/before? interval-1-2 interval-3-4)) |
| 886 | + (is (not (j/before? interval-3-4 interval-1-2))) |
| 887 | + (is (j/before? interval-1-2 instant-3)) |
| 888 | + (is (not (j/before? interval-3-4 instant-1))) |
| 889 | + |
| 890 | + (is (j/after? interval-3-4 interval-1-2)) |
| 891 | + (is (not (j/after? interval-1-2 interval-3-4))) |
| 892 | + (is (j/after? interval-3-4 instant-1)) |
| 893 | + (is (not (j/after? interval-1-2 instant-3))) |
| 894 | + |
| 895 | + (is (j/not-before? interval-3-4 interval-3-4)) |
| 896 | + (is (j/not-before? interval-1-2 interval-3-4)) |
| 897 | + (is (not (j/not-before? interval-1-2 interval-3-4))) |
| 898 | + (is (j/not-before? interval-3-4 instant-3)) |
| 899 | + (is (j/not-before? interval-3-4 instant-1)) |
| 900 | + (is (not (j/not-before? interval-1-2 instant-3))) |
| 901 | + |
| 902 | + (is (j/not-after? interval-1-2 interval-1-2)) |
| 903 | + (is (j/not-after? interval-1-2 interval-3-4)) |
| 904 | + (is (not (j/not-after? interval-3-4 interval-1-2))) |
| 905 | + (is (j/not-after? interval-1-2 instant-1)) |
| 906 | + (is (j/not-after? interval-1-2 instant-3)) |
| 907 | + (is (not (j/not-after? interval-3-4 instant-1))))) |
766 | 908 |
|
767 | 909 | (jt.u/when-joda-time-loaded
|
768 | 910 |
|
|
0 commit comments