From 79a205c39a4b62d2e473741aa095459685b4aa74 Mon Sep 17 00:00:00 2001
From: Dimitri DI GUSTO <dimitri.digusto@ausy.fr>
Date: Wed, 6 Jan 2021 08:37:36 +0100
Subject: [PATCH] Make statistics query paramaters end and start date works in
 january

---
 .../dataset-detail/services/usage-statistics.service.ts   | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/app/dataset-detail/services/usage-statistics.service.ts b/src/app/dataset-detail/services/usage-statistics.service.ts
index c87153c6..4c650549 100644
--- a/src/app/dataset-detail/services/usage-statistics.service.ts
+++ b/src/app/dataset-detail/services/usage-statistics.service.ts
@@ -19,12 +19,12 @@ export class UsageStatisticsService {
     // However the months in javascript dates goes from 0 to 11 so when passing start and end dates, we don't need to subsctract a month
     // The backend service expect a 2 digits month while javascript date does not give 'O1' but only '1'. This is while we use a small trick
     // to make sure there always two digits for the month in the date
+    const monthListArray = ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12'];
     const today = new Date();
-    const aMonthAgo = `${today.getFullYear()}-${`0${today.getMonth()}`.slice(-2)}-${today.getDate()}`;
-
+    today.setMonth(today.getMonth() - 1);
+    const aMonthAgo = `${today.getFullYear()}-${monthListArray[today.getMonth()]}-${today.getDate()}`;
     today.setFullYear(today.getFullYear() - 1);
-    const aMonthAndAYearAgo = `${today.getFullYear()}-${`0${today.getMonth()}`.slice(-2)}-${today.getDate()}`;
-
+    const aMonthAndAYearAgo = `${today.getFullYear()}-${monthListArray[today.getMonth()]}-${today.getDate()}`;
     const url = `${APP_CONFIG.backendUrls.datasetUsageStatistics}?start=${aMonthAndAYearAgo}&uuid=${uuid}&granularity=month&end=${aMonthAgo}`;
 
     return this._httpClient.get(url).pipe(
-- 
GitLab