I get this error when running tests for an application. Here is the test:
dateUtil.ts
```
export const isDay = (date: Date) => {
const currentHour = date.getHours();
return currentHour > 6 && currentHour < 18;
};
```
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();
});
});
});
```
What am I getting wrong?
Solved! Go to Solution.
I found out that the date makes a time shift according to your machine's time zone. Change the test date accordingly, e.g. 'Sun Oct 04 2020 10:23:31 GMT+0100 (West Africa Standard Time)'
I found out that the date makes a time shift according to your machine's time zone. Change the test date accordingly, e.g. 'Sun Oct 04 2020 10:23:31 GMT+0100 (West Africa Standard Time)'