From fb64782769ba9db7b46b48755a05a07f766d5be8 Mon Sep 17 00:00:00 2001 From: Yoan VALLET <ext.sopra.yvallet@grandlyon.com> Date: Fri, 15 Jan 2021 20:04:07 +0100 Subject: [PATCH] fix: use utc for tests --- src/components/Duel/DuelBar.tsx | 4 +- src/services/challenge.service.spec.ts | 10 +- src/services/challenge.service.ts | 9 +- .../consumptionFormatter.service.spec.ts | 130 +++-- .../consumptionValidator.service.spec.ts | 50 +- src/services/dateChart.service.spec.ts | 502 +++++++++++++----- src/services/duel.service.spec.ts | 6 +- src/services/fluid.service.spec.ts | 48 +- src/services/initialization.service.spec.ts | 12 +- src/services/initialization.service.ts | 4 +- src/services/profile.service.spec.ts | 8 +- src/services/queryRunner.service.spec.ts | 287 ++++++---- src/services/queryRunner.service.ts | 1 + src/services/quiz.service.ts | 4 +- src/services/timePeriod.service.spec.ts | 78 +-- src/store/challenge/challenge.reducer.spec.ts | 4 +- src/store/global/global.reducer.spec.ts | 12 +- src/utils/date.spec.ts | 144 ++++- src/utils/date.ts | 6 +- test/__mocks__/datachartData.mock.ts | 24 +- test/__mocks__/fluidStatusData.mock.ts | 6 +- test/__mocks__/profile.mock.ts | 4 +- 22 files changed, 955 insertions(+), 398 deletions(-) diff --git a/src/components/Duel/DuelBar.tsx b/src/components/Duel/DuelBar.tsx index 704589cdc..a466a3dcc 100644 --- a/src/components/Duel/DuelBar.tsx +++ b/src/components/Duel/DuelBar.tsx @@ -52,7 +52,9 @@ const DuelBar: React.FC<BarChartProps> = (props: BarChartProps) => { const { currentDataload } = useSelector( (state: AppStore) => state.ecolyo.challenge ) - const falseDateTime = DateTime.fromISO('1000-10-01T00:00:00.000') + const falseDateTime = DateTime.fromISO('1000-10-01T00:00:00.000Z', { + zone: 'utc', + }) const getContentWidth = () => { return width - marginLeft - marginRight diff --git a/src/services/challenge.service.spec.ts b/src/services/challenge.service.spec.ts index 0ee62ce33..7b663a019 100644 --- a/src/services/challenge.service.spec.ts +++ b/src/services/challenge.service.spec.ts @@ -287,7 +287,9 @@ describe('Challenge service', () => { ...userChallengeData[0], duel: { ...userChallengeData[0].duel, - startDate: DateTime.local(), + startDate: DateTime.local().setZone('utc', { + keepLocalTime: true, + }), }, } mockGetGraphData.mockResolvedValueOnce(graphData) @@ -321,7 +323,11 @@ describe('Challenge service', () => { duration: Duration.fromObject({ day: 3 }), threshold: 200, userConsumption: 199, - startDate: DateTime.local().minus({ days: 5 }), + startDate: DateTime.local() + .setZone('utc', { + keepLocalTime: true, + }) + .minus({ days: 5 }), }, } const dataloads = graphData.actualData diff --git a/src/services/challenge.service.ts b/src/services/challenge.service.ts index ddf72359c..758a1e8ee 100644 --- a/src/services/challenge.service.ts +++ b/src/services/challenge.service.ts @@ -534,7 +534,14 @@ export default class ChallengeService { getLagDays(userChallenge.duel.fluidTypes) + 1 let diffFromNow = userChallenge.duel.startDate - ? userChallenge.duel.startDate.diffNow('days').toObject().days + ? userChallenge.duel.startDate + .diff( + DateTime.local().setZone('utc', { + keepLocalTime: true, + }), + 'days' + ) + .toObject().days : 0 diffFromNow = diffFromNow ? Math.abs(diffFromNow) : 0 diff --git a/src/services/consumptionFormatter.service.spec.ts b/src/services/consumptionFormatter.service.spec.ts index ff053cef2..efd1b69ef 100644 --- a/src/services/consumptionFormatter.service.spec.ts +++ b/src/services/consumptionFormatter.service.spec.ts @@ -5,156 +5,214 @@ import { Dataload, TimePeriod } from 'models' const mockDataLoad: Dataload[] = [ { - date: DateTime.fromISO('2020-10-01T00:00:00.000'), + date: DateTime.fromISO('2020-10-01T00:00:00.000Z', { + zone: 'utc', + }), value: 291.9, + valueDetail: null, }, { - date: DateTime.fromISO('2020-10-01T00:30:00.000'), + date: DateTime.fromISO('2020-10-01T00:30:00.000Z', { + zone: 'utc', + }), value: 235.5, + valueDetail: null, }, { - date: DateTime.fromISO('2020-10-03T18:59:59.999'), + date: DateTime.fromISO('2020-10-03T18:59:59.999Z', { + zone: 'utc', + }), value: 260.15, + valueDetail: null, }, { - date: DateTime.fromISO('2020-10-03T20:59:59.999'), + date: DateTime.fromISO('2020-10-03T20:59:59.999Z', { + zone: 'utc', + }), value: 293.33, + valueDetail: null, }, { - date: DateTime.fromISO('2020-11-03T20:59:59.999'), + date: DateTime.fromISO('2020-11-03T20:59:59.999Z', { + zone: 'utc', + }), value: 268.55, + valueDetail: null, }, { - date: DateTime.fromISO('2018-11-03T20:59:59.999'), + date: DateTime.fromISO('2018-11-03T20:59:59.999Z', { + zone: 'utc', + }), value: 272.33, + valueDetail: null, }, ] let mockTimePeriod: TimePeriod = { - startDate: DateTime.fromISO('2020-10-01T00:00:00.000'), - endDate: DateTime.fromISO('2020-10-03T23:59:59.999'), + startDate: DateTime.fromISO('2020-10-01T00:00:00.000Z', { + zone: 'utc', + }), + endDate: DateTime.fromISO('2020-10-03T23:59:59.999Z', { + zone: 'utc', + }), } const unknowTimeStep = 999 describe('ConsumptionFormatter service', () => { const consumptionFormatterService = new ConsumptionFormatterService() describe('formatGraphData method', () => { - it('shoud return a formattedData for DAY', async () => { + it('shoud return a formattedData for DAY', () => { const mockResult = [ { - date: DateTime.fromISO('2020-10-01T00:00:00.000+02:00'), + date: DateTime.fromISO('2020-10-01T00:00:00.000Z', { + zone: 'utc', + }), value: 291.9, valueDetail: null, }, { - date: DateTime.fromISO('2020-10-02T00:00:00.000+02:00'), + date: DateTime.fromISO('2020-10-02T00:00:00.000Z', { + zone: 'utc', + }), value: -1, valueDetail: null, }, { - date: DateTime.fromISO('2020-10-03T18:59:59.999+02:00'), + date: DateTime.fromISO('2020-10-03T18:59:59.999Z', { + zone: 'utc', + }), value: 260.15, valueDetail: null, }, ] - const result = await consumptionFormatterService.formatGraphData( + const result = consumptionFormatterService.formatGraphData( mockDataLoad, mockTimePeriod, TimeStep.DAY ) expect(result).toEqual(mockResult) }) - it('shoud return a formattedData for HALF_AN_HOUR', async () => { + it('shoud return a formattedData for HALF_AN_HOUR', () => { mockTimePeriod = { - startDate: DateTime.fromISO('2020-10-01T00:00:00.000'), - endDate: DateTime.fromISO('2020-10-01T01:00:00.000'), + startDate: DateTime.fromISO('2020-10-01T00:00:00.000Z', { + zone: 'utc', + }), + endDate: DateTime.fromISO('2020-10-01T01:00:00.000Z', { + zone: 'utc', + }), } const mockResult = [ { - date: DateTime.fromISO('2020-10-01T00:00:00.000+02:00'), + date: DateTime.fromISO('2020-10-01T00:00:00.000Z', { + zone: 'utc', + }), value: 291.9, valueDetail: null, }, { - date: DateTime.fromISO('2020-10-01T00:30:00.000+02:00'), + date: DateTime.fromISO('2020-10-01T00:30:00.000Z', { + zone: 'utc', + }), value: 235.5, valueDetail: null, }, { - date: DateTime.fromISO('2020-10-01T01:00:00.000+02:00'), + date: DateTime.fromISO('2020-10-01T01:00:00.000Z', { + zone: 'utc', + }), value: -1, valueDetail: null, }, ] - const result = await consumptionFormatterService.formatGraphData( + const result = consumptionFormatterService.formatGraphData( mockDataLoad, mockTimePeriod, TimeStep.HALF_AN_HOUR ) expect(result).toEqual(mockResult) }) - it('shoud return a formattedData for MONTH', async () => { + it('shoud return a formattedData for MONTH', () => { mockTimePeriod = { - startDate: DateTime.fromISO('2020-10-01T00:00:00.000'), - endDate: DateTime.fromISO('2020-12-01T00:00:00.000'), + startDate: DateTime.fromISO('2020-10-01T00:00:00.000Z', { + zone: 'utc', + }), + endDate: DateTime.fromISO('2020-12-01T00:00:00.000Z', { + zone: 'utc', + }), } const mockResult = [ { - date: DateTime.fromISO('2020-10-01T00:00:00.000+02:00'), + date: DateTime.fromISO('2020-10-01T00:00:00.000Z', { + zone: 'utc', + }), value: 291.9, valueDetail: null, }, { - date: DateTime.fromISO('2020-11-03T20:59:59.999+01:00'), + date: DateTime.fromISO('2020-11-03T20:59:59.999Z', { + zone: 'utc', + }), value: 268.55, valueDetail: null, }, { - date: DateTime.fromISO('2020-12-01T01:00:00.000+02:00'), + date: DateTime.fromISO('2020-12-01T00:00:00.000Z', { + zone: 'utc', + }), value: -1, valueDetail: null, }, ] - const result = await consumptionFormatterService.formatGraphData( + const result = consumptionFormatterService.formatGraphData( mockDataLoad, mockTimePeriod, TimeStep.MONTH ) expect(result).toEqual(mockResult) }) - it('shoud return a formattedData for YEAR', async () => { + it('shoud return a formattedData for YEAR', () => { mockTimePeriod = { - startDate: DateTime.fromISO('2018-10-01T00:00:00.000'), - endDate: DateTime.fromISO('2020-12-01T00:00:00.000'), + startDate: DateTime.fromISO('2018-10-01T00:00:00.000Z', { + zone: 'utc', + }), + endDate: DateTime.fromISO('2020-12-01T00:00:00.000Z', { + zone: 'utc', + }), } const mockResult = [ { - date: DateTime.fromISO('2018-11-03T20:59:59.999+01:00'), + date: DateTime.fromISO('2018-11-03T20:59:59.999Z', { + zone: 'utc', + }), value: 272.33, valueDetail: null, }, { - date: DateTime.fromISO('2019-10-01T00:00:00.000+02:00'), + date: DateTime.fromISO('2019-10-01T00:00:00.000Z', { + zone: 'utc', + }), value: -1, valueDetail: null, }, { - date: DateTime.fromISO('2020-10-01T00:00:00.000+02:00'), + date: DateTime.fromISO('2020-10-01T00:00:00.000Z', { + zone: 'utc', + }), value: 291.9, valueDetail: null, }, ] - const result = await consumptionFormatterService.formatGraphData( + const result = consumptionFormatterService.formatGraphData( mockDataLoad, mockTimePeriod, TimeStep.YEAR ) expect(result).toEqual(mockResult) }) - it('shoud return an error because of unknown TimeStep', async () => { + it('shoud return an error because of unknown TimeStep', () => { try { - await consumptionFormatterService.formatGraphData( + consumptionFormatterService.formatGraphData( mockDataLoad, mockTimePeriod, unknowTimeStep diff --git a/src/services/consumptionValidator.service.spec.ts b/src/services/consumptionValidator.service.spec.ts index 063229635..ac4456840 100644 --- a/src/services/consumptionValidator.service.spec.ts +++ b/src/services/consumptionValidator.service.spec.ts @@ -5,12 +5,12 @@ import { FluidType } from 'enum/fluid.enum' import { TimePeriod } from 'models' const mockTimePeriod: TimePeriod = { - startDate: DateTime.fromISO('2020-10-01T00:00:00.000'), - endDate: DateTime.fromISO('2020-10-03T23:59:59.999'), + startDate: DateTime.fromISO('2020-10-01T00:00:00.000Z', { zone: 'utc' }), + endDate: DateTime.fromISO('2020-10-03T23:59:59.999Z', { zone: 'utc' }), } const mockTimePeriodComparison: TimePeriod = { - startDate: DateTime.fromISO('2020-09-01T00:00:00.000'), - endDate: DateTime.fromISO('2020-09-03T23:59:59.999'), + startDate: DateTime.fromISO('2020-09-01T00:00:00.000Z', { zone: 'utc' }), + endDate: DateTime.fromISO('2020-09-03T23:59:59.999Z', { zone: 'utc' }), } let fluidTypes: FluidType[] = [0, 1, 2] describe('ConsumptionFormatter service', () => { @@ -35,8 +35,10 @@ describe('ConsumptionFormatter service', () => { }) it('shoud return false with comparison Date', () => { const wrongTimePeriodComparison: TimePeriod = { - startDate: DateTime.fromISO('2020-09-05T00:00:00.000'), - endDate: DateTime.fromISO('2020-09-03T23:59:59.999'), + startDate: DateTime.fromISO('2020-09-05T00:00:00.000Z', { + zone: 'utc', + }), + endDate: DateTime.fromISO('2020-09-03T23:59:59.999Z', { zone: 'utc' }), } const result = consumptionValidatorService.ValidateGetGraphData( mockTimePeriod, @@ -48,8 +50,10 @@ describe('ConsumptionFormatter service', () => { }) it('shoud return false with comparison Date', () => { const wrongTimePeriodComparison: TimePeriod = { - startDate: DateTime.fromISO('2020-09-05T00:00:00.000'), - endDate: DateTime.fromISO('2020-09-07T23:59:59.999'), + startDate: DateTime.fromISO('2020-09-05T00:00:00.000Z', { + zone: 'utc', + }), + endDate: DateTime.fromISO('2020-09-07T23:59:59.999Z', { zone: 'utc' }), } const result = consumptionValidatorService.ValidateGetGraphData( mockTimePeriod, @@ -70,8 +74,10 @@ describe('ConsumptionFormatter service', () => { }) it('shoud return false because of wrong TimePeriod', () => { const wrongTimePeriod: TimePeriod = { - startDate: DateTime.fromISO('2020-10-05T00:00:00.000'), - endDate: DateTime.fromISO('2020-10-03T23:59:59.999'), + startDate: DateTime.fromISO('2020-10-05T00:00:00.000Z', { + zone: 'utc', + }), + endDate: DateTime.fromISO('2020-10-03T23:59:59.999Z', { zone: 'utc' }), } const result = consumptionValidatorService.ValidateGetGraphData( wrongTimePeriod, @@ -99,8 +105,10 @@ describe('ConsumptionFormatter service', () => { it('shoud return false because of HALF_AN_HOUR and ValidateTimePeriodLength', () => { fluidTypes = [0] //Only fluid without TimeStep incompatibilty const mockTimePeriodTooLong: TimePeriod = { - startDate: DateTime.fromISO('2020-10-01T00:00:00.000'), - endDate: DateTime.fromISO('2020-10-02T22:59:59.999'), + startDate: DateTime.fromISO('2020-10-01T00:00:00.000Z', { + zone: 'utc', + }), + endDate: DateTime.fromISO('2020-10-02T22:59:59.999Z', { zone: 'utc' }), } const result = consumptionValidatorService.ValidateGetGraphData( mockTimePeriodTooLong, @@ -111,8 +119,10 @@ describe('ConsumptionFormatter service', () => { }) it('shoud return false because of DAY and ValidateTimePeriodLength', () => { const mockTimePeriodTooLong: TimePeriod = { - startDate: DateTime.fromISO('2020-10-01T00:00:00.000'), - endDate: DateTime.fromISO('2020-12-01T22:59:59.999'), + startDate: DateTime.fromISO('2020-10-01T00:00:00.000Z', { + zone: 'utc', + }), + endDate: DateTime.fromISO('2020-12-01T22:59:59.999Z', { zone: 'utc' }), } const result = consumptionValidatorService.ValidateGetGraphData( mockTimePeriodTooLong, @@ -123,8 +133,10 @@ describe('ConsumptionFormatter service', () => { }) it('shoud return false because of MONTH and ValidateTimePeriodLength', () => { const mockTimePeriodTooLong: TimePeriod = { - startDate: DateTime.fromISO('2018-10-01T00:00:00.000'), - endDate: DateTime.fromISO('2020-12-01T22:59:59.999'), + startDate: DateTime.fromISO('2018-10-01T00:00:00.000Z', { + zone: 'utc', + }), + endDate: DateTime.fromISO('2020-12-01T22:59:59.999Z', { zone: 'utc' }), } const result = consumptionValidatorService.ValidateGetGraphData( mockTimePeriodTooLong, @@ -135,8 +147,10 @@ describe('ConsumptionFormatter service', () => { }) it('shoud return false because of YEAR and ValidateTimePeriodLength', () => { const mockTimePeriodTooLong: TimePeriod = { - startDate: DateTime.fromISO('2009-10-01T00:00:00.000'), - endDate: DateTime.fromISO('2020-12-01T22:59:59.999'), + startDate: DateTime.fromISO('2009-10-01T00:00:00.000Z', { + zone: 'utc', + }), + endDate: DateTime.fromISO('2020-12-01T22:59:59.999Z', { zone: 'utc' }), } const result = consumptionValidatorService.ValidateGetGraphData( mockTimePeriodTooLong, diff --git a/src/services/dateChart.service.spec.ts b/src/services/dateChart.service.spec.ts index 9f277f21e..a548f0038 100644 --- a/src/services/dateChart.service.spec.ts +++ b/src/services/dateChart.service.spec.ts @@ -7,11 +7,17 @@ import { FluidType } from 'enum/fluid.enum' describe('dateChart service', () => { describe('defineTimePeriod method', () => { const dateChartService = new DateChartService() - const refDate = DateTime.fromISO('2020-10-10T08:00:00.000') + const refDate = DateTime.fromISO('2020-10-10T08:00:00.000Z', { + zone: 'utc', + }) it("should return year-4 and year of reference date's year for year timestep", () => { - const expectedStartDate = DateTime.fromISO('2016-01-01T00:00:00.000') - const expectedEndDate = DateTime.fromISO('2020-01-01T00:00:00.000') + const expectedStartDate = DateTime.fromISO('2016-01-01T00:00:00.000Z', { + zone: 'utc', + }) + const expectedEndDate = DateTime.fromISO('2020-01-01T00:00:00.000Z', { + zone: 'utc', + }) const expectedTimePeriod: TimePeriod = { endDate: expectedEndDate, startDate: expectedStartDate, @@ -25,8 +31,12 @@ describe('dateChart service', () => { }) it("should return year-9 and year-5 reference date's for year timestep", () => { - const expectedStartDate = DateTime.fromISO('2011-01-01T00:00:00.000') - const expectedEndDate = DateTime.fromISO('2015-01-01T00:00:00.000') + const expectedStartDate = DateTime.fromISO('2011-01-01T00:00:00.000Z', { + zone: 'utc', + }) + const expectedEndDate = DateTime.fromISO('2015-01-01T00:00:00.000Z', { + zone: 'utc', + }) const expectedTimePeriod: TimePeriod = { endDate: expectedEndDate, startDate: expectedStartDate, @@ -40,8 +50,12 @@ describe('dateChart service', () => { }) it("should return year+1 and year+5 reference date's for year timestep", () => { - const expectedStartDate = DateTime.fromISO('2021-01-01T00:00:00.000') - const expectedEndDate = DateTime.fromISO('2025-01-01T00:00:00.000') + const expectedStartDate = DateTime.fromISO('2021-01-01T00:00:00.000Z', { + zone: 'utc', + }) + const expectedEndDate = DateTime.fromISO('2025-01-01T00:00:00.000Z', { + zone: 'utc', + }) const expectedTimePeriod: TimePeriod = { endDate: expectedEndDate, startDate: expectedStartDate, @@ -55,8 +69,12 @@ describe('dateChart service', () => { }) it("should return first and last month of reference date's year for month timestep", () => { - const expectedStartDate = DateTime.fromISO('2020-01-01T00:00:00.000') - const expectedEndDate = DateTime.fromISO('2020-12-01T00:00:00.000') + const expectedStartDate = DateTime.fromISO('2020-01-01T00:00:00.000Z', { + zone: 'utc', + }) + const expectedEndDate = DateTime.fromISO('2020-12-01T00:00:00.000Z', { + zone: 'utc', + }) const expectedTimePeriod: TimePeriod = { startDate: expectedStartDate, endDate: expectedEndDate, @@ -70,8 +88,12 @@ describe('dateChart service', () => { }) it("should return first and last month of reference date's year -1 for month timestep", () => { - const expectedStartDate = DateTime.fromISO('2019-01-01T00:00:00.000') - const expectedEndDate = DateTime.fromISO('2019-12-01T00:00:00.000') + const expectedStartDate = DateTime.fromISO('2019-01-01T00:00:00.000Z', { + zone: 'utc', + }) + const expectedEndDate = DateTime.fromISO('2019-12-01T00:00:00.000Z', { + zone: 'utc', + }) const expectedTimePeriod: TimePeriod = { endDate: expectedEndDate, startDate: expectedStartDate, @@ -85,8 +107,12 @@ describe('dateChart service', () => { }) it("should return first and last month of reference date's year +1 for month timestep", () => { - const expectedStartDate = DateTime.fromISO('2021-01-01T00:00:00.000') - const expectedEndDate = DateTime.fromISO('2021-12-01T00:00:00.000') + const expectedStartDate = DateTime.fromISO('2021-01-01T00:00:00.000Z', { + zone: 'utc', + }) + const expectedEndDate = DateTime.fromISO('2021-12-01T00:00:00.000Z', { + zone: 'utc', + }) const expectedTimePeriod: TimePeriod = { endDate: expectedEndDate, startDate: expectedStartDate, @@ -100,8 +126,12 @@ describe('dateChart service', () => { }) it("should return first and last day of reference date's month for day timestep", () => { - const expectedStartDate = DateTime.fromISO('2020-10-01T00:00:00.000') - const expectedEndDate = DateTime.fromISO('2020-10-31T00:00:00.000') + const expectedStartDate = DateTime.fromISO('2020-10-01T00:00:00.000Z', { + zone: 'utc', + }) + const expectedEndDate = DateTime.fromISO('2020-10-31T00:00:00.000Z', { + zone: 'utc', + }) const expectedTimePeriod: TimePeriod = { startDate: expectedStartDate, endDate: expectedEndDate, @@ -111,8 +141,12 @@ describe('dateChart service', () => { }) it("should return first and last day of reference date's month -1 for day timestep", () => { - const expectedStartDate = DateTime.fromISO('2020-09-01T00:00:00.000') - const expectedEndDate = DateTime.fromISO('2020-09-30T00:00:00.000') + const expectedStartDate = DateTime.fromISO('2020-09-01T00:00:00.000Z', { + zone: 'utc', + }) + const expectedEndDate = DateTime.fromISO('2020-09-30T00:00:00.000Z', { + zone: 'utc', + }) const expectedTimePeriod: TimePeriod = { startDate: expectedStartDate, endDate: expectedEndDate, @@ -122,8 +156,12 @@ describe('dateChart service', () => { }) it("should return first and last day of reference date's month +1 for day timestep", () => { - const expectedStartDate = DateTime.fromISO('2020-11-01T00:00:00.000') - const expectedEndDate = DateTime.fromISO('2020-11-30T00:00:00.000') + const expectedStartDate = DateTime.fromISO('2020-11-01T00:00:00.000Z', { + zone: 'utc', + }) + const expectedEndDate = DateTime.fromISO('2020-11-30T00:00:00.000Z', { + zone: 'utc', + }) const expectedTimePeriod: TimePeriod = { startDate: expectedStartDate, endDate: expectedEndDate, @@ -137,8 +175,12 @@ describe('dateChart service', () => { }) it("should return day at 00:00 and day at 23:00 of reference date's for hour timestep", () => { - const expectedStartDate = DateTime.fromISO('2020-10-10T00:00:00.000') - const expectedEndDate = DateTime.fromISO('2020-10-10T23:00:00.000') + const expectedStartDate = DateTime.fromISO('2020-10-10T00:00:00.000Z', { + zone: 'utc', + }) + const expectedEndDate = DateTime.fromISO('2020-10-10T23:00:00.000Z', { + zone: 'utc', + }) const expectedTimePeriod: TimePeriod = { endDate: expectedEndDate, startDate: expectedStartDate, @@ -152,8 +194,12 @@ describe('dateChart service', () => { }) it("should return previous day at 00:00 and day at 23:00 of reference date's for hour timestep", () => { - const expectedStartDate = DateTime.fromISO('2020-10-09T00:00:00.000') - const expectedEndDate = DateTime.fromISO('2020-10-09T23:00:00.000') + const expectedStartDate = DateTime.fromISO('2020-10-09T00:00:00.000Z', { + zone: 'utc', + }) + const expectedEndDate = DateTime.fromISO('2020-10-09T23:00:00.000Z', { + zone: 'utc', + }) const expectedTimePeriod: TimePeriod = { endDate: expectedEndDate, startDate: expectedStartDate, @@ -167,8 +213,12 @@ describe('dateChart service', () => { }) it("should return next day at 00:00 and day at 23:00 of reference date's for hour timestep", () => { - const expectedStartDate = DateTime.fromISO('2020-10-11T00:00:00.000') - const expectedEndDate = DateTime.fromISO('2020-10-11T23:00:00.000') + const expectedStartDate = DateTime.fromISO('2020-10-11T00:00:00.000Z', { + zone: 'utc', + }) + const expectedEndDate = DateTime.fromISO('2020-10-11T23:00:00.000Z', { + zone: 'utc', + }) const expectedTimePeriod: TimePeriod = { endDate: expectedEndDate, startDate: expectedStartDate, @@ -182,8 +232,12 @@ describe('dateChart service', () => { }) it("should return day at 00:00 and day at 23:30 of reference date's for half-hour timestep", () => { - const expectedStartDate = DateTime.fromISO('2020-10-10T00:00:00.000') - const expectedEndDate = DateTime.fromISO('2020-10-10T23:30:00.000') + const expectedStartDate = DateTime.fromISO('2020-10-10T00:00:00.000Z', { + zone: 'utc', + }) + const expectedEndDate = DateTime.fromISO('2020-10-10T23:30:00.000Z', { + zone: 'utc', + }) const expectedTimePeriod: TimePeriod = { endDate: expectedEndDate, startDate: expectedStartDate, @@ -197,8 +251,12 @@ describe('dateChart service', () => { }) it("should return previous day at 00:00 and day at 23:30 of reference date's for half-hour timestep", () => { - const expectedStartDate = DateTime.fromISO('2020-10-09T00:00:00.000') - const expectedEndDate = DateTime.fromISO('2020-10-09T23:30:00.000') + const expectedStartDate = DateTime.fromISO('2020-10-09T00:00:00.000Z', { + zone: 'utc', + }) + const expectedEndDate = DateTime.fromISO('2020-10-09T23:30:00.000Z', { + zone: 'utc', + }) const expectedTimePeriod: TimePeriod = { endDate: expectedEndDate, startDate: expectedStartDate, @@ -212,8 +270,12 @@ describe('dateChart service', () => { }) it("should return next day at 00:00 and day at 23:30 of reference date's for half-hour timestep", () => { - const expectedStartDate = DateTime.fromISO('2020-10-11T00:00:00.000') - const expectedEndDate = DateTime.fromISO('2020-10-11T23:30:00.000') + const expectedStartDate = DateTime.fromISO('2020-10-11T00:00:00.000Z', { + zone: 'utc', + }) + const expectedEndDate = DateTime.fromISO('2020-10-11T23:30:00.000Z', { + zone: 'utc', + }) const expectedTimePeriod: TimePeriod = { endDate: expectedEndDate, startDate: expectedStartDate, @@ -237,10 +299,14 @@ describe('dateChart service', () => { describe('defineFirstStepDate method', () => { const dateChartService = new DateChartService() - const refDate = DateTime.fromISO('2020-10-10T08:00:00.000') + const refDate = DateTime.fromISO('2020-10-10T08:00:00.000Z', { + zone: 'utc', + }) it("should return year-4 of reference date's year for year timestep", () => { - const expectedStartDate = DateTime.fromISO('2016-01-01T00:00:00.000') + const expectedStartDate = DateTime.fromISO('2016-01-01T00:00:00.000Z', { + zone: 'utc', + }) const result = dateChartService.defineFirstStepDate( refDate, TimeStep.YEAR, @@ -250,7 +316,9 @@ describe('dateChart service', () => { }) it("should return year-9 reference date's for year timestep", () => { - const expectedStartDate = DateTime.fromISO('2011-01-01T00:00:00.000') + const expectedStartDate = DateTime.fromISO('2011-01-01T00:00:00.000Z', { + zone: 'utc', + }) const result = dateChartService.defineFirstStepDate( refDate, TimeStep.YEAR, @@ -260,7 +328,9 @@ describe('dateChart service', () => { }) it("should return year+5 reference date's for year timestep", () => { - const expectedStartDate = DateTime.fromISO('2021-01-01T00:00:00.000') + const expectedStartDate = DateTime.fromISO('2021-01-01T00:00:00.000Z', { + zone: 'utc', + }) const result = dateChartService.defineFirstStepDate( refDate, TimeStep.YEAR, @@ -270,7 +340,9 @@ describe('dateChart service', () => { }) it("should return first month of reference date's year for month timestep", () => { - const expectedStartDate = DateTime.fromISO('2020-01-01T00:00:00.000') + const expectedStartDate = DateTime.fromISO('2020-01-01T00:00:00.000Z', { + zone: 'utc', + }) const result = dateChartService.defineFirstStepDate( refDate, TimeStep.MONTH, @@ -280,7 +352,9 @@ describe('dateChart service', () => { }) it("should return first month of reference date's year -1 for month timestep", () => { - const expectedStartDate = DateTime.fromISO('2019-01-01T00:00:00.000') + const expectedStartDate = DateTime.fromISO('2019-01-01T00:00:00.000Z', { + zone: 'utc', + }) const result = dateChartService.defineFirstStepDate( refDate, TimeStep.MONTH, @@ -290,7 +364,9 @@ describe('dateChart service', () => { }) it("should return first month of reference date's year +1 for month timestep", () => { - const expectedStartDate = DateTime.fromISO('2021-01-01T00:00:00.000') + const expectedStartDate = DateTime.fromISO('2021-01-01T00:00:00.000Z', { + zone: 'utc', + }) const result = dateChartService.defineFirstStepDate( refDate, TimeStep.MONTH, @@ -300,7 +376,9 @@ describe('dateChart service', () => { }) it("should return first day of reference date's month for day timestep", () => { - const expectedStartDate = DateTime.fromISO('2020-10-01T00:00:00.000') + const expectedStartDate = DateTime.fromISO('2020-10-01T00:00:00.000Z', { + zone: 'utc', + }) const result = dateChartService.defineFirstStepDate( refDate, TimeStep.DAY, @@ -310,7 +388,9 @@ describe('dateChart service', () => { }) it("should return first day of reference date's month -1 for day timestep", () => { - const expectedStartDate = DateTime.fromISO('2020-09-01T00:00:00.000') + const expectedStartDate = DateTime.fromISO('2020-09-01T00:00:00.000Z', { + zone: 'utc', + }) const result = dateChartService.defineFirstStepDate( refDate, TimeStep.DAY, @@ -320,7 +400,9 @@ describe('dateChart service', () => { }) it("should return first day of reference date's month +1 for day timestep", () => { - const expectedStartDate = DateTime.fromISO('2020-11-01T00:00:00.000') + const expectedStartDate = DateTime.fromISO('2020-11-01T00:00:00.000Z', { + zone: 'utc', + }) const result = dateChartService.defineFirstStepDate( refDate, TimeStep.DAY, @@ -332,10 +414,14 @@ describe('dateChart service', () => { describe('defineLastStepDate method', () => { const dateChartService = new DateChartService() - const refDate = DateTime.fromISO('2020-10-10T08:00:00.000') + const refDate = DateTime.fromISO('2020-10-10T08:00:00.000Z', { + zone: 'utc', + }) it("should return year of reference date's year for year timestep", () => { - const expectedEndDate = DateTime.fromISO('2020-01-01T00:00:00.000') + const expectedEndDate = DateTime.fromISO('2020-01-01T00:00:00.000Z', { + zone: 'utc', + }) const result = dateChartService.defineLastStepDate( refDate, TimeStep.YEAR, @@ -345,7 +431,9 @@ describe('dateChart service', () => { }) it("should return year-5 reference date's for year timestep", () => { - const expectedEndDate = DateTime.fromISO('2015-01-01T00:00:00.000') + const expectedEndDate = DateTime.fromISO('2015-01-01T00:00:00.000Z', { + zone: 'utc', + }) const result = dateChartService.defineLastStepDate( refDate, TimeStep.YEAR, @@ -355,7 +443,9 @@ describe('dateChart service', () => { }) it("should return year+5 reference date's for year timestep", () => { - const expectedEndDate = DateTime.fromISO('2025-01-01T00:00:00.000') + const expectedEndDate = DateTime.fromISO('2025-01-01T00:00:00.000Z', { + zone: 'utc', + }) const result = dateChartService.defineLastStepDate( refDate, TimeStep.YEAR, @@ -365,7 +455,9 @@ describe('dateChart service', () => { }) it("should return last month of reference date's year for month timestep", () => { - const expectedEndDate = DateTime.fromISO('2020-12-01T00:00:00.000') + const expectedEndDate = DateTime.fromISO('2020-12-01T00:00:00.000Z', { + zone: 'utc', + }) const result = dateChartService.defineLastStepDate( refDate, TimeStep.MONTH, @@ -375,7 +467,9 @@ describe('dateChart service', () => { }) it("should return last month of reference date's year -1 for month timestep", () => { - const expectedEndDate = DateTime.fromISO('2019-12-01T00:00:00.000') + const expectedEndDate = DateTime.fromISO('2019-12-01T00:00:00.000Z', { + zone: 'utc', + }) const result = dateChartService.defineLastStepDate( refDate, TimeStep.MONTH, @@ -385,7 +479,9 @@ describe('dateChart service', () => { }) it("should return last month of reference date's year +1 for month timestep", () => { - const expectedEndDate = DateTime.fromISO('2021-12-01T00:00:00.000') + const expectedEndDate = DateTime.fromISO('2021-12-01T00:00:00.000Z', { + zone: 'utc', + }) const result = dateChartService.defineLastStepDate( refDate, TimeStep.MONTH, @@ -395,7 +491,9 @@ describe('dateChart service', () => { }) it("should return last day of reference date's month for day timestep", () => { - const expectedEndDate = DateTime.fromISO('2020-10-31T00:00:00.000') + const expectedEndDate = DateTime.fromISO('2020-10-31T00:00:00.000Z', { + zone: 'utc', + }) const result = dateChartService.defineLastStepDate( refDate, TimeStep.DAY, @@ -405,7 +503,9 @@ describe('dateChart service', () => { }) it("should return last day of reference date's month -1 for day timestep", () => { - const expectedEndDate = DateTime.fromISO('2020-09-30T00:00:00.000') + const expectedEndDate = DateTime.fromISO('2020-09-30T00:00:00.000Z', { + zone: 'utc', + }) const result = dateChartService.defineLastStepDate( refDate, TimeStep.DAY, @@ -415,7 +515,9 @@ describe('dateChart service', () => { }) it("should return last day of reference date's month +1 for day timestep", () => { - const expectedEndDate = DateTime.fromISO('2020-11-30T00:00:00.000') + const expectedEndDate = DateTime.fromISO('2020-11-30T00:00:00.000Z', { + zone: 'utc', + }) const result = dateChartService.defineLastStepDate( refDate, TimeStep.DAY, @@ -429,8 +531,12 @@ describe('dateChart service', () => { const dateChartService = new DateChartService() it('should return true for year comparaison', () => { - const firstDate = DateTime.fromISO('2020-10-31T00:00:00.000') - const secondDate = DateTime.fromISO('2020-12-31T11:11:11.111') + const firstDate = DateTime.fromISO('2020-10-31T00:00:00.000Z', { + zone: 'utc', + }) + const secondDate = DateTime.fromISO('2020-12-31T11:11:11.111Z', { + zone: 'utc', + }) const result = dateChartService.compareStepDate( TimeStep.YEAR, firstDate, @@ -440,8 +546,12 @@ describe('dateChart service', () => { }) it('should return false for year comparaison', () => { - const firstDate = DateTime.fromISO('2020-10-31T00:00:00.000') - const secondDate = DateTime.fromISO('2021-10-30T00:00:00.000') + const firstDate = DateTime.fromISO('2020-10-31T00:00:00.000Z', { + zone: 'utc', + }) + const secondDate = DateTime.fromISO('2021-10-30T00:00:00.000Z', { + zone: 'utc', + }) const result = dateChartService.compareStepDate( TimeStep.YEAR, firstDate, @@ -451,8 +561,12 @@ describe('dateChart service', () => { }) it('should return true for month comparaison', () => { - const firstDate = DateTime.fromISO('2020-10-31T00:00:00.000') - const secondDate = DateTime.fromISO('2020-10-30T11:11:11.111') + const firstDate = DateTime.fromISO('2020-10-31T00:00:00.000Z', { + zone: 'utc', + }) + const secondDate = DateTime.fromISO('2020-10-30T11:11:11.111Z', { + zone: 'utc', + }) const result = dateChartService.compareStepDate( TimeStep.MONTH, firstDate, @@ -462,8 +576,12 @@ describe('dateChart service', () => { }) it('should return false for month comparaison', () => { - const firstDate = DateTime.fromISO('2020-10-31T00:00:00.000') - const secondDate = DateTime.fromISO('2020-09-31T00:00:00.000') + const firstDate = DateTime.fromISO('2020-10-31T00:00:00.000Z', { + zone: 'utc', + }) + const secondDate = DateTime.fromISO('2020-09-31T00:00:00.000Z', { + zone: 'utc', + }) const result = dateChartService.compareStepDate( TimeStep.MONTH, firstDate, @@ -473,8 +591,12 @@ describe('dateChart service', () => { }) it('should return true for day comparaison', () => { - const firstDate = DateTime.fromISO('2020-10-31T00:00:00.000') - const secondDate = DateTime.fromISO('2020-10-31T11:11:11.111') + const firstDate = DateTime.fromISO('2020-10-31T00:00:00.000Z', { + zone: 'utc', + }) + const secondDate = DateTime.fromISO('2020-10-31T11:11:11.111Z', { + zone: 'utc', + }) const result = dateChartService.compareStepDate( TimeStep.DAY, firstDate, @@ -484,8 +606,12 @@ describe('dateChart service', () => { }) it('should return false for day comparaison', () => { - const firstDate = DateTime.fromISO('2020-10-31T00:00:00.000') - const secondDate = DateTime.fromISO('2020-10-30T00:00:00.000') + const firstDate = DateTime.fromISO('2020-10-31T00:00:00.000Z', { + zone: 'utc', + }) + const secondDate = DateTime.fromISO('2020-10-30T00:00:00.000Z', { + zone: 'utc', + }) const result = dateChartService.compareStepDate( TimeStep.DAY, firstDate, @@ -495,8 +621,12 @@ describe('dateChart service', () => { }) it('should return true for hour comparaison', () => { - const firstDate = DateTime.fromISO('2020-10-31T00:00:00.000') - const secondDate = DateTime.fromISO('2020-10-31T00:11:11.111') + const firstDate = DateTime.fromISO('2020-10-31T00:00:00.000Z', { + zone: 'utc', + }) + const secondDate = DateTime.fromISO('2020-10-31T00:11:11.111Z', { + zone: 'utc', + }) const result = dateChartService.compareStepDate( TimeStep.HOUR, firstDate, @@ -506,8 +636,12 @@ describe('dateChart service', () => { }) it('should return false for hour comparaison', () => { - const firstDate = DateTime.fromISO('2020-10-31T00:00:00.000') - const secondDate = DateTime.fromISO('2020-10-31T01:00:00.000') + const firstDate = DateTime.fromISO('2020-10-31T00:00:00.000Z', { + zone: 'utc', + }) + const secondDate = DateTime.fromISO('2020-10-31T01:00:00.000Z', { + zone: 'utc', + }) const result = dateChartService.compareStepDate( TimeStep.HOUR, firstDate, @@ -517,8 +651,12 @@ describe('dateChart service', () => { }) it('should return true for half-hour comparaison', () => { - const firstDate = DateTime.fromISO('2020-10-31T00:00:00.000') - const secondDate = DateTime.fromISO('2020-10-31T00:00:11.111') + const firstDate = DateTime.fromISO('2020-10-31T00:00:00.000Z', { + zone: 'utc', + }) + const secondDate = DateTime.fromISO('2020-10-31T00:00:11.111Z', { + zone: 'utc', + }) const result = dateChartService.compareStepDate( TimeStep.HALF_AN_HOUR, firstDate, @@ -528,8 +666,12 @@ describe('dateChart service', () => { }) it('should return false for half-hour comparaison', () => { - const firstDate = DateTime.fromISO('2020-10-31T00:00:00.000') - const secondDate = DateTime.fromISO('2020-10-31T00:30:00.000') + const firstDate = DateTime.fromISO('2020-10-31T00:00:00.000Z', { + zone: 'utc', + }) + const secondDate = DateTime.fromISO('2020-10-31T00:30:00.000Z', { + zone: 'utc', + }) const result = dateChartService.compareStepDate( TimeStep.HALF_AN_HOUR, firstDate, @@ -539,8 +681,12 @@ describe('dateChart service', () => { }) it('should throw error for unknown TimeStep', () => { - const firstDate = DateTime.fromISO('2020-10-31T00:00:00.000') - const secondDate = DateTime.fromISO('2020-10-31T00:30:00.000') + const firstDate = DateTime.fromISO('2020-10-31T00:00:00.000Z', { + zone: 'utc', + }) + const secondDate = DateTime.fromISO('2020-10-31T00:30:00.000Z', { + zone: 'utc', + }) try { dateChartService.compareStepDate(4, firstDate, secondDate) } catch (error) { @@ -629,7 +775,9 @@ describe('dateChart service', () => { describe('formatDetailedDate method', () => { const dateChartService = new DateChartService() - const refDate = DateTime.fromISO('2020-10-10T08:08:08.008') + const refDate = DateTime.fromISO('2020-10-10T08:08:08.008Z', { + zone: 'utc', + }) it('should return input date for year format', () => { const result = dateChartService.formatDetailedDate(refDate, TimeStep.YEAR) @@ -637,7 +785,9 @@ describe('dateChart service', () => { }) it('should return date with first month, first day 00:00:00 for month format', () => { - const exceptedDate = DateTime.fromISO('2020-01-01T00:00:00.000') + const exceptedDate = DateTime.fromISO('2020-01-01T00:00:00.000Z', { + zone: 'utc', + }) const result = dateChartService.formatDetailedDate( refDate, TimeStep.MONTH @@ -646,19 +796,25 @@ describe('dateChart service', () => { }) it('should return date with first day 00:00:00 date day format', () => { - const exceptedDate = DateTime.fromISO('2020-10-01T00:00:00.000') + const exceptedDate = DateTime.fromISO('2020-10-01T00:00:00.000Z', { + zone: 'utc', + }) const result = dateChartService.formatDetailedDate(refDate, TimeStep.DAY) expect(result).toEqual(exceptedDate) }) it('should return date with 00:00:00 date hour format', () => { - const exceptedDate = DateTime.fromISO('2020-10-10T00:00:00.000') + const exceptedDate = DateTime.fromISO('2020-10-10T00:00:00.000Z', { + zone: 'utc', + }) const result = dateChartService.formatDetailedDate(refDate, TimeStep.HOUR) expect(result).toEqual(exceptedDate) }) it('should return date with 0m 0s 0ms date hour format', () => { - const exceptedDate = DateTime.fromISO('2020-10-10T08:00:00.000') + const exceptedDate = DateTime.fromISO('2020-10-10T08:00:00.000Z', { + zone: 'utc', + }) const result = dateChartService.formatDetailedDate( refDate, TimeStep.HALF_AN_HOUR @@ -674,13 +830,19 @@ describe('dateChart service', () => { describe('incrementDate method', () => { const dateChartService = new DateChartService() - const lastDataDate = DateTime.fromISO('2020-10-10T08:08:08.008') + const lastDataDate = DateTime.fromISO('2020-10-10T08:08:08.008Z', { + zone: 'utc', + }) it('should return previous year and same index for year timestep', () => { - const initialDate = DateTime.fromISO('2020-10-10T08:08:08.008') + const initialDate = DateTime.fromISO('2020-10-10T08:08:08.008Z', { + zone: 'utc', + }) const exceptedResult = { incrementIndex: 0, - incrementedDate: DateTime.fromISO('2019-10-10T08:08:08.008'), + incrementedDate: DateTime.fromISO('2019-10-10T08:08:08.008Z', { + zone: 'utc', + }), } const result = dateChartService.incrementDate( -1, @@ -692,10 +854,14 @@ describe('dateChart service', () => { }) it('should return previous year and next index for year timestep and lastDataDate >= initialDate-1', () => { - const initialDate = DateTime.fromISO('2021-10-10T08:08:08.008') + const initialDate = DateTime.fromISO('2021-10-10T08:08:08.008Z', { + zone: 'utc', + }) const exceptedResult = { incrementIndex: 1, - incrementedDate: DateTime.fromISO('2020-10-10T08:08:08.008'), + incrementedDate: DateTime.fromISO('2020-10-10T08:08:08.008Z', { + zone: 'utc', + }), } const result = dateChartService.incrementDate( -1, @@ -707,10 +873,14 @@ describe('dateChart service', () => { }) it('should return previous year and next index for year timestep and lastDataDate <= initialDate-1', () => { - const initialDate = DateTime.fromISO('2026-10-10T08:08:08.008') + const initialDate = DateTime.fromISO('2026-10-10T08:08:08.008Z', { + zone: 'utc', + }) const exceptedResult = { incrementIndex: 1, - incrementedDate: DateTime.fromISO('2025-10-10T08:08:08.008'), + incrementedDate: DateTime.fromISO('2025-10-10T08:08:08.008Z', { + zone: 'utc', + }), } const result = dateChartService.incrementDate( -1, @@ -722,10 +892,14 @@ describe('dateChart service', () => { }) it('should return next year and same index for year timestep', () => { - const initialDate = DateTime.fromISO('2019-10-10T08:08:08.008') + const initialDate = DateTime.fromISO('2019-10-10T08:08:08.008Z', { + zone: 'utc', + }) const exceptedResult = { incrementIndex: 0, - incrementedDate: DateTime.fromISO('2020-10-10T08:08:08.008'), + incrementedDate: DateTime.fromISO('2020-10-10T08:08:08.008Z', { + zone: 'utc', + }), } const result = dateChartService.incrementDate( 1, @@ -737,10 +911,14 @@ describe('dateChart service', () => { }) it('should return next year and previous index for year timestep and lastDataDate >= initialDate+1', () => { - const initialDate = DateTime.fromISO('2015-10-10T08:08:08.008') + const initialDate = DateTime.fromISO('2015-10-10T08:08:08.008Z', { + zone: 'utc', + }) const exceptedResult = { incrementIndex: -1, - incrementedDate: DateTime.fromISO('2016-10-10T08:08:08.008'), + incrementedDate: DateTime.fromISO('2016-10-10T08:08:08.008Z', { + zone: 'utc', + }), } const result = dateChartService.incrementDate( 1, @@ -752,10 +930,14 @@ describe('dateChart service', () => { }) it('should return next year and previous index for year timestep and lastDataDate <= initialDate+1', () => { - const initialDate = DateTime.fromISO('2020-10-10T08:08:08.008') + const initialDate = DateTime.fromISO('2020-10-10T08:08:08.008Z', { + zone: 'utc', + }) const exceptedResult = { incrementIndex: -1, - incrementedDate: DateTime.fromISO('2021-10-10T08:08:08.008'), + incrementedDate: DateTime.fromISO('2021-10-10T08:08:08.008Z', { + zone: 'utc', + }), } const result = dateChartService.incrementDate( 1, @@ -767,10 +949,14 @@ describe('dateChart service', () => { }) it('should return previous month and same index for month timestep', () => { - const initialDate = DateTime.fromISO('2020-10-10T08:08:08.008') + const initialDate = DateTime.fromISO('2020-10-10T08:08:08.008Z', { + zone: 'utc', + }) const exceptedResult = { incrementIndex: 0, - incrementedDate: DateTime.fromISO('2020-09-10T08:08:08.008'), + incrementedDate: DateTime.fromISO('2020-09-10T08:08:08.008Z', { + zone: 'utc', + }), } const result = dateChartService.incrementDate( -1, @@ -782,10 +968,14 @@ describe('dateChart service', () => { }) it('should return previous month and next index for month timestep', () => { - const initialDate = DateTime.fromISO('2020-01-10T08:08:08.008') + const initialDate = DateTime.fromISO('2020-01-10T08:08:08.008Z', { + zone: 'utc', + }) const exceptedResult = { incrementIndex: 1, - incrementedDate: DateTime.fromISO('2019-12-10T08:08:08.008'), + incrementedDate: DateTime.fromISO('2019-12-10T08:08:08.008Z', { + zone: 'utc', + }), } const result = dateChartService.incrementDate( -1, @@ -797,10 +987,14 @@ describe('dateChart service', () => { }) it('should return next month and same index for month timestep', () => { - const initialDate = DateTime.fromISO('2020-10-10T08:08:08.008') + const initialDate = DateTime.fromISO('2020-10-10T08:08:08.008Z', { + zone: 'utc', + }) const exceptedResult = { incrementIndex: 0, - incrementedDate: DateTime.fromISO('2020-11-10T08:08:08.008'), + incrementedDate: DateTime.fromISO('2020-11-10T08:08:08.008Z', { + zone: 'utc', + }), } const result = dateChartService.incrementDate( 1, @@ -812,10 +1006,14 @@ describe('dateChart service', () => { }) it('should return next month and previous index for month timestep', () => { - const initialDate = DateTime.fromISO('2020-12-10T08:08:08.008') + const initialDate = DateTime.fromISO('2020-12-10T08:08:08.008Z', { + zone: 'utc', + }) const exceptedResult = { incrementIndex: -1, - incrementedDate: DateTime.fromISO('2021-01-10T08:08:08.008'), + incrementedDate: DateTime.fromISO('2021-01-10T08:08:08.008Z', { + zone: 'utc', + }), } const result = dateChartService.incrementDate( 1, @@ -827,10 +1025,14 @@ describe('dateChart service', () => { }) it('should return previous day and same index for day timestep', () => { - const initialDate = DateTime.fromISO('2020-10-10T08:08:08.008') + const initialDate = DateTime.fromISO('2020-10-10T08:08:08.008Z', { + zone: 'utc', + }) const exceptedResult = { incrementIndex: 0, - incrementedDate: DateTime.fromISO('2020-10-09T08:08:08.008'), + incrementedDate: DateTime.fromISO('2020-10-09T08:08:08.008Z', { + zone: 'utc', + }), } const result = dateChartService.incrementDate( -1, @@ -842,10 +1044,14 @@ describe('dateChart service', () => { }) it('should return previous day and next index for day timestep', () => { - const initialDate = DateTime.fromISO('2020-10-01T08:08:08.008') + const initialDate = DateTime.fromISO('2020-10-01T08:08:08.008Z', { + zone: 'utc', + }) const exceptedResult = { incrementIndex: 1, - incrementedDate: DateTime.fromISO('2020-09-30T08:08:08.008'), + incrementedDate: DateTime.fromISO('2020-09-30T08:08:08.008Z', { + zone: 'utc', + }), } const result = dateChartService.incrementDate( -1, @@ -857,10 +1063,14 @@ describe('dateChart service', () => { }) it('should return next day and same index for day timestep', () => { - const initialDate = DateTime.fromISO('2020-10-10T08:08:08.008') + const initialDate = DateTime.fromISO('2020-10-10T08:08:08.008Z', { + zone: 'utc', + }) const exceptedResult = { incrementIndex: 0, - incrementedDate: DateTime.fromISO('2020-10-11T08:08:08.008'), + incrementedDate: DateTime.fromISO('2020-10-11T08:08:08.008Z', { + zone: 'utc', + }), } const result = dateChartService.incrementDate( 1, @@ -872,10 +1082,14 @@ describe('dateChart service', () => { }) it('should return next day and previous index for day timestep', () => { - const initialDate = DateTime.fromISO('2020-10-31T08:08:08.008') + const initialDate = DateTime.fromISO('2020-10-31T08:08:08.008Z', { + zone: 'utc', + }) const exceptedResult = { incrementIndex: -1, - incrementedDate: DateTime.fromISO('2020-11-01T08:08:08.008'), + incrementedDate: DateTime.fromISO('2020-11-01T08:08:08.008Z', { + zone: 'utc', + }), } const result = dateChartService.incrementDate( 1, @@ -887,10 +1101,14 @@ describe('dateChart service', () => { }) it('should return previous hour and same index for hour timestep', () => { - const initialDate = DateTime.fromISO('2020-10-10T08:08:08.008') + const initialDate = DateTime.fromISO('2020-10-10T08:08:08.008Z', { + zone: 'utc', + }) const exceptedResult = { incrementIndex: 0, - incrementedDate: DateTime.fromISO('2020-10-10T07:08:08.008'), + incrementedDate: DateTime.fromISO('2020-10-10T07:08:08.008Z', { + zone: 'utc', + }), } const result = dateChartService.incrementDate( -1, @@ -902,10 +1120,14 @@ describe('dateChart service', () => { }) it('should return previous hour and next index for hour timestep', () => { - const initialDate = DateTime.fromISO('2020-10-01T00:08:08.008') + const initialDate = DateTime.fromISO('2020-10-01T00:08:08.008Z', { + zone: 'utc', + }) const exceptedResult = { incrementIndex: 1, - incrementedDate: DateTime.fromISO('2020-09-30T23:08:08.008'), + incrementedDate: DateTime.fromISO('2020-09-30T23:08:08.008Z', { + zone: 'utc', + }), } const result = dateChartService.incrementDate( -1, @@ -917,10 +1139,14 @@ describe('dateChart service', () => { }) it('should return next hour and same index for hour timestep', () => { - const initialDate = DateTime.fromISO('2020-10-10T08:08:08.008') + const initialDate = DateTime.fromISO('2020-10-10T08:08:08.008Z', { + zone: 'utc', + }) const exceptedResult = { incrementIndex: 0, - incrementedDate: DateTime.fromISO('2020-10-10T09:08:08.008'), + incrementedDate: DateTime.fromISO('2020-10-10T09:08:08.008Z', { + zone: 'utc', + }), } const result = dateChartService.incrementDate( 1, @@ -932,10 +1158,14 @@ describe('dateChart service', () => { }) it('should return next hour and previous index for hour timestep', () => { - const initialDate = DateTime.fromISO('2020-10-10T23:08:08.008') + const initialDate = DateTime.fromISO('2020-10-10T23:08:08.008Z', { + zone: 'utc', + }) const exceptedResult = { incrementIndex: -1, - incrementedDate: DateTime.fromISO('2020-10-11T00:08:08.008'), + incrementedDate: DateTime.fromISO('2020-10-11T00:08:08.008Z', { + zone: 'utc', + }), } const result = dateChartService.incrementDate( 1, @@ -947,10 +1177,14 @@ describe('dateChart service', () => { }) it('should return previous half-hour and same index for half-hour timestep', () => { - const initialDate = DateTime.fromISO('2020-10-10T08:00:08.008') + const initialDate = DateTime.fromISO('2020-10-10T08:00:08.008Z', { + zone: 'utc', + }) const exceptedResult = { incrementIndex: 0, - incrementedDate: DateTime.fromISO('2020-10-10T07:30:08.008'), + incrementedDate: DateTime.fromISO('2020-10-10T07:30:08.008Z', { + zone: 'utc', + }), } const result = dateChartService.incrementDate( -1, @@ -962,10 +1196,14 @@ describe('dateChart service', () => { }) it('should return previous half-hour and next index for half-hour timestep', () => { - const initialDate = DateTime.fromISO('2020-10-01T00:00:08.008') + const initialDate = DateTime.fromISO('2020-10-01T00:00:08.008Z', { + zone: 'utc', + }) const exceptedResult = { incrementIndex: 1, - incrementedDate: DateTime.fromISO('2020-09-30T23:30:08.008'), + incrementedDate: DateTime.fromISO('2020-09-30T23:30:08.008Z', { + zone: 'utc', + }), } const result = dateChartService.incrementDate( -1, @@ -977,10 +1215,14 @@ describe('dateChart service', () => { }) it('should return next half-hour and same index for half-hour timestep', () => { - const initialDate = DateTime.fromISO('2020-10-10T08:00:08.008') + const initialDate = DateTime.fromISO('2020-10-10T08:00:08.008Z', { + zone: 'utc', + }) const exceptedResult = { incrementIndex: 0, - incrementedDate: DateTime.fromISO('2020-10-10T08:30:08.008'), + incrementedDate: DateTime.fromISO('2020-10-10T08:30:08.008Z', { + zone: 'utc', + }), } const result = dateChartService.incrementDate( 1, @@ -992,10 +1234,14 @@ describe('dateChart service', () => { }) it('should return next half-hour and previous index for half-hour timestep', () => { - const initialDate = DateTime.fromISO('2020-10-10T23:30:08.008') + const initialDate = DateTime.fromISO('2020-10-10T23:30:08.008Z', { + zone: 'utc', + }) const exceptedResult = { incrementIndex: -1, - incrementedDate: DateTime.fromISO('2020-10-11T00:00:08.008'), + incrementedDate: DateTime.fromISO('2020-10-11T00:00:08.008Z', { + zone: 'utc', + }), } const result = dateChartService.incrementDate( 1, @@ -1009,12 +1255,15 @@ describe('dateChart service', () => { describe('isDataToCome method', () => { const dateChartService = new DateChartService() - const today = DateTime.local() + const today = DateTime.local().setZone('utc', { + keepLocalTime: true, + }) it('should return true for electricity fluidType and dataLoad with date < today-1', () => { const dataLoad: Dataload = { date: today, value: 0, + valueDetail: null, } const result = dateChartService.isDataToCome( dataLoad, @@ -1027,6 +1276,7 @@ describe('dateChart service', () => { const dataLoad: Dataload = { date: today.plus({ day: -1 }), value: 0, + valueDetail: null, } const result = dateChartService.isDataToCome( dataLoad, @@ -1039,6 +1289,7 @@ describe('dateChart service', () => { const dataLoad: Dataload = { date: today.plus({ day: -1 }), value: 0, + valueDetail: null, } const result = dateChartService.isDataToCome(dataLoad, FluidType.GAS) expect(result).toBe(true) @@ -1048,6 +1299,7 @@ describe('dateChart service', () => { const dataLoad: Dataload = { date: today.plus({ day: -2 }), value: 0, + valueDetail: null, } const result = dateChartService.isDataToCome(dataLoad, FluidType.GAS) expect(result).toBe(false) @@ -1057,6 +1309,7 @@ describe('dateChart service', () => { const dataLoad: Dataload = { date: today.plus({ day: -2 }), value: 0, + valueDetail: null, } const result = dateChartService.isDataToCome(dataLoad, FluidType.WATER) expect(result).toBe(true) @@ -1066,6 +1319,7 @@ describe('dateChart service', () => { const dataLoad: Dataload = { date: today.plus({ day: -3 }), value: 0, + valueDetail: null, } const result = dateChartService.isDataToCome(dataLoad, FluidType.WATER) expect(result).toBe(false) diff --git a/src/services/duel.service.spec.ts b/src/services/duel.service.spec.ts index 2b4ee94c4..043c86f3c 100644 --- a/src/services/duel.service.spec.ts +++ b/src/services/duel.service.spec.ts @@ -111,14 +111,16 @@ describe('Duel service', () => { jest .spyOn(DateTime, 'local') .mockReturnValue( - DateTime.fromISO('2020-10-01T00:00:00.000', { zone: 'utc' }) + DateTime.fromISO('2020-10-01T00:00:00.000Z', { zone: 'utc' }) ) const result = await duelService.startUserDuel(duelData) const mockUpdatedDuel: UserDuel = { ...duelData, state: UserDuelState.ONGOING, - startDate: DateTime.fromISO('2020-10-01T00:00:00.000', { zone: 'utc' }), + startDate: DateTime.fromISO('2020-10-01T00:00:00.000Z', { + zone: 'utc', + }), } expect(result).toEqual(mockUpdatedDuel) }) diff --git a/src/services/fluid.service.spec.ts b/src/services/fluid.service.spec.ts index c5c5f2ade..d5f5c4f3a 100644 --- a/src/services/fluid.service.spec.ts +++ b/src/services/fluid.service.spec.ts @@ -59,9 +59,15 @@ describe('FLuid service', () => { describe('getFluidStatus method', () => { it('shoud return fluid status for all fluids', async () => { const mockLastDataDates: (DateTime | null)[] = [ - DateTime.local(), - DateTime.local(), - DateTime.local(), + DateTime.local().setZone('utc', { + keepLocalTime: true, + }), + DateTime.local().setZone('utc', { + keepLocalTime: true, + }), + DateTime.local().setZone('utc', { + keepLocalTime: true, + }), ] const mockResult: FluidStatus[] = [ { @@ -142,9 +148,15 @@ describe('FLuid service', () => { it('shoud return fluid status with NOT_CONNECTED status when no accounts', async () => { const mockLastDataDates: (DateTime | null)[] = [ - DateTime.local(), - DateTime.local(), - DateTime.local(), + DateTime.local().setZone('utc', { + keepLocalTime: true, + }), + DateTime.local().setZone('utc', { + keepLocalTime: true, + }), + DateTime.local().setZone('utc', { + keepLocalTime: true, + }), ] const mockResult: FluidStatus[] = [ { @@ -225,9 +237,15 @@ describe('FLuid service', () => { it('shoud return fluid status with KONNECTOR_NOT_FOUND status when no konnector', async () => { const mockLastDataDates: (DateTime | null)[] = [ - DateTime.local(), - DateTime.local(), - DateTime.local(), + DateTime.local().setZone('utc', { + keepLocalTime: true, + }), + DateTime.local().setZone('utc', { + keepLocalTime: true, + }), + DateTime.local().setZone('utc', { + keepLocalTime: true, + }), ] const mockResult: FluidStatus[] = [ { @@ -308,9 +326,15 @@ describe('FLuid service', () => { it('shoud return fluid status with NOT_CONNECTED status when no triggers', async () => { const mockLastDataDates: (DateTime | null)[] = [ - DateTime.local(), - DateTime.local(), - DateTime.local(), + DateTime.local().setZone('utc', { + keepLocalTime: true, + }), + DateTime.local().setZone('utc', { + keepLocalTime: true, + }), + DateTime.local().setZone('utc', { + keepLocalTime: true, + }), ] const mockResult: FluidStatus[] = [ { diff --git a/src/services/initialization.service.spec.ts b/src/services/initialization.service.spec.ts index b147233b2..a1f6c4972 100644 --- a/src/services/initialization.service.spec.ts +++ b/src/services/initialization.service.spec.ts @@ -319,7 +319,9 @@ describe('Initialization service', () => { it('should return true and updated profile when report is not up to date', () => { const mockProfile = { ...profileData, - monthlyReportDate: DateTime.fromISO('2000-10-02T00:00:00.000'), + monthlyReportDate: DateTime.fromISO('2000-10-02T00:00:00.000Z', { + zone: 'utc', + }), haveSeenLastReport: true, } const updatedProfile = { @@ -337,7 +339,9 @@ describe('Initialization service', () => { it('should throw error when report is not up to date and profile is not updated', () => { const mockProfile = { ...profileData, - monthlyReportDate: DateTime.fromISO('2000-10-02T00:00:00.000'), + monthlyReportDate: DateTime.fromISO('2000-10-02T00:00:00.000Z', { + zone: 'utc', + }), } mockUpdateProfile.mockResolvedValueOnce(null) expect(initializationService.initReport(mockProfile)).rejects.toEqual( @@ -348,7 +352,9 @@ describe('Initialization service', () => { it('should throw error when report is not up to date and update profile failed', () => { const mockProfile = { ...profileData, - monthlyReportDate: DateTime.fromISO('2000-10-02T00:00:00.000'), + monthlyReportDate: DateTime.fromISO('2000-10-02T00:00:00.000Z', { + zone: 'utc', + }), } mockUpdateProfile.mockRejectedValueOnce(new Error()) expect(initializationService.initReport(mockProfile)).rejects.toEqual( diff --git a/src/services/initialization.service.ts b/src/services/initialization.service.ts index 6e66ba50e..cb1de1cc5 100644 --- a/src/services/initialization.service.ts +++ b/src/services/initialization.service.ts @@ -203,7 +203,9 @@ export default class InitializationService { // TODO ensure that actual profile has all needed attributes } const updatedProfile = await profileService.updateProfile({ - lastConnectionDate: DateTime.local(), + lastConnectionDate: DateTime.local().setZone('utc', { + keepLocalTime: true, + }), }) return updatedProfile } catch (error) { diff --git a/src/services/profile.service.spec.ts b/src/services/profile.service.spec.ts index fb11e9fb5..ba7bde446 100644 --- a/src/services/profile.service.spec.ts +++ b/src/services/profile.service.spec.ts @@ -37,10 +37,10 @@ describe('UserProfile service', () => { mockClient.query.mockResolvedValueOnce(mockQueryResult) const resultUserProfile = { ...profileData, - haveSeenOldFluidModal: DateTime.fromISO('2020-11-09T11:27:30.073', { + haveSeenOldFluidModal: DateTime.fromISO('2020-11-09T11:27:30.073Z', { zone: 'utc', }), - monthlyReportDate: DateTime.fromISO('2020-11-09T11:27:30.073', { + monthlyReportDate: DateTime.fromISO('2020-11-09T11:27:30.073Z', { zone: 'utc', }), } @@ -90,10 +90,10 @@ describe('UserProfile service', () => { mockClient.save.mockResolvedValueOnce(mockUpdatedQueryResult) const resultUserProfile = { ...profileData, - haveSeenOldFluidModal: DateTime.fromISO('2020-11-09T11:27:30.073', { + haveSeenOldFluidModal: DateTime.fromISO('2020-11-09T11:27:30.073Z', { zone: 'utc', }), - monthlyReportDate: DateTime.fromISO('2020-11-03T00:00:00.000', { + monthlyReportDate: DateTime.fromISO('2020-11-03T00:00:00.000Z', { zone: 'utc', }), haveSeenFavoriteModal: false, diff --git a/src/services/queryRunner.service.spec.ts b/src/services/queryRunner.service.spec.ts index 3d63265b0..4eca5bbf0 100644 --- a/src/services/queryRunner.service.spec.ts +++ b/src/services/queryRunner.service.spec.ts @@ -17,31 +17,34 @@ describe('queryRunner service', () => { describe('fetchFluidData method', () => { it('should return the data of the elec fluid and year time step', async () => { const mockTimePeriod = { - startDate: DateTime.fromISO('2018-01-01T00:00:00.000', { + startDate: DateTime.fromISO('2018-01-01T00:00:00.000Z', { zone: 'utc', }), - endDate: DateTime.fromISO('2020-11-30T23:59:59.999', { + endDate: DateTime.fromISO('2020-11-30T23:59:59.999Z', { zone: 'utc', }), } const expectedResult: Dataload[] = [ { - date: DateTime.fromISO('2018-01-01T00:00:00.000', { + date: DateTime.fromISO('2018-01-01T00:00:00.000Z', { zone: 'utc', }), value: 125.25, + valueDetail: null, }, { - date: DateTime.fromISO('2019-01-01T00:00:00.000', { + date: DateTime.fromISO('2019-01-01T00:00:00.000Z', { zone: 'utc', }), value: 220.5, + valueDetail: null, }, { - date: DateTime.fromISO('2020-01-01T00:00:00.000', { + date: DateTime.fromISO('2020-01-01T00:00:00.000Z', { zone: 'utc', }), value: 130.33, + valueDetail: null, }, ] const mockQueryResult: QueryResult<DataloadEntity[]> = { @@ -61,31 +64,34 @@ describe('queryRunner service', () => { it('should return the data of the elec fluid and month time step', async () => { const mockTimePeriod = { - startDate: DateTime.fromISO('2020-01-01T00:00:00.000', { + startDate: DateTime.fromISO('2020-01-01T00:00:00.000Z', { zone: 'utc', }), - endDate: DateTime.fromISO('2020-11-30T23:59:59.999', { + endDate: DateTime.fromISO('2020-11-30T23:59:59.999Z', { zone: 'utc', }), } const expectedResult: Dataload[] = [ { - date: DateTime.fromISO('2020-09-01T00:00:00.000', { + date: DateTime.fromISO('2020-09-01T00:00:00.000Z', { zone: 'utc', }), value: 125.25, + valueDetail: null, }, { - date: DateTime.fromISO('2020-10-01T00:00:00.000', { + date: DateTime.fromISO('2020-10-01T00:00:00.000Z', { zone: 'utc', }), value: 220.5, + valueDetail: null, }, { - date: DateTime.fromISO('2020-11-01T00:00:00.000', { + date: DateTime.fromISO('2020-11-01T00:00:00.000Z', { zone: 'utc', }), value: 130.33, + valueDetail: null, }, ] const mockQueryResult: QueryResult<DataloadEntity[]> = { @@ -105,37 +111,41 @@ describe('queryRunner service', () => { it('should return the data of the elec fluid and day time step', async () => { const mockTimePeriod = { - startDate: DateTime.fromISO('2020-11-01T00:00:00.000', { + startDate: DateTime.fromISO('2020-11-01T00:00:00.000Z', { zone: 'utc', }), - endDate: DateTime.fromISO('2020-11-30T23:59:59.999', { + endDate: DateTime.fromISO('2020-11-30T23:59:59.999Z', { zone: 'utc', }), } const expectedResult: Dataload[] = [ { - date: DateTime.fromISO('2020-11-01T00:00:00.000', { + date: DateTime.fromISO('2020-11-01T00:00:00.000Z', { zone: 'utc', }), value: 25.25, + valueDetail: null, }, { - date: DateTime.fromISO('2020-11-02T00:00:00.000', { + date: DateTime.fromISO('2020-11-02T00:00:00.000Z', { zone: 'utc', }), value: 20.5, + valueDetail: null, }, { - date: DateTime.fromISO('2020-11-03T00:00:00.000', { + date: DateTime.fromISO('2020-11-03T00:00:00.000Z', { zone: 'utc', }), value: 30.33, + valueDetail: null, }, { - date: DateTime.fromISO('2020-11-04T00:00:00.000', { + date: DateTime.fromISO('2020-11-04T00:00:00.000Z', { zone: 'utc', }), value: 1.22, + valueDetail: null, }, ] const mockQueryResult: QueryResult<DataloadEntity[]> = { @@ -155,43 +165,48 @@ describe('queryRunner service', () => { it('should return the data of the elec fluid and half an hour time step', async () => { const mockTimePeriod = { - startDate: DateTime.fromISO('2020-11-02T00:00:00.000', { + startDate: DateTime.fromISO('2020-11-02T00:00:00.000Z', { zone: 'utc', }), - endDate: DateTime.fromISO('2020-11-02T23:59:59.999', { + endDate: DateTime.fromISO('2020-11-02T23:59:59.999Z', { zone: 'utc', }), } const expectedResult: Dataload[] = [ { - date: DateTime.fromISO('2020-11-02T00:00:00.000', { + date: DateTime.fromISO('2020-11-02T00:00:00.000Z', { zone: 'utc', }), value: 4.5, + valueDetail: null, }, { - date: DateTime.fromISO('2020-11-02T00:30:00.000', { + date: DateTime.fromISO('2020-11-02T00:30:00.000Z', { zone: 'utc', }), value: 1.33, + valueDetail: null, }, { - date: DateTime.fromISO('2020-11-02T01:00:00.000', { + date: DateTime.fromISO('2020-11-02T01:00:00.000Z', { zone: 'utc', }), value: 3.22, + valueDetail: null, }, { - date: DateTime.fromISO('2020-11-02T01:30:00.000', { + date: DateTime.fromISO('2020-11-02T01:30:00.000Z', { zone: 'utc', }), value: 7.82, + valueDetail: null, }, { - date: DateTime.fromISO('2020-11-02T02:00:00.000', { + date: DateTime.fromISO('2020-11-02T02:00:00.000Z', { zone: 'utc', }), value: 1.23, + valueDetail: null, }, ] const filteredData = [...loadMinuteData] @@ -215,31 +230,34 @@ describe('queryRunner service', () => { it('should return the data of the water fluid and year time step', async () => { const mockTimePeriod = { - startDate: DateTime.fromISO('2018-01-01T00:00:00.000', { + startDate: DateTime.fromISO('2018-01-01T00:00:00.000Z', { zone: 'utc', }), - endDate: DateTime.fromISO('2020-11-30T23:59:59.999', { + endDate: DateTime.fromISO('2020-11-30T23:59:59.999Z', { zone: 'utc', }), } const expectedResult: Dataload[] = [ { - date: DateTime.fromISO('2018-01-01T00:00:00.000', { + date: DateTime.fromISO('2018-01-01T00:00:00.000Z', { zone: 'utc', }), value: 125.25, + valueDetail: null, }, { - date: DateTime.fromISO('2019-01-01T00:00:00.000', { + date: DateTime.fromISO('2019-01-01T00:00:00.000Z', { zone: 'utc', }), value: 220.5, + valueDetail: null, }, { - date: DateTime.fromISO('2020-01-01T00:00:00.000', { + date: DateTime.fromISO('2020-01-01T00:00:00.000Z', { zone: 'utc', }), value: 130.33, + valueDetail: null, }, ] const mockQueryResult: QueryResult<DataloadEntity[]> = { @@ -259,31 +277,34 @@ describe('queryRunner service', () => { it('should return the data of the water fluid and month time step', async () => { const mockTimePeriod = { - startDate: DateTime.fromISO('2020-01-01T00:00:00.000', { + startDate: DateTime.fromISO('2020-01-01T00:00:00.000Z', { zone: 'utc', }), - endDate: DateTime.fromISO('2020-11-30T23:59:59.999', { + endDate: DateTime.fromISO('2020-11-30T23:59:59.999Z', { zone: 'utc', }), } const expectedResult: Dataload[] = [ { - date: DateTime.fromISO('2020-09-01T00:00:00.000', { + date: DateTime.fromISO('2020-09-01T00:00:00.000Z', { zone: 'utc', }), value: 125.25, + valueDetail: null, }, { - date: DateTime.fromISO('2020-10-01T00:00:00.000', { + date: DateTime.fromISO('2020-10-01T00:00:00.000Z', { zone: 'utc', }), value: 220.5, + valueDetail: null, }, { - date: DateTime.fromISO('2020-11-01T00:00:00.000', { + date: DateTime.fromISO('2020-11-01T00:00:00.000Z', { zone: 'utc', }), value: 130.33, + valueDetail: null, }, ] const mockQueryResult: QueryResult<DataloadEntity[]> = { @@ -303,37 +324,41 @@ describe('queryRunner service', () => { it('should return the data of the water fluid and day time step', async () => { const mockTimePeriod = { - startDate: DateTime.fromISO('2020-11-01T00:00:00.000', { + startDate: DateTime.fromISO('2020-11-01T00:00:00.000Z', { zone: 'utc', }), - endDate: DateTime.fromISO('2020-11-30T23:59:59.999', { + endDate: DateTime.fromISO('2020-11-30T23:59:59.999Z', { zone: 'utc', }), } const expectedResult: Dataload[] = [ { - date: DateTime.fromISO('2020-11-01T00:00:00.000', { + date: DateTime.fromISO('2020-11-01T00:00:00.000Z', { zone: 'utc', }), value: 25.25, + valueDetail: null, }, { - date: DateTime.fromISO('2020-11-02T00:00:00.000', { + date: DateTime.fromISO('2020-11-02T00:00:00.000Z', { zone: 'utc', }), value: 20.5, + valueDetail: null, }, { - date: DateTime.fromISO('2020-11-03T00:00:00.000', { + date: DateTime.fromISO('2020-11-03T00:00:00.000Z', { zone: 'utc', }), value: 30.33, + valueDetail: null, }, { - date: DateTime.fromISO('2020-11-04T00:00:00.000', { + date: DateTime.fromISO('2020-11-04T00:00:00.000Z', { zone: 'utc', }), value: 1.22, + valueDetail: null, }, ] const mockQueryResult: QueryResult<DataloadEntity[]> = { @@ -353,37 +378,41 @@ describe('queryRunner service', () => { it('should return the day data of the water fluid and unkown time step', async () => { const mockTimePeriod = { - startDate: DateTime.fromISO('2020-11-01T00:00:00.000', { + startDate: DateTime.fromISO('2020-11-01T00:00:00.000Z', { zone: 'utc', }), - endDate: DateTime.fromISO('2020-11-30T23:59:59.999', { + endDate: DateTime.fromISO('2020-11-30T23:59:59.999Z', { zone: 'utc', }), } const expectedResult: Dataload[] = [ { - date: DateTime.fromISO('2020-11-01T00:00:00.000', { + date: DateTime.fromISO('2020-11-01T00:00:00.000Z', { zone: 'utc', }), value: 25.25, + valueDetail: null, }, { - date: DateTime.fromISO('2020-11-02T00:00:00.000', { + date: DateTime.fromISO('2020-11-02T00:00:00.000Z', { zone: 'utc', }), value: 20.5, + valueDetail: null, }, { - date: DateTime.fromISO('2020-11-03T00:00:00.000', { + date: DateTime.fromISO('2020-11-03T00:00:00.000Z', { zone: 'utc', }), value: 30.33, + valueDetail: null, }, { - date: DateTime.fromISO('2020-11-04T00:00:00.000', { + date: DateTime.fromISO('2020-11-04T00:00:00.000Z', { zone: 'utc', }), value: 1.22, + valueDetail: null, }, ] const mockQueryResult: QueryResult<DataloadEntity[]> = { @@ -403,31 +432,34 @@ describe('queryRunner service', () => { it('should return the data of the gas fluid and year time step', async () => { const mockTimePeriod = { - startDate: DateTime.fromISO('2018-01-01T00:00:00.000', { + startDate: DateTime.fromISO('2018-01-01T00:00:00.000Z', { zone: 'utc', }), - endDate: DateTime.fromISO('2020-11-30T23:59:59.999', { + endDate: DateTime.fromISO('2020-11-30T23:59:59.999Z', { zone: 'utc', }), } const expectedResult: Dataload[] = [ { - date: DateTime.fromISO('2018-01-01T00:00:00.000', { + date: DateTime.fromISO('2018-01-01T00:00:00.000Z', { zone: 'utc', }), value: 125.25, + valueDetail: null, }, { - date: DateTime.fromISO('2019-01-01T00:00:00.000', { + date: DateTime.fromISO('2019-01-01T00:00:00.000Z', { zone: 'utc', }), value: 220.5, + valueDetail: null, }, { - date: DateTime.fromISO('2020-01-01T00:00:00.000', { + date: DateTime.fromISO('2020-01-01T00:00:00.000Z', { zone: 'utc', }), value: 130.33, + valueDetail: null, }, ] const mockQueryResult: QueryResult<DataloadEntity[]> = { @@ -447,31 +479,34 @@ describe('queryRunner service', () => { it('should return the data of the gas fluid and month time step', async () => { const mockTimePeriod = { - startDate: DateTime.fromISO('2020-01-01T00:00:00.000', { + startDate: DateTime.fromISO('2020-01-01T00:00:00.000Z', { zone: 'utc', }), - endDate: DateTime.fromISO('2020-11-30T23:59:59.999', { + endDate: DateTime.fromISO('2020-11-30T23:59:59.999Z', { zone: 'utc', }), } const expectedResult: Dataload[] = [ { - date: DateTime.fromISO('2020-09-01T00:00:00.000', { + date: DateTime.fromISO('2020-09-01T00:00:00.000Z', { zone: 'utc', }), value: 125.25, + valueDetail: null, }, { - date: DateTime.fromISO('2020-10-01T00:00:00.000', { + date: DateTime.fromISO('2020-10-01T00:00:00.000Z', { zone: 'utc', }), value: 220.5, + valueDetail: null, }, { - date: DateTime.fromISO('2020-11-01T00:00:00.000', { + date: DateTime.fromISO('2020-11-01T00:00:00.000Z', { zone: 'utc', }), value: 130.33, + valueDetail: null, }, ] const mockQueryResult: QueryResult<DataloadEntity[]> = { @@ -491,37 +526,41 @@ describe('queryRunner service', () => { it('should return the data of the gas fluid and day time step', async () => { const mockTimePeriod = { - startDate: DateTime.fromISO('2020-11-01T00:00:00.000', { + startDate: DateTime.fromISO('2020-11-01T00:00:00.000Z', { zone: 'utc', }), - endDate: DateTime.fromISO('2020-11-30T23:59:59.999', { + endDate: DateTime.fromISO('2020-11-30T23:59:59.999Z', { zone: 'utc', }), } const expectedResult: Dataload[] = [ { - date: DateTime.fromISO('2020-11-01T00:00:00.000', { + date: DateTime.fromISO('2020-11-01T00:00:00.000Z', { zone: 'utc', }), value: 25.25, + valueDetail: null, }, { - date: DateTime.fromISO('2020-11-02T00:00:00.000', { + date: DateTime.fromISO('2020-11-02T00:00:00.000Z', { zone: 'utc', }), value: 20.5, + valueDetail: null, }, { - date: DateTime.fromISO('2020-11-03T00:00:00.000', { + date: DateTime.fromISO('2020-11-03T00:00:00.000Z', { zone: 'utc', }), value: 30.33, + valueDetail: null, }, { - date: DateTime.fromISO('2020-11-04T00:00:00.000', { + date: DateTime.fromISO('2020-11-04T00:00:00.000Z', { zone: 'utc', }), value: 1.22, + valueDetail: null, }, ] const mockQueryResult: QueryResult<DataloadEntity[]> = { @@ -541,43 +580,48 @@ describe('queryRunner service', () => { it('should return the data of the gas fluid and hour time step', async () => { const mockTimePeriod = { - startDate: DateTime.fromISO('2020-11-02T00:00:00.000', { + startDate: DateTime.fromISO('2020-11-02T00:00:00.000Z', { zone: 'utc', }), - endDate: DateTime.fromISO('2020-11-02T23:59:59.999', { + endDate: DateTime.fromISO('2020-11-02T23:59:59.999Z', { zone: 'utc', }), } const expectedResult: Dataload[] = [ { - date: DateTime.fromISO('2020-11-02T00:00:00.000', { + date: DateTime.fromISO('2020-11-02T00:00:00.000Z', { zone: 'utc', }), value: 4.5, + valueDetail: null, }, { - date: DateTime.fromISO('2020-11-02T01:00:00.000', { + date: DateTime.fromISO('2020-11-02T01:00:00.000Z', { zone: 'utc', }), value: 1.33, + valueDetail: null, }, { - date: DateTime.fromISO('2020-11-02T02:00:00.000', { + date: DateTime.fromISO('2020-11-02T02:00:00.000Z', { zone: 'utc', }), value: 3.22, + valueDetail: null, }, { - date: DateTime.fromISO('2020-11-02T03:00:00.000', { + date: DateTime.fromISO('2020-11-02T03:00:00.000Z', { zone: 'utc', }), value: 7.82, + valueDetail: null, }, { - date: DateTime.fromISO('2020-11-02T04:00:00.000', { + date: DateTime.fromISO('2020-11-02T04:00:00.000Z', { zone: 'utc', }), value: 1.23, + valueDetail: null, }, ] const mockQueryResult: QueryResult<DataloadEntity[]> = { @@ -597,37 +641,41 @@ describe('queryRunner service', () => { it('should return the day data of the gas fluid and unkonwn time step', async () => { const mockTimePeriod = { - startDate: DateTime.fromISO('2020-11-01T00:00:00.000', { + startDate: DateTime.fromISO('2020-11-01T00:00:00.000Z', { zone: 'utc', }), - endDate: DateTime.fromISO('2020-11-30T23:59:59.999', { + endDate: DateTime.fromISO('2020-11-30T23:59:59.999Z', { zone: 'utc', }), } const expectedResult: Dataload[] = [ { - date: DateTime.fromISO('2020-11-01T00:00:00.000', { + date: DateTime.fromISO('2020-11-01T00:00:00.000Z', { zone: 'utc', }), value: 25.25, + valueDetail: null, }, { - date: DateTime.fromISO('2020-11-02T00:00:00.000', { + date: DateTime.fromISO('2020-11-02T00:00:00.000Z', { zone: 'utc', }), value: 20.5, + valueDetail: null, }, { - date: DateTime.fromISO('2020-11-03T00:00:00.000', { + date: DateTime.fromISO('2020-11-03T00:00:00.000Z', { zone: 'utc', }), value: 30.33, + valueDetail: null, }, { - date: DateTime.fromISO('2020-11-04T00:00:00.000', { + date: DateTime.fromISO('2020-11-04T00:00:00.000Z', { zone: 'utc', }), value: 1.22, + valueDetail: null, }, ] const mockQueryResult: QueryResult<DataloadEntity[]> = { @@ -647,25 +695,27 @@ describe('queryRunner service', () => { it('should return the data of the elec fluid and month time step with start year <> end year', async () => { const mockTimePeriod = { - startDate: DateTime.fromISO('2019-12-01T00:00:00.000', { + startDate: DateTime.fromISO('2019-12-01T00:00:00.000Z', { zone: 'utc', }), - endDate: DateTime.fromISO('2020-10-30T23:59:59.999', { + endDate: DateTime.fromISO('2020-10-30T23:59:59.999Z', { zone: 'utc', }), } const expectedResult: Dataload[] = [ { - date: DateTime.fromISO('2020-09-01T00:00:00.000', { + date: DateTime.fromISO('2020-09-01T00:00:00.000Z', { zone: 'utc', }), value: 125.25, + valueDetail: null, }, { - date: DateTime.fromISO('2020-10-01T00:00:00.000', { + date: DateTime.fromISO('2020-10-01T00:00:00.000Z', { zone: 'utc', }), value: 220.5, + valueDetail: null, }, ] const mockQueryResult: QueryResult<DataloadEntity[]> = { @@ -685,31 +735,34 @@ describe('queryRunner service', () => { it('should return the data of the elec fluid and month time step with period >=12 months', async () => { const mockTimePeriod = { - startDate: DateTime.fromISO('2019-12-01T00:00:00.000', { + startDate: DateTime.fromISO('2019-12-01T00:00:00.000Z', { zone: 'utc', }), - endDate: DateTime.fromISO('2020-11-30T23:59:59.999', { + endDate: DateTime.fromISO('2020-11-30T23:59:59.999Z', { zone: 'utc', }), } const expectedResult: Dataload[] = [ { - date: DateTime.fromISO('2020-09-01T00:00:00.000', { + date: DateTime.fromISO('2020-09-01T00:00:00.000Z', { zone: 'utc', }), value: 125.25, + valueDetail: null, }, { - date: DateTime.fromISO('2020-10-01T00:00:00.000', { + date: DateTime.fromISO('2020-10-01T00:00:00.000Z', { zone: 'utc', }), value: 220.5, + valueDetail: null, }, { - date: DateTime.fromISO('2020-11-01T00:00:00.000', { + date: DateTime.fromISO('2020-11-01T00:00:00.000Z', { zone: 'utc', }), value: 130.33, + valueDetail: null, }, ] const mockQueryResult: QueryResult<DataloadEntity[]> = { @@ -729,37 +782,41 @@ describe('queryRunner service', () => { it('should return the data of the elec fluid and day time step with start month <> end month', async () => { const mockTimePeriod = { - startDate: DateTime.fromISO('2020-10-15T00:00:00.000', { + startDate: DateTime.fromISO('2020-10-15T00:00:00.000Z', { zone: 'utc', }), - endDate: DateTime.fromISO('2020-11-05T23:59:59.999', { + endDate: DateTime.fromISO('2020-11-05T23:59:59.999Z', { zone: 'utc', }), } const expectedResult: Dataload[] = [ { - date: DateTime.fromISO('2020-11-01T00:00:00.000', { + date: DateTime.fromISO('2020-11-01T00:00:00.000Z', { zone: 'utc', }), value: 25.25, + valueDetail: null, }, { - date: DateTime.fromISO('2020-11-02T00:00:00.000', { + date: DateTime.fromISO('2020-11-02T00:00:00.000Z', { zone: 'utc', }), value: 20.5, + valueDetail: null, }, { - date: DateTime.fromISO('2020-11-03T00:00:00.000', { + date: DateTime.fromISO('2020-11-03T00:00:00.000Z', { zone: 'utc', }), value: 30.33, + valueDetail: null, }, { - date: DateTime.fromISO('2020-11-04T00:00:00.000', { + date: DateTime.fromISO('2020-11-04T00:00:00.000Z', { zone: 'utc', }), value: 1.22, + valueDetail: null, }, ] const mockQueryResult: QueryResult<DataloadEntity[]> = { @@ -779,37 +836,41 @@ describe('queryRunner service', () => { it('should return the data of the elec fluid and day time step with time period > 31 days', async () => { const mockTimePeriod = { - startDate: DateTime.fromISO('2020-10-01T00:00:00.000', { + startDate: DateTime.fromISO('2020-10-01T00:00:00.000Z', { zone: 'utc', }), - endDate: DateTime.fromISO('2020-11-30T23:59:59.999', { + endDate: DateTime.fromISO('2020-11-30T23:59:59.999Z', { zone: 'utc', }), } const expectedResult: Dataload[] = [ { - date: DateTime.fromISO('2020-11-01T00:00:00.000', { + date: DateTime.fromISO('2020-11-01T00:00:00.000Z', { zone: 'utc', }), value: 25.25, + valueDetail: null, }, { - date: DateTime.fromISO('2020-11-02T00:00:00.000', { + date: DateTime.fromISO('2020-11-02T00:00:00.000Z', { zone: 'utc', }), value: 20.5, + valueDetail: null, }, { - date: DateTime.fromISO('2020-11-03T00:00:00.000', { + date: DateTime.fromISO('2020-11-03T00:00:00.000Z', { zone: 'utc', }), value: 30.33, + valueDetail: null, }, { - date: DateTime.fromISO('2020-11-04T00:00:00.000', { + date: DateTime.fromISO('2020-11-04T00:00:00.000Z', { zone: 'utc', }), value: 1.22, + valueDetail: null, }, ] const mockQueryResult: QueryResult<DataloadEntity[]> = { @@ -829,10 +890,10 @@ describe('queryRunner service', () => { it('should return null when fetch data failed', async () => { const mockTimePeriod = { - startDate: DateTime.fromISO('2020-11-01T00:00:00.000', { + startDate: DateTime.fromISO('2020-11-01T00:00:00.000Z', { zone: 'utc', }), - endDate: DateTime.fromISO('2020-11-30T23:59:59.999', { + endDate: DateTime.fromISO('2020-11-30T23:59:59.999Z', { zone: 'utc', }), } @@ -847,10 +908,10 @@ describe('queryRunner service', () => { it('should return null when unknown fluid type', async () => { const mockTimePeriod = { - startDate: DateTime.fromISO('2020-11-01T00:00:00.000', { + startDate: DateTime.fromISO('2020-11-01T00:00:00.000Z', { zone: 'utc', }), - endDate: DateTime.fromISO('2020-11-30T23:59:59.999', { + endDate: DateTime.fromISO('2020-11-30T23:59:59.999Z', { zone: 'utc', }), } @@ -864,10 +925,10 @@ describe('queryRunner service', () => { it('should return null when unknown time step', async () => { const mockTimePeriod = { - startDate: DateTime.fromISO('2020-11-01T00:00:00.000', { + startDate: DateTime.fromISO('2020-11-01T00:00:00.000Z', { zone: 'utc', }), - endDate: DateTime.fromISO('2020-11-30T23:59:59.999', { + endDate: DateTime.fromISO('2020-11-30T23:59:59.999Z', { zone: 'utc', }), } @@ -883,10 +944,10 @@ describe('queryRunner service', () => { describe('fetchFluidMaxData method', () => { it('should return the max load for elec fluid with day timestep', async () => { const mockTimePeriod = { - startDate: DateTime.fromISO('2020-11-01T00:00:00.000', { + startDate: DateTime.fromISO('2020-11-01T00:00:00.000Z', { zone: 'utc', }), - endDate: DateTime.fromISO('2020-11-30T23:59:59.999', { + endDate: DateTime.fromISO('2020-11-30T23:59:59.999Z', { zone: 'utc', }), } @@ -907,10 +968,10 @@ describe('queryRunner service', () => { it('should return the max load for elec fluid with half an hour timestep', async () => { const mockTimePeriod = { - startDate: DateTime.fromISO('2020-11-02T00:00:00.000', { + startDate: DateTime.fromISO('2020-11-02T00:00:00.000Z', { zone: 'utc', }), - endDate: DateTime.fromISO('2020-11-2T23:59:59.999', { + endDate: DateTime.fromISO('2020-11-2T23:59:59.999Z', { zone: 'utc', }), } @@ -939,10 +1000,10 @@ describe('queryRunner service', () => { it('should return 0 for elec fluid with half an hour timestep and no data found', async () => { const mockTimePeriod = { - startDate: DateTime.fromISO('2020-11-02T00:00:00.000', { + startDate: DateTime.fromISO('2020-11-02T00:00:00.000Z', { zone: 'utc', }), - endDate: DateTime.fromISO('2020-11-2T23:59:59.999', { + endDate: DateTime.fromISO('2020-11-2T23:59:59.999Z', { zone: 'utc', }), } @@ -971,10 +1032,10 @@ describe('queryRunner service', () => { it('should return null when fetch data failed', async () => { const mockTimePeriod = { - startDate: DateTime.fromISO('2020-11-01T00:00:00.000', { + startDate: DateTime.fromISO('2020-11-01T00:00:00.000Z', { zone: 'utc', }), - endDate: DateTime.fromISO('2020-11-30T23:59:59.999', { + endDate: DateTime.fromISO('2020-11-30T23:59:59.999Z', { zone: 'utc', }), } @@ -989,10 +1050,10 @@ describe('queryRunner service', () => { it('should return null when unknown fluid type', async () => { const mockTimePeriod = { - startDate: DateTime.fromISO('2020-11-01T00:00:00.000', { + startDate: DateTime.fromISO('2020-11-01T00:00:00.000Z', { zone: 'utc', }), - endDate: DateTime.fromISO('2020-11-30T23:59:59.999', { + endDate: DateTime.fromISO('2020-11-30T23:59:59.999Z', { zone: 'utc', }), } @@ -1006,10 +1067,10 @@ describe('queryRunner service', () => { it('should return null when unknown time step', async () => { const mockTimePeriod = { - startDate: DateTime.fromISO('2020-11-01T00:00:00.000', { + startDate: DateTime.fromISO('2020-11-01T00:00:00.000Z', { zone: 'utc', }), - endDate: DateTime.fromISO('2020-11-30T23:59:59.999', { + endDate: DateTime.fromISO('2020-11-30T23:59:59.999Z', { zone: 'utc', }), } diff --git a/src/services/queryRunner.service.ts b/src/services/queryRunner.service.ts index 2d67dce85..a09952411 100644 --- a/src/services/queryRunner.service.ts +++ b/src/services/queryRunner.service.ts @@ -143,6 +143,7 @@ export default class QueryRunner { keepLocalTime: true, }), value: entry.load, + valueDetail: null, })) return mappedResult diff --git a/src/services/quiz.service.ts b/src/services/quiz.service.ts index 995f29556..6d7d9685c 100644 --- a/src/services/quiz.service.ts +++ b/src/services/quiz.service.ts @@ -371,7 +371,9 @@ export default class QuizService { interval: TimePeriod, fluidType: FluidType[] ): Promise<IntervalAnswer> { - let dateMax: DateTime = DateTime.local() + let dateMax: DateTime = DateTime.local().setZone('utc', { + keepLocalTime: true, + }) let max = 0 const consumptionService = new ConsumptionDataManager(this._client) const graphData = await consumptionService.getGraphData( diff --git a/src/services/timePeriod.service.spec.ts b/src/services/timePeriod.service.spec.ts index b65790d20..c5568b6c3 100644 --- a/src/services/timePeriod.service.spec.ts +++ b/src/services/timePeriod.service.spec.ts @@ -4,28 +4,30 @@ import { DateTime } from 'luxon' import { TimePeriod } from 'models' import { FluidType } from 'enum/fluid.enum' -const randomDate = DateTime.fromISO('2020-10-10T08:00:00.000') +const randomDate = DateTime.fromISO('2020-10-10T08:00:00.000Z', { + zone: 'utc', +}) const unknowTimeStep = 999 describe('timePeriod service', () => { const timePeriodService = new TimePeriodService() describe('getTimePeriods method', () => { - const lastDatePeriod = DateTime.fromISO('2020-10-31T08:00:00.000', { + const lastDatePeriod = DateTime.fromISO('2020-10-31T08:00:00.000Z', { zone: 'utc', }) const fluidTypes: FluidType[] = [0, 1, 2] const comparisonTimePeriod: TimePeriod = { - startDate: DateTime.fromISO('2020-08-01T00:00:00.000', { + startDate: DateTime.fromISO('2020-08-01T00:00:00.000Z', { zone: 'utc', }), - endDate: DateTime.fromISO('2020-08-31T00:00:00.000', { + endDate: DateTime.fromISO('2020-08-31T00:00:00.000Z', { zone: 'utc', }), } const timePeriod: TimePeriod = { - startDate: DateTime.fromISO('2020-09-01T00:00:00.000', { + startDate: DateTime.fromISO('2020-09-01T00:00:00.000Z', { zone: 'utc', }), - endDate: DateTime.fromISO('2020-09-30T23:59:59.999', { + endDate: DateTime.fromISO('2020-09-30T23:59:59.999Z', { zone: 'utc', }), } @@ -43,22 +45,22 @@ describe('timePeriod service', () => { }) it('should return the current timePeriod and the comparison timePeriod for MONTH', () => { comparisonTimePeriod.endDate = DateTime.fromISO( - '2020-08-31T23:59:59.999', + '2020-08-31T23:59:59.999Z', { zone: 'utc', } ) comparisonTimePeriod.startDate = DateTime.fromISO( - '2020-08-01T00:00:00.000', + '2020-08-01T00:00:00.000Z', { zone: 'utc', } ) - timePeriod.startDate = DateTime.fromISO('2020-09-01T00:00:00.000', { + timePeriod.startDate = DateTime.fromISO('2020-09-01T00:00:00.000Z', { zone: 'utc', }) - timePeriod.endDate = DateTime.fromISO('2020-09-30T23:59:59.999', { + timePeriod.endDate = DateTime.fromISO('2020-09-30T23:59:59.999Z', { zone: 'utc', }) result = timePeriodService.getTimePeriods( @@ -73,22 +75,22 @@ describe('timePeriod service', () => { }) it('should return the current timePeriod and the comparison timePeriod for YEAR', () => { comparisonTimePeriod.endDate = DateTime.fromISO( - '2018-12-31T23:59:59.999', + '2018-12-31T23:59:59.999Z', { zone: 'utc', } ) comparisonTimePeriod.startDate = DateTime.fromISO( - '2018-01-01T00:00:00.000', + '2018-01-01T00:00:00.000Z', { zone: 'utc', } ) - timePeriod.startDate = DateTime.fromISO('2019-01-01T00:00:00.000', { + timePeriod.startDate = DateTime.fromISO('2019-01-01T00:00:00.000Z', { zone: 'utc', }) - timePeriod.endDate = DateTime.fromISO('2019-12-31T23:59:59.999', { + timePeriod.endDate = DateTime.fromISO('2019-12-31T23:59:59.999Z', { zone: 'utc', }) result = timePeriodService.getTimePeriods( @@ -122,13 +124,13 @@ describe('timePeriod service', () => { }) describe('applyOffsetToDate method', () => { it('should return new date with offset day apply', () => { - let expectedDate = DateTime.fromISO('2020-10-07T08:00:00.000', { + let expectedDate = DateTime.fromISO('2020-10-07T08:00:00.000Z', { zone: 'utc', }) let result = timePeriodService.applyOffsetToDate(randomDate, 3) expect(result).toEqual(expectedDate) - expectedDate = DateTime.fromISO('2020-09-25T08:00:00.000', { + expectedDate = DateTime.fromISO('2020-09-25T08:00:00.000Z', { zone: 'utc', }) result = timePeriodService.applyOffsetToDate(randomDate, 15) @@ -138,18 +140,18 @@ describe('timePeriod service', () => { describe('getComparisonTimePeriod method', () => { const timePeriod: TimePeriod = { - startDate: DateTime.fromISO('2020-10-07T08:00:00.000', { + startDate: DateTime.fromISO('2020-10-07T08:00:00.000Z', { zone: 'utc', }), - endDate: DateTime.fromISO('2020-10-14T08:00:00.000', { + endDate: DateTime.fromISO('2020-10-14T08:00:00.000Z', { zone: 'utc', }), } let expectedComparisonDateTime: TimePeriod = { - startDate: DateTime.fromISO('2020-10-06T08:00:00.000', { + startDate: DateTime.fromISO('2020-10-06T08:00:00.000Z', { zone: 'utc', }), - endDate: DateTime.fromISO('2020-10-13T08:00:00.000', { + endDate: DateTime.fromISO('2020-10-13T08:00:00.000Z', { zone: 'utc', }), } @@ -163,10 +165,10 @@ describe('timePeriod service', () => { }) it('should return the comparison TimePeriod for DAY', () => { expectedComparisonDateTime = { - startDate: DateTime.fromISO('2020-10-01T00:00:00.000', { + startDate: DateTime.fromISO('2020-10-01T00:00:00.000Z', { zone: 'utc', }), - endDate: DateTime.fromISO('2020-10-06T08:00:00.000', { + endDate: DateTime.fromISO('2020-10-06T08:00:00.000Z', { zone: 'utc', }), } @@ -178,10 +180,10 @@ describe('timePeriod service', () => { }) it('should return the comparison TimePeriod for MONTH', () => { expectedComparisonDateTime = { - startDate: DateTime.fromISO('2020-09-07T00:00:00.000', { + startDate: DateTime.fromISO('2020-09-07T00:00:00.000Z', { zone: 'utc', }), - endDate: DateTime.fromISO('2020-09-30T23:59:59.999', { + endDate: DateTime.fromISO('2020-09-30T23:59:59.999Z', { zone: 'utc', }), } @@ -193,10 +195,10 @@ describe('timePeriod service', () => { }) it('should return the comparison TimePeriod for YEAR', () => { expectedComparisonDateTime = { - startDate: DateTime.fromISO('2019-10-07T00:00:00.000', { + startDate: DateTime.fromISO('2019-10-07T00:00:00.000Z', { zone: 'utc', }), - endDate: DateTime.fromISO('2019-12-31T23:59:59.999', { + endDate: DateTime.fromISO('2019-12-31T23:59:59.999Z', { zone: 'utc', }), } @@ -220,7 +222,7 @@ describe('timePeriod service', () => { describe('getLastDayOfCompletePeriod method', () => { let result = null - let expectedDate = DateTime.fromISO('2020-10-10T00:00:00.000', { + let expectedDate = DateTime.fromISO('2020-10-10T00:00:00.000Z', { zone: 'utc', }) it('should return the date of the last day of a completed period for HOUR', () => { @@ -231,7 +233,7 @@ describe('timePeriod service', () => { expect(result).toEqual(expectedDate) }) it('should return the date of the last day of a completed period for DAY', () => { - expectedDate = DateTime.fromISO('2020-09-30T00:00:00.000', { + expectedDate = DateTime.fromISO('2020-09-30T00:00:00.000Z', { zone: 'utc', }) result = timePeriodService.getLastDayOfCompletePeriod( @@ -241,7 +243,7 @@ describe('timePeriod service', () => { expect(result).toEqual(expectedDate) }) it('should return the date of the last day of a completed period for MONTH', () => { - expectedDate = DateTime.fromISO('2020-09-30T00:00:00.000', { + expectedDate = DateTime.fromISO('2020-09-30T00:00:00.000Z', { zone: 'utc', }) result = timePeriodService.getLastDayOfCompletePeriod( @@ -251,7 +253,7 @@ describe('timePeriod service', () => { expect(result).toEqual(expectedDate) }) it('should return the date of the last day of a completed period for YEAR', () => { - expectedDate = DateTime.fromISO('2019-12-31T00:00:00.000', { + expectedDate = DateTime.fromISO('2019-12-31T00:00:00.000Z', { zone: 'utc', }) result = timePeriodService.getLastDayOfCompletePeriod( @@ -274,7 +276,7 @@ describe('timePeriod service', () => { describe('getLastDayOfTimePeriod method', () => { let result = null - let expectedDate = DateTime.fromISO('2020-10-10T00:00:00.000', { + let expectedDate = DateTime.fromISO('2020-10-10T00:00:00.000Z', { zone: 'utc', }) it('should return the date of the last day of current period', () => { @@ -285,7 +287,7 @@ describe('timePeriod service', () => { expect(result).toEqual(expectedDate) }) it('should return the date of the last day of current period', () => { - expectedDate = DateTime.fromISO('2020-10-31T23:59:59.999', { + expectedDate = DateTime.fromISO('2020-10-31T23:59:59.999Z', { zone: 'utc', }) result = timePeriodService.getLastDayOfTimePeriod( @@ -295,7 +297,7 @@ describe('timePeriod service', () => { expect(result).toEqual(expectedDate) }) it('should return the date of the last day of current period', () => { - expectedDate = DateTime.fromISO('2020-10-31T00:00:00.000', { + expectedDate = DateTime.fromISO('2020-10-31T00:00:00.000Z', { zone: 'utc', }) result = timePeriodService.getLastDayOfTimePeriod( @@ -305,7 +307,7 @@ describe('timePeriod service', () => { expect(result).toEqual(expectedDate) }) it('should return the date of the last day of current period', () => { - expectedDate = DateTime.fromISO('2020-12-31T00:00:00.000', { + expectedDate = DateTime.fromISO('2020-12-31T00:00:00.000Z', { zone: 'utc', }) result = timePeriodService.getLastDayOfTimePeriod( @@ -328,7 +330,7 @@ describe('timePeriod service', () => { describe('getStartDateFromEndDateByTimeStep method', () => { let result = null - let expectedDate = DateTime.fromISO('2020-10-10T00:00:00.000', { + let expectedDate = DateTime.fromISO('2020-10-10T00:00:00.000Z', { zone: 'utc', }) it('should return the date of the first day of a period', () => { @@ -339,7 +341,7 @@ describe('timePeriod service', () => { expect(result).toEqual(expectedDate) }) it('should return the date of the last day of current period', () => { - expectedDate = DateTime.fromISO('2020-10-01T00:00:00.000', { + expectedDate = DateTime.fromISO('2020-10-01T00:00:00.000Z', { zone: 'utc', }) result = timePeriodService.getStartDateFromEndDateByTimeStep( @@ -349,7 +351,7 @@ describe('timePeriod service', () => { expect(result).toEqual(expectedDate) }) it('should return the date of the last day of current period', () => { - expectedDate = DateTime.fromISO('2020-10-01T00:00:00.000', { + expectedDate = DateTime.fromISO('2020-10-01T00:00:00.000Z', { zone: 'utc', }) result = timePeriodService.getStartDateFromEndDateByTimeStep( @@ -359,7 +361,7 @@ describe('timePeriod service', () => { expect(result).toEqual(expectedDate) }) it('should return the date of the last day of current period', () => { - expectedDate = DateTime.fromISO('2020-01-01T00:00:00.000', { + expectedDate = DateTime.fromISO('2020-01-01T00:00:00.000Z', { zone: 'utc', }) result = timePeriodService.getStartDateFromEndDateByTimeStep( diff --git a/src/store/challenge/challenge.reducer.spec.ts b/src/store/challenge/challenge.reducer.spec.ts index f8ca26c2b..11fcd1baf 100644 --- a/src/store/challenge/challenge.reducer.spec.ts +++ b/src/store/challenge/challenge.reducer.spec.ts @@ -115,7 +115,9 @@ describe('challenge reducer', () => { } const dataload: Dataload[] = [ { - date: DateTime.fromISO('2020-10-01T00:00:00.000'), + date: DateTime.fromISO('2020-10-01T00:00:00.000Z', { + zone: 'utc', + }), value: 20, valueDetail: [5.0, 10.0, 5.0], }, diff --git a/src/store/global/global.reducer.spec.ts b/src/store/global/global.reducer.spec.ts index 65b26f575..8b2e04f57 100644 --- a/src/store/global/global.reducer.spec.ts +++ b/src/store/global/global.reducer.spec.ts @@ -14,9 +14,15 @@ import { accountsData } from '../../../test/__mocks__/accountsData.mock' import { triggersData } from '../../../test/__mocks__/triggersData.mock' const mockLastDataDates: (DateTime | null)[] = [ - DateTime.local(), - DateTime.local(), - DateTime.local(), + DateTime.local().setZone('utc', { + keepLocalTime: true, + }), + DateTime.local().setZone('utc', { + keepLocalTime: true, + }), + DateTime.local().setZone('utc', { + keepLocalTime: true, + }), ] const mockFluidStatus: FluidStatus[] = [ diff --git a/src/utils/date.spec.ts b/src/utils/date.spec.ts index 30b0ff06a..6aa85972d 100644 --- a/src/utils/date.spec.ts +++ b/src/utils/date.spec.ts @@ -34,7 +34,11 @@ describe('date utils', () => { it('should return true if date is latter that now', () => { const result = isLastDateReached( - DateTime.local().plus({ days: 1 }), + DateTime.local() + .setZone('utc', { + keepLocalTime: true, + }) + .plus({ days: 1 }), timeStep ) expect(result).toBe(true) @@ -42,7 +46,11 @@ describe('date utils', () => { it('should return false if date is previous that now', () => { const result = isLastDateReached( - DateTime.local().minus({ days: 1 }), + DateTime.local() + .setZone('utc', { + keepLocalTime: true, + }) + .minus({ days: 1 }), timeStep ) expect(result).toBe(false) @@ -54,7 +62,11 @@ describe('date utils', () => { it('should return true if date is latter that now', () => { const result = isLastDateReached( - DateTime.local().plus({ days: 1 }), + DateTime.local() + .setZone('utc', { + keepLocalTime: true, + }) + .plus({ days: 1 }), timeStep ) expect(result).toBe(true) @@ -62,7 +74,11 @@ describe('date utils', () => { it('should return false if date is previous that now', () => { const result = isLastDateReached( - DateTime.local().minus({ days: 1 }), + DateTime.local() + .setZone('utc', { + keepLocalTime: true, + }) + .minus({ days: 1 }), timeStep ) expect(result).toBe(false) @@ -74,7 +90,11 @@ describe('date utils', () => { it('should return true if date is latter that now', () => { const result = isLastDateReached( - DateTime.local().plus({ days: 1 }), + DateTime.local() + .setZone('utc', { + keepLocalTime: true, + }) + .plus({ days: 1 }), timeStep ) expect(result).toBe(true) @@ -82,7 +102,11 @@ describe('date utils', () => { it('should return false if date is previous that now', () => { const result = isLastDateReached( - DateTime.local().minus({ days: 1 }), + DateTime.local() + .setZone('utc', { + keepLocalTime: true, + }) + .minus({ days: 1 }), timeStep ) expect(result).toBe(false) @@ -94,7 +118,11 @@ describe('date utils', () => { it('should return true if date is latter that now', () => { const result = isLastDateReached( - DateTime.local().plus({ months: 1 }), + DateTime.local() + .setZone('utc', { + keepLocalTime: true, + }) + .plus({ months: 1 }), timeStep ) expect(result).toBe(true) @@ -102,7 +130,11 @@ describe('date utils', () => { it('should return false if date is previous that now', () => { const result = isLastDateReached( - DateTime.local().minus({ months: 1 }), + DateTime.local() + .setZone('utc', { + keepLocalTime: true, + }) + .minus({ months: 1 }), timeStep ) expect(result).toBe(false) @@ -114,7 +146,11 @@ describe('date utils', () => { it('should return true if date is latter that now', () => { const result = isLastDateReached( - DateTime.local().plus({ years: 1 }), + DateTime.local() + .setZone('utc', { + keepLocalTime: true, + }) + .plus({ years: 1 }), timeStep ) expect(result).toBe(true) @@ -122,7 +158,11 @@ describe('date utils', () => { it('should return false if date is previous that now', () => { const result = isLastDateReached( - DateTime.local().minus({ years: 1 }), + DateTime.local() + .setZone('utc', { + keepLocalTime: true, + }) + .minus({ years: 1 }), timeStep ) expect(result).toBe(false) @@ -136,7 +176,11 @@ describe('date utils', () => { it('should return false when date is previous to now + 1 day', () => { const result = isLastPeriodReached( - DateTime.local().minus({ days: 1 }), + DateTime.local() + .setZone('utc', { + keepLocalTime: true, + }) + .minus({ days: 1 }), timeStep ) expect(result).toBe(false) @@ -144,7 +188,11 @@ describe('date utils', () => { it('should return true when date is latter to date + 1 day', () => { const result = isLastPeriodReached( - DateTime.local().plus({ days: 1 }), + DateTime.local() + .setZone('utc', { + keepLocalTime: true, + }) + .plus({ days: 1 }), timeStep ) expect(result).toBe(true) @@ -156,7 +204,11 @@ describe('date utils', () => { it('should return false when date is previous to now + 1 day', () => { const result = isLastPeriodReached( - DateTime.local().minus({ days: 1 }), + DateTime.local() + .setZone('utc', { + keepLocalTime: true, + }) + .minus({ days: 1 }), timeStep ) expect(result).toBe(false) @@ -164,7 +216,11 @@ describe('date utils', () => { it('should return true when date is latter to date + 1 day', () => { const result = isLastPeriodReached( - DateTime.local().plus({ days: 1 }), + DateTime.local() + .setZone('utc', { + keepLocalTime: true, + }) + .plus({ days: 1 }), timeStep ) expect(result).toBe(true) @@ -176,7 +232,11 @@ describe('date utils', () => { it('should return false when date is previous to now + 1 month', () => { const result = isLastPeriodReached( - DateTime.local().minus({ months: 1 }), + DateTime.local() + .setZone('utc', { + keepLocalTime: true, + }) + .minus({ months: 1 }), timeStep ) expect(result).toBe(false) @@ -184,7 +244,11 @@ describe('date utils', () => { it('should return true when date is latter to date + 1 month', () => { const result = isLastPeriodReached( - DateTime.local().plus({ months: 1 }), + DateTime.local() + .setZone('utc', { + keepLocalTime: true, + }) + .plus({ months: 1 }), timeStep ) expect(result).toBe(true) @@ -196,7 +260,11 @@ describe('date utils', () => { it('should return false when date is previous to now + 1 year', () => { const result = isLastPeriodReached( - DateTime.local().minus({ years: 1 }), + DateTime.local() + .setZone('utc', { + keepLocalTime: true, + }) + .minus({ years: 1 }), timeStep ) expect(result).toBe(false) @@ -204,7 +272,11 @@ describe('date utils', () => { it('should return true when date is latter to date + 1 year', () => { const result = isLastPeriodReached( - DateTime.local().plus({ years: 1 }), + DateTime.local() + .setZone('utc', { + keepLocalTime: true, + }) + .plus({ years: 1 }), timeStep ) expect(result).toBe(true) @@ -216,7 +288,11 @@ describe('date utils', () => { it('should return false when date is previous to now + 5 year', () => { const result = isLastPeriodReached( - DateTime.local().minus({ years: 5 }), + DateTime.local() + .setZone('utc', { + keepLocalTime: true, + }) + .minus({ years: 5 }), timeStep ) expect(result).toBe(false) @@ -224,7 +300,11 @@ describe('date utils', () => { it('should return true when date is latter to date + 5 year', () => { const result = isLastPeriodReached( - DateTime.local().plus({ years: 5 }), + DateTime.local() + .setZone('utc', { + keepLocalTime: true, + }) + .plus({ years: 5 }), timeStep ) expect(result).toBe(true) @@ -261,8 +341,12 @@ describe('date utils', () => { describe('convertDateToShortDateString test', () => { const timePeriod: TimePeriod = { - startDate: DateTime.fromISO('2020-01-01T00:09:00.000'), - endDate: DateTime.fromISO('2020-12-29T23:59:59.999'), + startDate: DateTime.fromISO('2020-01-01T00:09:00.000Z', { + zone: 'utc', + }), + endDate: DateTime.fromISO('2020-12-29T23:59:59.999Z', { + zone: 'utc', + }), } it('should return an empty string when the TimePeriod is empty', () => { @@ -319,13 +403,17 @@ describe('date utils', () => { describe('cconvertDateToMonthString test', () => { it('should return the name of the month with " de " ', () => { - const date = DateTime.fromISO('2020-11-29T23:59:59.999') + const date = DateTime.fromISO('2020-11-29T23:59:59.999Z', { + zone: 'utc', + }) const result = convertDateToMonthString(date) expect(result).toBe(' de novembre') }) it('should return the name of the month with " d\'" ', () => { - const date = DateTime.fromISO('2020-10-29T23:59:59.999') + const date = DateTime.fromISO('2020-10-29T23:59:59.999Z', { + zone: 'utc', + }) const result = convertDateToMonthString(date) expect(result).toBe(" d'octobre") }) @@ -333,7 +421,9 @@ describe('date utils', () => { describe('getActualReportDate test', () => { it('should return the 3rd of this month if actual day >= 3', () => { - const now = DateTime.local() + const now = DateTime.local().setZone('utc', { + keepLocalTime: true, + }) jest .spyOn(DateTime, 'local') .mockReturnValueOnce(now.set({ day: 3, month: 11, year: 2020 })) @@ -343,7 +433,9 @@ describe('date utils', () => { }) it('should return the 3rd of previous month if actual day < 3', () => { - const now = DateTime.local() + const now = DateTime.local().setZone('utc', { + keepLocalTime: true, + }) jest .spyOn(DateTime, 'local') .mockReturnValueOnce(now.set({ day: 2, month: 11, year: 2020 })) diff --git a/src/utils/date.ts b/src/utils/date.ts index 6888ed794..3becc39a7 100644 --- a/src/utils/date.ts +++ b/src/utils/date.ts @@ -152,7 +152,11 @@ export const convertDateToMonthString = (date: DateTime): string => { } export const getActualReportDate = (): DateTime => { - const now = DateTime.local().startOf('day') + const now = DateTime.local() + .setZone('utc', { + keepLocalTime: true, + }) + .startOf('day') if (now.day < 3) { return now.set({ day: 3, month: now.month - 1 }) } else { diff --git a/test/__mocks__/datachartData.mock.ts b/test/__mocks__/datachartData.mock.ts index 52491972d..212dd2977 100644 --- a/test/__mocks__/datachartData.mock.ts +++ b/test/__mocks__/datachartData.mock.ts @@ -4,34 +4,46 @@ import { DateTime } from 'luxon' export const graphData: Datachart = { actualData: [ { - date: DateTime.fromISO('2020-10-01T00:00:00.000'), + date: DateTime.fromISO('2020-10-01T00:00:00.000Z', { + zone: 'utc', + }), value: 69.18029999999999, valueDetail: [45.127739999999996, 0.9048899999999999, 23.147669999999998], }, { - date: DateTime.fromISO('2020-10-02T00:00:00.000'), + date: DateTime.fromISO('2020-10-02T00:00:00.000Z', { + zone: 'utc', + }), value: 61.65554999999999, valueDetail: [40.21918999999999, 0.8064649999999999, 20.629894999999998], }, { - date: DateTime.fromISO('2020-10-03T00:00:00.000'), + date: DateTime.fromISO('2020-10-03T00:00:00.000Z', { + zone: 'utc', + }), value: -1, valueDetail: null, }, ], comparisonData: [ { - date: DateTime.fromISO('2020-09-01T00:00:00.000'), + date: DateTime.fromISO('2020-09-01T00:00:00.000Z', { + zone: 'utc', + }), value: 54.090509999999995, valueDetail: [35.284358, 0.707513, 18.098639], }, { - date: DateTime.fromISO('2020-09-02T00:00:00.000'), + date: DateTime.fromISO('2020-09-02T00:00:00.000Z', { + zone: 'utc', + }), value: 56.57427, valueDetail: [36.904565999999996, 0.740001, 18.929703], }, { - date: DateTime.fromISO('2020-09-03T00:00:00.000'), + date: DateTime.fromISO('2020-09-03T00:00:00.000Z', { + zone: 'utc', + }), value: -1, valueDetail: null, }, diff --git a/test/__mocks__/fluidStatusData.mock.ts b/test/__mocks__/fluidStatusData.mock.ts index 69c78d2d1..50d0adf4d 100644 --- a/test/__mocks__/fluidStatusData.mock.ts +++ b/test/__mocks__/fluidStatusData.mock.ts @@ -5,16 +5,16 @@ export const fluidStatusData: FluidStatus[] = [ { fluidType: 0, status: 'errored', - lastDataDate: DateTime.fromISO('2020-09-01T00:00:00.000'), + lastDataDate: DateTime.fromISO('2020-09-01T00:00:00.000Z', { zone: 'utc' }), }, { fluidType: 1, status: 'errored', - lastDataDate: DateTime.fromISO('2020-09-01T00:00:00.000'), + lastDataDate: DateTime.fromISO('2020-09-01T00:00:00.000Z', { zone: 'utc' }), }, { fluidType: 2, status: 'errored', - lastDataDate: DateTime.fromISO('2020-09-01T00:00:00.000'), + lastDataDate: DateTime.fromISO('2020-09-01T00:00:00.000Z', { zone: 'utc' }), }, ] diff --git a/test/__mocks__/profile.mock.ts b/test/__mocks__/profile.mock.ts index 1ca4813e8..e9dcaa200 100644 --- a/test/__mocks__/profile.mock.ts +++ b/test/__mocks__/profile.mock.ts @@ -11,10 +11,10 @@ export const profileData: Profile = { quizHash: '1136feb6185c7643e071d14180c0e95782aa4ba3', explorationHash: '1136feb6185c7643e071d14180c0e95782aa4ba3', isFirstConnection: true, - lastConnectionDate: DateTime.fromISO('2020-11-03T00:00:00.000+01:00'), + lastConnectionDate: DateTime.fromISO('2020-11-03T00:00:00.000Z'), haveSeenFavoriteModal: false, haveSeenOldFluidModal: false, haveSeenLastReport: true, - monthlyReportDate: DateTime.fromISO('2020-11-03T00:00:00.000+01:00'), + monthlyReportDate: DateTime.fromISO('2020-11-03T00:00:00.000Z'), sendReportNotification: false, } -- GitLab