Skip to content

Commit

Permalink
fix all days event doesn't work anymore (#150)
Browse files Browse the repository at this point in the history
  • Loading branch information
idaho authored Dec 30, 2023
1 parent d5db0f3 commit 88ae4a1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/utils/findActiveEvent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('findActiveEvent', (): void => {
test('the whole day event today cause its before 10 o`clock', async () => {
const events = normaliseEvents(calendarEvents as RawCalendarEvent[]);

const now = new Date(`2023-12-10T09:59:59${offset}`);
const now = new Date(`2023-12-10T09:59:59`);
const dropAfter = isTodayAfter(now, '10:00:00');

const result = findActiveEvent(events, {
Expand Down
7 changes: 2 additions & 5 deletions src/utils/isTodayAfter.test.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
/* eslint-disable @typescript-eslint/naming-convention */
import { getTimeZoneOffset } from './getTimeZoneOffset';
import { isTodayAfter } from './isTodayAfter';

describe('isTodayAfter', (): void => {
const offset = getTimeZoneOffset();

test('11:10:00 is after 11:00:00', async () => {
const date = new Date(`1970-01-01T11:10:00.000${offset}`);
const date = new Date(`1970-01-01T11:10:00.000`);

const result = isTodayAfter(date, '11:00:00');

expect(result).toEqual(true);
});

test('11:10:00 is before 11:10:01', async () => {
const date = new Date(`1970-01-01T11:10:00.000${offset}`);
const date = new Date(`1970-01-01T11:10:00.000`);

const result = isTodayAfter(date, '11:10:01');

Expand Down
20 changes: 14 additions & 6 deletions src/utils/isTodayAfter.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
import { getDayFromDate } from './getDayFromDate';
import { getTimeZoneOffset } from './getTimeZoneOffset';

const isTodayAfter = (now: Date, dropAfter: string): boolean => {
const [ hours, minutes, seconds ] = dropAfter.split(':');

const dropAfterDateString = `${getDayFromDate(now)}T${hours}:${minutes}:${seconds}.000${getTimeZoneOffset()}`;
const dropAfterDate = new Date(dropAfterDateString);
if (now.getHours() < Number(hours)) {
return false;
}
if (now.getHours() > Number(hours)) {
return true;
}

if (now.getMinutes() > Number(minutes)) {
return true;
}
if (now.getSeconds() >= Number(seconds)) {
return true;
}

return now > dropAfterDate;
return false;
};

export {
Expand Down

0 comments on commit 88ae4a1

Please sign in to comment.