Browse Source

Feature/Add `wtd` and `mtd` as possible values for date range

This commit adds support for the following date ranges
- 'wtd': week-to-date (from the start of the week)
- 'mtd': month-to-date (from the start of the month)

fixes #2900
pull/2902/head
Cédric Meuter 2 years ago
parent
commit
2b8ea4865f
  1. 18
      apps/api/src/app/portfolio/portfolio.service.ts
  2. 2
      apps/api/src/app/user/update-user-setting.dto.ts
  3. 2
      libs/common/src/lib/types/date-range.type.ts

18
apps/api/src/app/portfolio/portfolio.service.ts

@ -73,7 +73,9 @@ import {
min,
parseISO,
set,
setDayOfYear,
startOfWeek,
startOfMonth,
startOfYear,
subDays,
subYears
} from 'date-fns';
@ -1652,7 +1654,19 @@ export class PortfolioService {
case 'ytd':
portfolioStart = max([
portfolioStart,
setDayOfYear(new Date().setHours(0, 0, 0, 0), 1)
startOfYear(new Date().setHours(0, 0, 0, 0))
]);
break;
case 'mtd':
portfolioStart = max([
portfolioStart,
startOfMonth(new Date().setHours(0, 0, 0, 0))
]);
break;
case 'wtd':
portfolioStart = max([
portfolioStart,
startOfWeek(new Date().setHours(0, 0, 0, 0), { weekStartsOn: 1 })
]);
break;
case '1y':

2
apps/api/src/app/user/update-user-setting.dto.ts

@ -30,7 +30,7 @@ export class UpdateUserSettingDto {
@IsOptional()
colorScheme?: ColorScheme;
@IsIn(<DateRange[]>['1d', '1y', '5y', 'max', 'ytd'])
@IsIn(<DateRange[]>['1d', '1y', '5y', 'max', 'mtd', 'wtd', 'ytd'])
@IsOptional()
dateRange?: DateRange;

2
libs/common/src/lib/types/date-range.type.ts

@ -1 +1 @@
export type DateRange = '1d' | '1y' | '5y' | 'max' | 'ytd';
export type DateRange = '1d' | '1y' | '5y' | 'max' | 'mtd' | 'wtd' | 'ytd';

Loading…
Cancel
Save