Browse Source

Refactor isAfter() with isFuture() and isPast()

pull/7389/head
Thomas Kaul 1 month ago
parent
commit
b73a3f2fbe
  1. 6
      apps/api/src/app/portfolio/calculator/portfolio-calculator.ts
  2. 4
      apps/api/src/services/benchmark/benchmark.service.ts

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

@ -51,6 +51,8 @@ import {
format, format,
isAfter, isAfter,
isBefore, isBefore,
isFuture,
isPast,
isWithinInterval, isWithinInterval,
min, min,
startOfDay, startOfDay,
@ -134,7 +136,7 @@ export abstract class PortfolioCalculator {
dateOfFirstActivity = date; dateOfFirstActivity = date;
} }
if (isAfter(date, new Date())) { if (isFuture(date)) {
// Adapt date to today if activity is in future (e.g. liability) // Adapt date to today if activity is in future (e.g. liability)
// to include it in the interval // to include it in the interval
date = endOfDay(new Date()); date = endOfDay(new Date());
@ -1113,7 +1115,7 @@ export abstract class PortfolioCalculator {
portfolioSnapshot portfolioSnapshot
); );
if (isAfter(new Date(), new Date(expiration))) { if (isPast(new Date(expiration))) {
isCachedPortfolioSnapshotExpired = true; isCachedPortfolioSnapshotExpired = true;
} }
} catch {} } 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 { Injectable, Logger } from '@nestjs/common';
import { SymbolProfile } from '@prisma/client'; import { SymbolProfile } from '@prisma/client';
import { Big } from 'big.js'; 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 { round, uniqBy } from 'lodash';
import ms from 'ms'; import ms from 'ms';
@ -94,7 +94,7 @@ export class BenchmarkService {
this.logger.debug('Fetched benchmarks from cache'); this.logger.debug('Fetched benchmarks from cache');
if (isAfter(new Date(), new Date(expiration))) { if (isPast(new Date(expiration))) {
this.calculateAndCacheBenchmarks({ this.calculateAndCacheBenchmarks({
enableSharing enableSharing
}); });

Loading…
Cancel
Save