Skip to content

Commit ba325c9

Browse files
committed
feat: helpers to calculate prior (local) month range
by default use the America/Los_Angeles time zone override with TZ_NAME env var
1 parent 1166cab commit ba325c9

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

.env.sample

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@ TOGGL_USER_INFO=data/toggl-user-info-sample.json
88
TOGGL_API_TOKEN=token
99
TOGGL_CLIENT_ID=client
1010
TOGGL_WORKSPACE_ID=workspace
11+
12+
TZ_NAME=America/Los_Angeles

compiler_admin/main.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
from argparse import ArgumentParser, _SubParsersAction
2+
from datetime import datetime, timedelta
3+
import os
24
import sys
5+
from zoneinfo import ZoneInfo
36

47
from compiler_admin import __version__ as version
58
from compiler_admin.commands.info import info
@@ -9,6 +12,24 @@
912
from compiler_admin.commands.user.convert import ACCOUNT_TYPE_OU
1013

1114

15+
TZINFO = ZoneInfo(os.environ.get("TZ_NAME", "America/Los_Angeles"))
16+
17+
18+
def local_now():
19+
return datetime.now(tz=TZINFO)
20+
21+
22+
def prior_month_end():
23+
now = local_now()
24+
first = now.replace(day=1)
25+
return first - timedelta(days=1)
26+
27+
28+
def prior_month_start():
29+
end = prior_month_end()
30+
return end.replace(day=1)
31+
32+
1233
def add_sub_cmd_parser(parser: ArgumentParser, dest="subcommand", help=None):
1334
"""Helper adds a subparser for the given dest."""
1435
return parser.add_subparsers(dest=dest, help=help)

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ requires-python = ">=3.11"
1313
dependencies = [
1414
"advanced-gam-for-google-workspace @ git+https://github.com/taers232c/GAMADV-XTD3.git@v7.00.05#subdirectory=src",
1515
"pandas==2.2.3",
16+
"tzdata",
1617
]
1718

1819
[project.urls]

0 commit comments

Comments
 (0)