-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix days till calculation when event is not whole day event (#243)
- Loading branch information
Showing
4 changed files
with
89 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* eslint-disable @typescript-eslint/naming-convention */ | ||
import { daysTill } from './daysTill'; | ||
|
||
import type { CalendarItem } from './calendarItem'; | ||
|
||
describe('daysTill', (): void => { | ||
test('2 days till whole day events', async () => { | ||
const date = new Date(`1970-01-02T00:00:00.000`); | ||
|
||
const item = { | ||
date: { | ||
start: new Date(`1970-01-04T00:00:00.000`) | ||
} | ||
} as CalendarItem; | ||
|
||
const result = daysTill(date, item); | ||
|
||
expect(result).toEqual(2); | ||
}); | ||
|
||
test('2 days till event at the evening', async () => { | ||
const date = new Date(`1970-01-02T00:00:00.000`); | ||
|
||
const item = { | ||
date: { | ||
start: new Date(`1970-01-04T22:00:00.000`) | ||
} | ||
} as CalendarItem; | ||
|
||
const result = daysTill(date, item); | ||
|
||
expect(result).toEqual(2); | ||
}); | ||
|
||
test('2 days till event during leap ear', async () => { | ||
const date = new Date(`2024-02-28T00:00:00.000`); | ||
|
||
const item = { | ||
date: { | ||
start: new Date(`2024-03-01T00:00:00.000`) | ||
} | ||
} as CalendarItem; | ||
|
||
const result = daysTill(date, item); | ||
|
||
expect(result).toEqual(2); | ||
}); | ||
|
||
describe('calculate correct during time changeover', (): void => { | ||
test('from normal to day light saving', async () => { | ||
const date = new Date(`2024-03-30T00:00:00.000`); | ||
|
||
const item = { | ||
date: { | ||
start: new Date(`2024-04-01T00:00:00.000`) | ||
} | ||
} as CalendarItem; | ||
|
||
const result = daysTill(date, item); | ||
|
||
expect(result).toEqual(2); | ||
}); | ||
|
||
test('from day light saving to normal', async () => { | ||
const date = new Date(`2024-10-26T00:00:00.000`); | ||
|
||
const item = { | ||
date: { | ||
start: new Date(`2024-10-29T00:00:00.000`) | ||
} | ||
} as CalendarItem; | ||
|
||
const result = daysTill(date, item); | ||
|
||
expect(result).toEqual(3); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters