Skip to content

Commit b79ea50

Browse files
authored
Merge pull request #15 from tdomhan/just-to-date-arg
Add "to" date argument.
2 parents a225eb0 + ab30464 commit b79ea50

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/commands/import.command.ts

+14
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,22 @@ const handleCommand = async (argv: ArgumentsCamelCase) => {
3030
const fromDate = argv.from
3131
? parse(argv.from as string, DATE_FORMAT, new Date())
3232
: undefined;
33+
const toDate = argv.to
34+
? parse(argv.to as string, DATE_FORMAT, new Date())
35+
: undefined;
3336

3437
if (fromDate && isNaN(fromDate.getTime())) {
3538
throw new Error(
3639
`Invalid from date: '${argv.from}'. Expected a date in the format: ${DATE_FORMAT}`
3740
);
3841
}
3942

43+
if (toDate && isNaN(toDate.getTime())) {
44+
throw new Error(
45+
`Invalid "to" date: '${argv.to}'. Expected a date in the format: ${DATE_FORMAT}`
46+
);
47+
}
48+
4049
for (const serverConfig of config.actualServers) {
4150
const actualApi = new ActualApi(serverConfig, logger);
4251

@@ -106,6 +115,11 @@ export default {
106115
.describe(
107116
'from',
108117
`Import transactions on or after this date (${DATE_FORMAT})`
118+
)
119+
.string('to')
120+
.describe(
121+
'from',
122+
`Import transactions up to this date (${DATE_FORMAT})`
109123
);
110124
},
111125
handler: (argv) => handleCommand(argv),

src/utils/Importer.ts

+4
Original file line numberDiff line numberDiff line change
@@ -130,16 +130,19 @@ class Importer {
130130
async importTransactions({
131131
accountMapping,
132132
from,
133+
to,
133134
isDryRun = false,
134135
}: {
135136
accountMapping: Map<MonMonAccount, Account>;
136137
from?: Date;
138+
to?: Date;
137139
isDryRun?: boolean;
138140
}) {
139141
const fromDate = from ?? subMonths(new Date(), 1);
140142
const earliestImportDate = this.budgetConfig.earliestImportDate
141143
? new Date(this.budgetConfig.earliestImportDate)
142144
: null;
145+
const toDate = to;
143146

144147
const importDate =
145148
earliestImportDate && earliestImportDate > fromDate
@@ -157,6 +160,7 @@ class Importer {
157160

158161
let monMonTransactions = await getTransactions({
159162
from: importDate,
163+
to: toDate
160164
});
161165

162166
if (monMonTransactions.length === 0) {

0 commit comments

Comments
 (0)