Skip to content

Commit

Permalink
fix days back
Browse files Browse the repository at this point in the history
  • Loading branch information
shayki5 committed Oct 3, 2023
1 parent 1838cc0 commit d774cd4
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import "dotenv/config";
import { subDays, format, startOfMonth, differenceInDays } from "date-fns";
import {
subDays,
format,
startOfMonth,
differenceInDays,
startOfDay,
} from "date-fns";
import { AccountConfig } from "./types";
import { logToPublicLog } from "./utils/logger.js";

Expand All @@ -19,7 +25,10 @@ const {
/**
* Add default values in case the value is falsy (0 is not valid here) or an empty string
*/
export const daysBackToScrape = DAYS_BACK || 10;
export const daysBackToScrape =
SCRAPE_FROM_BEGINNING_OF_MONTH === "true"
? differenceInDays(Date.now(), startOfMonth(Date.now()))
: DAYS_BACK || 10;
export const worksheetName = WORKSHEET_NAME || "_moneyman";
export const futureMonthsToScrape = parseInt(FUTURE_MONTHS, 10);

Expand All @@ -32,11 +41,13 @@ export const systemName = "moneyman";
export const currentDate = format(Date.now(), "yyyy-MM-dd");
export const scrapeStartDate =
SCRAPE_FROM_BEGINNING_OF_MONTH === "true"
? subDays(
Date.now(),
Number(differenceInDays(Date.now(), startOfMonth(Date.now()))),
? startOfDay(
subDays(
Date.now(),
Number(differenceInDays(Date.now(), startOfMonth(Date.now()))),
),
)
: subDays(Date.now(), Number(daysBackToScrape));
: startOfDay(subDays(Date.now(), Number(daysBackToScrape)));

export const accounts = parseAccounts(ACCOUNTS_JSON).filter(
(account) =>
Expand Down

0 comments on commit d774cd4

Please sign in to comment.