RED-5333: fix date range generation

This commit is contained in:
Dan Percic 2022-10-14 20:57:07 +03:00
parent c90ed462ea
commit 549802c8da
3 changed files with 8 additions and 24 deletions

View File

@ -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);

View File

@ -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,

View File

@ -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;