Commits

Tim Donohue authored and GitHub committed 94d38efabc2 Merge
Merge pull request #1947 from 4Science/CST-7376

Test cases of date.util.spec.ts fixed
No tags
gidlmaster

src/app/shared/date.util.spec.ts

Modified
15 15 });
16 16 it('should convert Year string to YYYY-MM-DDThh:mm:ssZ string', () => {
17 17 expect(dateToISOFormat('2022')).toEqual('2022-01-01T00:00:00Z');
18 18 });
19 19 it('should convert ISO Date string to YYYY-MM-DDThh:mm:ssZ string', () => {
20 20 // NOTE: Time is always zeroed out as proven by this test.
21 21 expect(dateToISOFormat('2022-06-03T03:24:04Z')).toEqual('2022-06-03T00:00:00Z');
22 22 });
23 23 it('should convert NgbDateStruct to YYYY-MM-DDThh:mm:ssZ string', () => {
24 24 // NOTE: month is zero indexed which is why it increases by one
25 - const date = new Date(2022, 5, 3);
25 + const date = new Date(Date.UTC(2022, 5, 3));
26 26 expect(dateToISOFormat(dateToNgbDateStruct(date))).toEqual('2022-06-03T00:00:00Z');
27 27 });
28 28 });
29 29
30 30 describe('dateToString', () => {
31 31 it('should convert Date to YYYY-MM-DD string', () => {
32 32 // NOTE: month is zero indexed which is why it increases by one
33 - expect(dateToString(new Date(2022, 5, 3))).toEqual('2022-06-03');
33 + expect(dateToString(new Date(Date.UTC(2022, 5, 3)))).toEqual('2022-06-03');
34 34 });
35 35 it('should convert Date with time to YYYY-MM-DD string', () => {
36 36 // NOTE: month is zero indexed which is why it increases by one
37 - expect(dateToString(new Date(2022, 5, 3, 3, 24, 0))).toEqual('2022-06-03');
37 + expect(dateToString(new Date(Date.UTC(2022, 5, 3, 3, 24, 0)))).toEqual('2022-06-03');
38 38 });
39 39 it('should convert Month only to YYYY-MM-DD string', () => {
40 40 // NOTE: month is zero indexed which is why it increases by one
41 - expect(dateToString(new Date(2022, 5))).toEqual('2022-06-01');
41 + expect(dateToString(new Date(Date.UTC(2022, 5)))).toEqual('2022-06-01');
42 42 });
43 43 it('should convert ISO Date to YYYY-MM-DD string', () => {
44 44 expect(dateToString(new Date('2022-06-03T03:24:00Z'))).toEqual('2022-06-03');
45 45 });
46 46 it('should convert NgbDateStruct to YYYY-MM-DD string', () => {
47 47 // NOTE: month is zero indexed which is why it increases by one
48 - const date = new Date(2022, 5, 3);
48 + const date = new Date(Date.UTC(2022, 5, 3));
49 49 expect(dateToString(dateToNgbDateStruct(date))).toEqual('2022-06-03');
50 50 });
51 51 });
52 52
53 53
54 54 describe('isValidDate', () => {
55 55 it('should return false for null', () => {
56 56 expect(isValidDate(null)).toBe(false);
57 57 });
58 58 it('should return false for empty string', () => {

Everything looks good. We'll let you know here if there's anything you should know about.

Add shortcut