Skip to content

Commit 0cc7ccc

Browse files
committed
doc updates
1 parent cef371c commit 0cc7ccc

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

appdaemon/parse.py

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,9 @@ def resolve_time_str(
228228
229229
Args:
230230
time_str (str): The time string to parse. Can be in various formats
231-
now (datetime): The current datetime to use as a reference for parsing.
231+
now (datetime, str): The current datetime to use as a reference for parsing. This is intended to represent the
232+
datetime that the call is being made, which affects how times are resolved. Strings will be interpreted as
233+
ISO 8601 datetime strings, which helps with testing.
232234
location (Location | None): Location used for sunrise/sunset parsing. Comes from the astral package
233235
days_offset (int): Number of days to offset from the current date for sunrise/sunset parsing. Defaults to 0.
234236
@@ -306,14 +308,20 @@ def parse_datetime(
306308
307309
Args:
308310
input_ (str | time | datetime): The input to parse. Can be a string, time, or datetime object.
309-
now (datetime): The current datetime to use as a reference for parsing. This is intended to represent the
310-
datetime that the call is being made, which affects how times are resolved.
311+
now (datetime | str): The current datetime to use as a reference for parsing. This is intended to represent the
312+
datetime that the call is being made, which affects how times are resolved. Strings will be interpreted as
313+
ISO 8601 datetime strings, which helps with testing.
311314
location (Location, optional): Location used for sunrise/sunset parsing. This is needed in order to parse
312315
sunset/sunrise times from the input.
313-
today (bool, optional): If `True`, forces the result to be today. If `False`, allows the result to be in the
314-
past. This will be forced to `False` if the ``days_offset`` is negative.
315-
offset (timedelta, optional): An optional offset to apply to the resulting datetime.
316-
days_offset (int, optional): Number of days to offset from the current date for sunrise/sunset parsing.
316+
today (bool, optional): If `True`, forces the result to have the same date as the `now` datetime. `False` is
317+
effectively equivalent to `next`. The default value is `None`, which doesn't try to coerce the output at
318+
all. This results in slightly different date results for different input types. For example, a time string
319+
will be given the same date as the one in the `now` datetime, but a sun event string will be the datetime
320+
of the next one.
321+
offset (timedelta, optional): An optional offset to apply to the resulting datetime. This is separate from the
322+
offset that may be included in an input string, and the `days_offset` parameter.
323+
days_offset (int, optional): Number of days to offset from the current date for sunrise/sunset parsing. If this
324+
is negative, this will unset the `today` argument, which allows the result to be in the past.
317325
aware (bool, optional): If `False`, the resulting datetime will be naive (without timezone). Defaults to
318326
`True`.
319327
@@ -353,9 +361,12 @@ def parse_datetime(
353361
case _:
354362
raise NotImplementedError(f"Unsupported input type: {type(input_)}")
355363

356-
if result.tzinfo is None and aware:
357-
# Just adds the timezone without changing the time values
358-
result = result.replace(tzinfo=now.tzinfo)
364+
if aware:
365+
if result.tzinfo is None:
366+
# Just adds the timezone without changing the time values
367+
result = result.replace(tzinfo=now.tzinfo)
368+
else:
369+
result = result.astimezone(now.tzinfo)
359370

360371
# The the days offset is negative, the result can't be forced to today, so set today to False
361372
if days_offset < 0:

0 commit comments

Comments
 (0)