refactor: replace ignored numeric literals with constants
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { ISO_DATE_LENGTH, ISO_DATE_START } from '../../common/time';
|
||||
import { planIncomePeriod } from './income/income.api';
|
||||
import { dateOnlyBounds, moscowDate } from './investment-calendar';
|
||||
import {
|
||||
@@ -5,6 +6,12 @@ import {
|
||||
operationIntervals,
|
||||
} from './operations/domain/operations-sync-plan';
|
||||
|
||||
const FORECAST_YEARS = 1;
|
||||
const JANUARY_INDEX = 0;
|
||||
const FIRST_DAY_OF_MONTH = 1;
|
||||
const EXCLUSIVE_END_OFFSET_MS = 1;
|
||||
const NO_END_OFFSET_MS = 0;
|
||||
|
||||
export type InvestmentScreen = {
|
||||
accountId?: string;
|
||||
candlePeriod?: 'all' | 'halfYear' | 'month' | 'year';
|
||||
@@ -232,7 +239,7 @@ export function planInvestmentScreen(
|
||||
const day =
|
||||
screen.screen === 'stock' || screen.screen === 'bond' ?
|
||||
moscowDate(now) :
|
||||
now.toISOString().slice(0, 10);
|
||||
now.toISOString().slice(ISO_DATE_START, ISO_DATE_LENGTH);
|
||||
const from =
|
||||
screen.screen === 'events' && screen.from ?
|
||||
new Date(`${screen.from}T00:00:00Z`) :
|
||||
@@ -250,7 +257,7 @@ export function planInvestmentScreen(
|
||||
}
|
||||
if (screen.screen === 'stock' || screen.screen === 'bond') {
|
||||
from.setUTCFullYear(from.getUTCFullYear() - incomeHistoryYears);
|
||||
to.setUTCFullYear(to.getUTCFullYear() + 1);
|
||||
to.setUTCFullYear(to.getUTCFullYear() + FORECAST_YEARS);
|
||||
}
|
||||
sources.push({
|
||||
...identity,
|
||||
@@ -325,7 +332,7 @@ export function ledgerRange(
|
||||
new Date(fromValue) :
|
||||
instrumentUid ?
|
||||
new Date(opening ? `${opening}T00:00:00Z` : '1970-01-01T00:00:00Z') :
|
||||
new Date(Date.UTC(now.getUTCFullYear(), 0, 1));
|
||||
new Date(Date.UTC(now.getUTCFullYear(), JANUARY_INDEX, FIRST_DAY_OF_MONTH));
|
||||
const end = toValue ?
|
||||
new Date(
|
||||
/^\d{4}-\d{2}-\d{2}$/.test(toValue) ?
|
||||
@@ -335,6 +342,6 @@ export function ledgerRange(
|
||||
now;
|
||||
return {
|
||||
from,
|
||||
to: new Date(Math.min(end.valueOf() + (toValue ? 1 : 0), now.valueOf())),
|
||||
to: new Date(Math.min(end.valueOf() + (toValue ? EXCLUSIVE_END_OFFSET_MS : NO_END_OFFSET_MS), now.valueOf())),
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user