refactor: replace ignored numeric literals with constants
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
import { ISO_DATE_LENGTH, ISO_DATE_START } from '../../../../common/time';
|
||||
import { BankOperationKind } from './bank-operation-kind';
|
||||
import { ZERO_KOPECKS } from './rub-money';
|
||||
|
||||
export function moscowToday(now = new Date()): string {
|
||||
return new Intl.DateTimeFormat('en-CA', {
|
||||
@@ -10,11 +12,11 @@ export function moscowToday(now = new Date()): string {
|
||||
}
|
||||
|
||||
export function isCalendarDate(value: string): boolean {
|
||||
if (value.length !== 10 || !/^\d{4}-\d{2}-\d{2}$/.test(value)) return false;
|
||||
if (value.length !== ISO_DATE_LENGTH || !/^\d{4}-\d{2}-\d{2}$/.test(value)) return false;
|
||||
if (value.startsWith('0000')) return false;
|
||||
const date = new Date(`${value}T00:00:00.000Z`);
|
||||
return (
|
||||
!Number.isNaN(date.getTime()) && date.toISOString().slice(0, 10) === value
|
||||
!Number.isNaN(date.getTime()) && date.toISOString().slice(ISO_DATE_START, ISO_DATE_LENGTH) === value
|
||||
);
|
||||
}
|
||||
|
||||
@@ -63,8 +65,8 @@ export function bankSummary(
|
||||
kind: string;
|
||||
}>,
|
||||
) {
|
||||
let expenses = 0n;
|
||||
let refunds = 0n;
|
||||
let expenses = ZERO_KOPECKS;
|
||||
let refunds = ZERO_KOPECKS;
|
||||
const categories = new Map<
|
||||
string,
|
||||
{ categoryId: string; expenses: bigint; net: bigint; refunds: bigint }
|
||||
@@ -81,19 +83,19 @@ export function bankSummary(
|
||||
const expense =
|
||||
operation.kind === BankOperationKind.Expense ?
|
||||
operation.amountKopecks :
|
||||
0n;
|
||||
ZERO_KOPECKS;
|
||||
const refund =
|
||||
operation.kind === BankOperationKind.Refund ?
|
||||
operation.amountKopecks :
|
||||
0n;
|
||||
ZERO_KOPECKS;
|
||||
expenses += expense;
|
||||
refunds += refund;
|
||||
if (operation.categoryId !== null) {
|
||||
const category = categories.get(operation.categoryId) ?? {
|
||||
categoryId: operation.categoryId,
|
||||
expenses: 0n,
|
||||
refunds: 0n,
|
||||
net: 0n,
|
||||
expenses: ZERO_KOPECKS,
|
||||
refunds: ZERO_KOPECKS,
|
||||
net: ZERO_KOPECKS,
|
||||
};
|
||||
category.expenses += expense;
|
||||
category.refunds += refund;
|
||||
|
||||
Reference in New Issue
Block a user