|
1 |
| -import {isDateMoreRecentThan} from './is-date-more-recent-than'; |
| 1 | +import {isDateEqualTo, isDateMoreRecentThan} from './is-date-more-recent-than'; |
2 | 2 |
|
3 | 3 | describe('isDateMoreRecentThan()', (): void => {
|
4 | 4 | let date: Date;
|
@@ -48,4 +48,68 @@ describe('isDateMoreRecentThan()', (): void => {
|
48 | 48 | expect(result).toStrictEqual(true);
|
49 | 49 | });
|
50 | 50 | });
|
| 51 | + |
| 52 | + describe('date equality', (): void => { |
| 53 | + it('should correctly compare a before date outside tolerance', (): void => { |
| 54 | + const aDate = new Date('2022-09-09T13:00:00'); |
| 55 | + const otherDate = new Date('2022-09-09T14:00:00'); |
| 56 | + expect(isDateEqualTo(aDate, otherDate, 60)).toBe(false); |
| 57 | + }); |
| 58 | + |
| 59 | + it('should correctly compare a before date inside tolerance', (): void => { |
| 60 | + const aDate = new Date('2022-09-09T13:00:00'); |
| 61 | + const otherDate = new Date('2022-09-09T13:00:42'); |
| 62 | + expect(isDateEqualTo(aDate, otherDate, 60)).toBe(true); |
| 63 | + }); |
| 64 | + |
| 65 | + it('should correctly compare an after date outside tolerance', (): void => { |
| 66 | + const aDate = new Date('2022-09-09T13:00:00'); |
| 67 | + const otherDate = new Date('2022-09-09T12:00:00'); |
| 68 | + expect(isDateEqualTo(aDate, otherDate, 60)).toBe(false); |
| 69 | + }); |
| 70 | + |
| 71 | + it('should correctly compare an after date inside tolerance', (): void => { |
| 72 | + const aDate = new Date('2022-09-09T13:00:00'); |
| 73 | + const otherDate = new Date('2022-09-09T12:59:42'); |
| 74 | + expect(isDateEqualTo(aDate, otherDate, 60)).toBe(true); |
| 75 | + }); |
| 76 | + |
| 77 | + it('should correctly compare an exactly equal date', (): void => { |
| 78 | + const aDate = new Date('2022-09-09T13:00:00'); |
| 79 | + const otherDate = new Date('2022-09-09T13:00:00'); |
| 80 | + expect(isDateEqualTo(aDate, otherDate, 60)).toBe(true); |
| 81 | + }); |
| 82 | + }); |
| 83 | + |
| 84 | + describe('date comparison with tolerances', (): void => { |
| 85 | + it('should correctly compare a before date outside tolerance', (): void => { |
| 86 | + const aDate = new Date('2022-09-09T13:00:00'); |
| 87 | + const otherDate = new Date('2022-09-09T14:00:00'); |
| 88 | + expect(isDateMoreRecentThan(aDate, otherDate)).toBe(false); |
| 89 | + }); |
| 90 | + |
| 91 | + it('should correctly compare a before date inside tolerance', (): void => { |
| 92 | + const aDate = new Date('2022-09-09T13:00:00'); |
| 93 | + const otherDate = new Date('2022-09-09T13:00:42'); |
| 94 | + expect(isDateMoreRecentThan(aDate, otherDate, 60)).toBe(false); // considered equal here |
| 95 | + }); |
| 96 | + |
| 97 | + it('should correctly compare an after date outside tolerance', (): void => { |
| 98 | + const aDate = new Date('2022-09-09T13:00:00'); |
| 99 | + const otherDate = new Date('2022-09-09T12:00:00'); |
| 100 | + expect(isDateMoreRecentThan(aDate, otherDate, 60)).toBe(true); |
| 101 | + }); |
| 102 | + |
| 103 | + it('should correctly compare an after date inside tolerance', (): void => { |
| 104 | + const aDate = new Date('2022-09-09T13:00:00'); |
| 105 | + const otherDate = new Date('2022-09-09T12:59:42'); |
| 106 | + expect(isDateMoreRecentThan(aDate, otherDate, 60)).toBe(false); // considered equal here |
| 107 | + }); |
| 108 | + |
| 109 | + it('should correctly compare an exactly equal date', (): void => { |
| 110 | + const aDate = new Date('2022-09-09T13:00:00'); |
| 111 | + const otherDate = new Date('2022-09-09T13:00:00'); |
| 112 | + expect(isDateMoreRecentThan(aDate, otherDate, 60)).toBe(false); |
| 113 | + }); |
| 114 | + }); |
51 | 115 | });
|
0 commit comments