Browse Source

Task/refactor isAfter() with isFuture() and isPast() (#7389)

Refactor isAfter() with isFuture() and isPast()
pull/7384/merge
Thomas Kaul 2 days ago
committed by GitHub
parent
commit
72663fe40a
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 6
      apps/api/src/app/portfolio/calculator/portfolio-calculator.ts
  2. 4
      apps/api/src/services/benchmark/benchmark.service.ts
  3. 4
      apps/client/src/app/components/investment-chart/investment-chart.component.ts

6
apps/api/src/app/portfolio/calculator/portfolio-calculator.ts

@ -51,6 +51,8 @@ import {
format,
isAfter,
isBefore,
isFuture,
isPast,
isWithinInterval,
min,
startOfDay,
@ -134,7 +136,7 @@ export abstract class PortfolioCalculator {
dateOfFirstActivity = date;
}
if (isAfter(date, new Date())) {
if (isFuture(date)) {
// Adapt date to today if activity is in future (e.g. liability)
// to include it in the interval
date = endOfDay(new Date());
@ -1113,7 +1115,7 @@ export abstract class PortfolioCalculator {
portfolioSnapshot
);
if (isAfter(new Date(), new Date(expiration))) {
if (isPast(new Date(expiration))) {
isCachedPortfolioSnapshotExpired = true;
}
} catch {}

4
apps/api/src/services/benchmark/benchmark.service.ts

@ -23,7 +23,7 @@ import { BenchmarkTrend } from '@ghostfolio/common/types';
import { Injectable, Logger } from '@nestjs/common';
import { SymbolProfile } from '@prisma/client';
import { Big } from 'big.js';
import { addHours, isAfter, subDays } from 'date-fns';
import { addHours, isPast, subDays } from 'date-fns';
import { round, uniqBy } from 'lodash';
import ms from 'ms';
@ -94,7 +94,7 @@ export class BenchmarkService {
this.logger.debug('Fetched benchmarks from cache');
if (isAfter(new Date(), new Date(expiration))) {
if (isPast(new Date(expiration))) {
this.calculateAndCacheBenchmarks({
enableSharing
});

4
apps/client/src/app/components/investment-chart/investment-chart.component.ts

@ -41,7 +41,7 @@ import {
} from 'chart.js';
import 'chartjs-adapter-date-fns';
import { type AnnotationOptions } from 'chartjs-plugin-annotation';
import { isAfter } from 'date-fns';
import { isFuture } from 'date-fns';
import { NgxSkeletonLoaderModule } from 'ngx-skeleton-loader';
@Component({
@ -311,6 +311,6 @@ export class GfInvestmentChartComponent implements OnChanges, OnDestroy {
return undefined;
}
return isAfter(new Date(xValue), new Date()) ? aValue : undefined;
return isFuture(new Date(xValue)) ? aValue : undefined;
}
}

Loading…
Cancel
Save