From 0441e00a9e6a1389ba7e7b8acfaf744231007136 Mon Sep 17 00:00:00 2001 From: Maarceeli Date: Wed, 16 Apr 2025 10:03:54 +0200 Subject: [PATCH] Add function to get current month's start and end dates --- src/utils.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/utils.py b/src/utils.py index c8ddc2b..8155825 100644 --- a/src/utils.py +++ b/src/utils.py @@ -1,6 +1,7 @@ import keyring import os from pathlib import Path +from datetime import datetime, timedelta import configparser import subprocess import sys @@ -89,4 +90,16 @@ def restart(page: ft.Page): subprocess.Popen([python] + sys.argv) page.window.destroy() except FileNotFoundError: - exit() \ No newline at end of file + exit() + +def get_current_month_dates(): + today = datetime.today() + start_date = today.replace(day=1) + # To get the last day, move to the next month, then subtract one day + if today.month == 12: + next_month = today.replace(year=today.year + 1, month=1, day=1) + else: + next_month = today.replace(month=today.month + 1, day=1) + end_date = next_month - timedelta(days=1) + + return start_date.strftime("%Y-%m-%d"), end_date.strftime("%Y-%m-%d") \ No newline at end of file