Skip to content

Commit

Permalink
fix: auto date for transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
joshcanhelp committed May 28, 2023
1 parent 4943c66 commit c1a3949
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/scripts/transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { sortTransactionsByDate } from "../utils/transaction.js";
import { CommandArgs } from "../cli.js";

export const run = (config: Configuration, cliArgs: CommandArgs): void => {
const getDate = (cliArgs.date as string) || `${new Date().getFullYear()}`;
const getDate = (cliArgs.date as string) || (cliArgs.year as string) || `${new Date().getFullYear()}`;
const dateRegex = /^[0-9]{4}(?:-[0-9]{2})?$/;
if (!getDate || !(getDate.match(dateRegex) || []).length) {
hardNo("Invalid transaction date argument.");
Expand All @@ -17,7 +17,7 @@ export const run = (config: Configuration, cliArgs: CommandArgs): void => {
const reportCategory = reportTermsParts[0] || "*";
const reportSubCategory = reportTermsParts[1] || "*";

const outputFile = config.getOutputFile({ year: getDate.split("-")[0] });
const outputFile = config.getOutputFile({ date: getDate });

const db: DB = new DB(outputFile);
try {
Expand Down
1 change: 1 addition & 0 deletions src/utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ export const getConfiguration = (): Configuration => {
(year as string) || date
? (date as string).split("-")[0]
: new Date().getFullYear();

return mergedConfig.outputFile[reportYear];
}

Expand Down

0 comments on commit c1a3949

Please sign in to comment.