I am struggling to understand why moment startOf('year')
and endOf('year')
result in a different ISO string in local machine and on cloud. I am assuming its a timezone issue but ISO string looks like its in UTC, so it should return same ISO string. I’d like to understand if its a timezone issue how should I ensure that different timezone does not affect my code.
In local it returns start of year as '2022-12-31T19:00:00.000Z'
and in cloud it gives 2023-01-01T00:00:00.000Z
So my code is
// find current year start and end
const startOfYear = moment(currentDate).startOf('year').toDate();
const endOfYear = moment(currentDate).endOf('year').toDate();
return {
start: startOfYear,
end: endOfYear,
};
The unit test I wrote which PASS in local but FAIL in cloud in case you are interested in what I am doing
const timestamp = new Date('2023-05-15T00:00:00Z');
const expectedStart = new Date('2022-12-31T19:00:00.000Z');
const expectedEnd = new Date('2023-12-31T18:59:59.999Z');
const result = getFinancialYearDates(timestamp);
expect(result.start).toStrictEqual(expectedStart);
expect(result.end).toStrictEqual(expectedEnd);