From 9d0aaa64683a72f37b7f3211d5f310fa5d4fe754 Mon Sep 17 00:00:00 2001 From: Pierre Ecarlat <pecarlat@grandlyon.com> Date: Wed, 15 Jan 2025 14:28:43 +0100 Subject: [PATCH] Updated tests for non-leap year --- src/utils/date.spec.ts | 4 ++-- src/utils/date.ts | 31 ++++++++++------------------- tests/__mocks__/profileType.mock.ts | 30 ++++++++++++++-------------- 3 files changed, 27 insertions(+), 38 deletions(-) diff --git a/src/utils/date.spec.ts b/src/utils/date.spec.ts index 362a95ddd..02bf7c5d4 100644 --- a/src/utils/date.spec.ts +++ b/src/utils/date.spec.ts @@ -449,7 +449,7 @@ describe('date utils', () => { }) jest .spyOn(DateTime, 'local') - .mockReturnValue(now.set({ month: 9, day: 21 })) + .mockReturnValue(now.set({ month: 6, day: 21 })) const currentSeason = getCurrentSeason() expect(currentSeason).toEqual(Season.SUMMER) }) @@ -459,7 +459,7 @@ describe('date utils', () => { }) jest .spyOn(DateTime, 'local') - .mockReturnValue(now.set({ month: 3, day: 31 })) + .mockReturnValue(now.set({ month: 3, day: 30 })) const currentSeason = getCurrentSeason() expect(currentSeason).toEqual(Season.WINTER) }) diff --git a/src/utils/date.ts b/src/utils/date.ts index 9468ee8f4..d545d7b9d 100644 --- a/src/utils/date.ts +++ b/src/utils/date.ts @@ -3,18 +3,6 @@ import { DateTime } from 'luxon' import { Dataload } from 'models' import { getMonthNameWithPrep } from './utils' -/** Between 21st of June and 20th of September */ -export const SUMMER_WEEK_DATES = { - start: 25, - end: 38, -} as const - -/** Between 31st of October and 30th of March */ -const WINTER_WEEK_DATES = { - start: 44, - end: 13, -} as const - export function compareDates(dateA: DateTime, dateB: DateTime) { return dateA < dateB ? -1 : 1 } @@ -165,17 +153,18 @@ export const getActualAnalysisDate = (): DateTime => { * - Otherwise returns null. */ export function getCurrentSeason() { - const weekNumber = DateTime.local().weekNumber - if ( - weekNumber >= SUMMER_WEEK_DATES.start && - weekNumber <= SUMMER_WEEK_DATES.end - ) { - return Season.SUMMER + const now = DateTime.local().setZone('utc', { keepLocalTime: true }) + const month = now.month + const day = now.day + + if ((month >= 10 && day >= 31) || (month <= 3 && day <= 31)) { + return Season.WINTER } else if ( - weekNumber >= WINTER_WEEK_DATES.start || - weekNumber <= WINTER_WEEK_DATES.end + (month === 6 && day >= 21) || + (month >= 7 && month <= 8) || + (month === 9 && day <= 20) ) { - return Season.WINTER + return Season.SUMMER } return null } diff --git a/tests/__mocks__/profileType.mock.ts b/tests/__mocks__/profileType.mock.ts index 5a0c69dc5..8e522e83d 100644 --- a/tests/__mocks__/profileType.mock.ts +++ b/tests/__mocks__/profileType.mock.ts @@ -71,9 +71,9 @@ export const mockMonthElectricSpecificConsumption = 175 export const mockMonthColdWaterConsumption = 4247 export const mockWaterRawNeeds = 2480 -export const mockWaterSpreadNeeds = 2708 +export const mockWaterSpreadNeeds = 2701 export const mockMonthEcsConsumptionOther = 166 -export const mockMonthEcsConsumptionThermo = 111 +export const mockMonthEcsConsumptionThermo = 110 export const mockProfileType1: ProfileType = { housingType: HousingType.APARTMENT, @@ -100,7 +100,7 @@ export const mockProfileType1: ProfileType = { // For the month of February export const mockMonthConsumption1 = 1174 -export const mockMonthEcsConsumption1Solar = 135 +export const mockMonthEcsConsumption1Solar = 134 export const mockProfileType2: ProfileType = { housingType: HousingType.INDIVIDUAL_HOUSE, @@ -180,17 +180,17 @@ export const mockMonthlyForecastJanuaryTestProfile1: MonthlyForecast = { detailsMonthlyForecast: { coldWaterConsumption: null, cookingConsumption: 85, - ecsConsumption: 291, + ecsConsumption: 290, electricSpecificConsumption: null, heatingConsumption: null, }, fluidType: 2, - load: 376, - value: 94.602, + load: 375, + value: 94.35, }, ], month: 1, - totalValue: 4938.102, + totalValue: 4937.85, } export const mockTestProfile2: ProfileType = { @@ -222,13 +222,13 @@ export const mockMonthlyForecastJanuaryTestProfile2: MonthlyForecast = { detailsMonthlyForecast: { coldWaterConsumption: null, cookingConsumption: 34, - ecsConsumption: 249, + ecsConsumption: 248, electricSpecificConsumption: 151, heatingConsumption: 1237, }, fluidType: 0, - load: 1671, - value: 420.42, + load: 1670, + value: 420.17, }, { detailsMonthlyForecast: { @@ -256,7 +256,7 @@ export const mockMonthlyForecastJanuaryTestProfile2: MonthlyForecast = { }, ], month: 1, - totalValue: 2557.52, + totalValue: 2557.27, } export const mockTestProfile3: ProfileType = { @@ -453,15 +453,15 @@ export const mockMonthlyForecastJanuaryTest1WithFullArrays: MonthlyForecast = { detailsMonthlyForecast: { coldWaterConsumption: null, cookingConsumption: 85, - ecsConsumption: 291, + ecsConsumption: 290, electricSpecificConsumption: null, heatingConsumption: null, }, fluidType: 2, - load: 376, - value: 94.602, + load: 375, + value: 94.35, }, ], month: 1, - totalValue: 4536.842, + totalValue: 4536.59, } -- GitLab