Skip to content

Commit b8df026

Browse files
committed
fix: default time parsing to PT
1 parent bc0b8f8 commit b8df026

1 file changed

Lines changed: 12 additions & 9 deletions

File tree

bmt_discord_bot/lib/time.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
# Copyright (c) 2021 Rapptz
66

77
import re
8-
from datetime import datetime, timedelta, timezone
8+
import zoneinfo
9+
from datetime import datetime, timedelta
910

1011
import parsedatetime as pdt
1112
from dateutil.relativedelta import relativedelta
@@ -14,6 +15,8 @@
1415
from .formats import format_dt as format_dt
1516
from .formats import human_join, plural
1617

18+
DEFAULT_TIMEZONE = zoneinfo.ZoneInfo("America/Los_Angeles")
19+
1720
# Monkey patch mins and secs into the units
1821
units = pdt.pdtLocales["en_US"].units
1922
units["minutes"].append("mins")
@@ -39,7 +42,7 @@ def __init__(self, argument, *, now=None):
3942
raise commands.BadArgument("invalid time provided")
4043

4144
data = {k: int(v) for k, v in match.groupdict(default=0).items()}
42-
now = now or datetime.now(timezone.utc)
45+
now = now or datetime.now(DEFAULT_TIMEZONE)
4346
self.dt = now + relativedelta(**data)
4447

4548
@classmethod
@@ -51,13 +54,13 @@ class HumanTime:
5154
calendar = pdt.Calendar(version=pdt.VERSION_CONTEXT_STYLE)
5255

5356
def __init__(self, argument, *, now=None):
54-
now = now or datetime.now(timezone.utc)
57+
now = now or datetime.now(DEFAULT_TIMEZONE)
5558
if now.tzinfo is None:
56-
now = now.replace(tzinfo=timezone.utc)
59+
now = now.replace(tzinfo=DEFAULT_TIMEZONE)
5760

5861
dt, status = self.calendar.parseDT(argument, sourceTime=now)
5962
if dt.tzinfo is None:
60-
dt = dt.replace(tzinfo=timezone.utc)
63+
dt = dt.replace(tzinfo=DEFAULT_TIMEZONE)
6164

6265
if not status.hasDateOrTime:
6366
raise commands.BadArgument('invalid time provided, try e.g. "tomorrow" or "3 days"')
@@ -198,7 +201,7 @@ async def convert(self, ctx, argument):
198201
if status.accuracy == pdt.pdtContext.ACU_HALFDAY:
199202
dt = dt.replace(day=now.day + 1)
200203

201-
result = self.Result(dt.replace(tzinfo=timezone.utc))
204+
result = self.Result(dt.replace(tzinfo=DEFAULT_TIMEZONE))
202205

203206
if begin in (0, 1):
204207
if begin == 1:
@@ -224,16 +227,16 @@ async def convert(self, ctx, argument):
224227

225228

226229
def human_timedelta(dt, *, source=None, accuracy=3, brief=False, suffix=True):
227-
now = source or datetime.now(timezone.utc)
230+
now = source or datetime.now(DEFAULT_TIMEZONE)
228231

229232
if isinstance(dt, timedelta):
230233
dt = now + dt
231234

232235
if dt.tzinfo is None:
233-
dt = dt.replace(tzinfo=timezone.utc)
236+
dt = dt.replace(tzinfo=DEFAULT_TIMEZONE)
234237

235238
if now.tzinfo is None:
236-
now = now.replace(tzinfo=timezone.utc)
239+
now = now.replace(tzinfo=DEFAULT_TIMEZONE)
237240

238241
# Microsecond free zone
239242
now = now.replace(microsecond=0)

0 commit comments

Comments
 (0)