From 549802c8daf85333adc1c6b5a9a22ad100cc65cb Mon Sep 17 00:00:00 2001 From: Dan Percic Date: Fri, 14 Oct 2022 20:57:07 +0300 Subject: [PATCH] RED-5333: fix date range generation --- .../license-chart/license-chart.component.ts | 10 ++++++++-- .../license-screen.component.ts | 2 -- .../admin/screens/license/utils/functions.ts | 20 ------------------- 3 files changed, 8 insertions(+), 24 deletions(-) diff --git a/apps/red-ui/src/app/modules/admin/screens/license/license-chart/license-chart.component.ts b/apps/red-ui/src/app/modules/admin/screens/license/license-chart/license-chart.component.ts index a307d819b..387e81038 100644 --- a/apps/red-ui/src/app/modules/admin/screens/license/license-chart/license-chart.component.ts +++ b/apps/red-ui/src/app/modules/admin/screens/license/license-chart/license-chart.component.ts @@ -5,7 +5,7 @@ import { IDateRange, ILicense, ILicenseReport } from '@red/domain'; import { LicenseService } from '@services/license.service'; import { switchMap, tap } from 'rxjs/operators'; import { List, LoadingService } from '@iqser/common-ui'; -import { generateDateRanges, isCurrentMonth, toDate, verboseDate } from '../utils/functions'; +import { isCurrentMonth, toDate, verboseDate } from '../utils/functions'; import { TranslateService } from '@ngx-translate/core'; import { Observable } from 'rxjs'; import { Series } from '@swimlane/ngx-charts'; @@ -41,7 +41,13 @@ export class LicenseChartComponent { const startMonth: number = startDate.month(); const startYear: number = startDate.year(); - const dateRanges = generateDateRanges(startMonth, startYear, endDate.month(), endDate.year()); + const dateRanges = []; + + for (let dt = startDate; dt <= endDate; dt = dt.add(1, 'month')) { + const end = dt.add(1, 'month'); + dateRanges.push({ startMonth: dt.month(), startYear: dt.year(), endMonth: end.month(), endYear: end.year() }); + } + const reports = await this.#getReports(dateRanges, license.id); return this.#mapRangesToReports(startMonth, startYear, dateRanges, reports); diff --git a/apps/red-ui/src/app/modules/admin/screens/license/license-screen/license-screen.component.ts b/apps/red-ui/src/app/modules/admin/screens/license/license-screen/license-screen.component.ts index abc1af4ce..fd9b4fbe6 100644 --- a/apps/red-ui/src/app/modules/admin/screens/license/license-screen/license-screen.component.ts +++ b/apps/red-ui/src/app/modules/admin/screens/license/license-screen/license-screen.component.ts @@ -6,7 +6,6 @@ import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker'; import { UserService } from '@users/user.service'; import { RouterHistoryService } from '@services/router-history.service'; import { LicenseService } from '@services/license.service'; -import { UserPreferenceService } from '@users/user-preference.service'; import { map } from 'rxjs/operators'; @Component({ @@ -29,7 +28,6 @@ export class LicenseScreenComponent implements OnInit { constructor( readonly configService: ConfigService, - readonly userPreferenceService: UserPreferenceService, readonly licenseService: LicenseService, private readonly _userService: UserService, private readonly _loadingService: LoadingService, diff --git a/apps/red-ui/src/app/modules/admin/screens/license/utils/functions.ts b/apps/red-ui/src/app/modules/admin/screens/license/utils/functions.ts index bf8a7829d..f2c71fe4d 100644 --- a/apps/red-ui/src/app/modules/admin/screens/license/utils/functions.ts +++ b/apps/red-ui/src/app/modules/admin/screens/license/utils/functions.ts @@ -5,26 +5,6 @@ export function toDate(month: number, year: number) { return dayjs(`01-${month}-${year}`, 'DD-M-YYYY').toDate(); } -export function generateDateRanges(month: number, year: number, endMonth: number, endYear: number) { - const dates: IDateRange[] = []; - - while (month <= endMonth && year <= endYear) { - let nextMonth = month + 1; - let nextYear = year; - if (nextMonth === 12) { - nextMonth = 0; - nextYear++; - } - - dates.push({ startMonth: month, startYear: year, endMonth: nextMonth, endYear: nextYear }); - - year = nextYear; - month = nextMonth; - } - - return dates; -} - export function isCurrentMonth(month: number, year: number) { const now = dayjs(); const currentMonth = now.month() + 1;