Reputation: 121
I am trying to test the following and I get an error:
dateUtil.spec.ts:
import { isDay } from "./dateUtil";
describe("utils/dateUtil", () => {
describe("isDate", () => {
it("should determine if time of day is day or night", () => {
const day = "Tue Dec 18 2018 12:00:00 GMT-0800 (Pacific Standard Time)";
const night = "Tue Dec 18 2018 20:00:00 GMT-0800 (Pacific Standard Time)";
expect(isDay(new Date(day))).toBeTruthy();
expect(isDay(new Date(night))).toBeFalsy();
});
});
});
dateUtil.ts
export const isDay = (date: Date) => {
const currentHour = date.getHours();
return currentHour > 6 && currentHour < 18;
};
What am I missing and what do I need to do?
Upvotes: 1
Views: 92
Reputation: 121
Change time according to time zone. For example:
const night = "Sun Oct 04 2020 10:23:31 GMT+0100 (West Africa Standard Time)";
Upvotes: 1