diff --git a/apps/api/src/app/portfolio/portfolio.service.ts b/apps/api/src/app/portfolio/portfolio.service.ts index e656d2df3..8de46530e 100644 --- a/apps/api/src/app/portfolio/portfolio.service.ts +++ b/apps/api/src/app/portfolio/portfolio.service.ts @@ -72,6 +72,7 @@ import { set, setDayOfYear, subDays, + subMonths, subYears } from 'date-fns'; import { isEmpty, sortBy, uniq, uniqBy } from 'lodash'; @@ -1624,6 +1625,28 @@ export class PortfolioService { setDayOfYear(new Date().setHours(0, 0, 0, 0), 1) ]); break; + + case '1w': + portfolioStart = max([ + portfolioStart, + subDays(new Date().setHours(0, 0, 0, 0), 7) + ]); + break; + + case '1m': + portfolioStart = max([ + portfolioStart, + subMonths(new Date().setHours(0, 0, 0, 0), 1) + ]); + break; + + case '3m': + portfolioStart = max([ + portfolioStart, + subMonths(new Date().setHours(0, 0, 0, 0), 3) + ]); + break; + case '1y': portfolioStart = max([ portfolioStart, diff --git a/apps/api/src/app/user/update-user-setting.dto.ts b/apps/api/src/app/user/update-user-setting.dto.ts index e510880ed..b1967faba 100644 --- a/apps/api/src/app/user/update-user-setting.dto.ts +++ b/apps/api/src/app/user/update-user-setting.dto.ts @@ -29,7 +29,7 @@ export class UpdateUserSettingDto { @IsOptional() colorScheme?: ColorScheme; - @IsIn(['1d', '1y', '5y', 'max', 'ytd']) + @IsIn(['1d', '1w', '1m', '3m', '1y', '5y', 'max', 'ytd']) @IsOptional() dateRange?: DateRange; diff --git a/apps/client/src/app/components/toggle/toggle.component.ts b/apps/client/src/app/components/toggle/toggle.component.ts index a330e8af8..3eb65e32c 100644 --- a/apps/client/src/app/components/toggle/toggle.component.ts +++ b/apps/client/src/app/components/toggle/toggle.component.ts @@ -19,6 +19,9 @@ import { ToggleOption } from '@ghostfolio/common/types'; export class ToggleComponent implements OnChanges, OnInit { public static DEFAULT_DATE_RANGE_OPTIONS: ToggleOption[] = [ { label: $localize`Today`, value: '1d' }, + { label: $localize`1W`, value: '1w' }, + { label: $localize`1M`, value: '1m' }, + { label: $localize`3M`, value: '3m' }, { label: $localize`YTD`, value: 'ytd' }, { label: $localize`1Y`, value: '1y' }, { label: $localize`5Y`, value: '5y' }, diff --git a/libs/common/src/lib/types/date-range.type.ts b/libs/common/src/lib/types/date-range.type.ts index afee7b100..5b7d1fbf6 100644 --- a/libs/common/src/lib/types/date-range.type.ts +++ b/libs/common/src/lib/types/date-range.type.ts @@ -1 +1 @@ -export type DateRange = '1d' | '1y' | '5y' | 'max' | 'ytd'; +export type DateRange = '1d' | '1w' | '1m' | '3m' | '1y' | '5y' | 'max' | 'ytd';