Skip to content

Commit

Permalink
fixing some tests....
Browse files Browse the repository at this point in the history
  • Loading branch information
JarbasAl committed Aug 14, 2023
1 parent da30857 commit 3b69894
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
7 changes: 5 additions & 2 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1205,9 +1205,12 @@ def _get_alert_dialog_data(self, alert: Alert, lang: str,
"""
expired_time = \
datetime.fromisoformat(alert.data["next_expiration_time"])
anchor = now_local()
if anchor.date() == expired_time.date(): # today, don't speak date
spoken_time = nice_time(expired_time, lang, use_24hour=use_24hour, use_ampm=True)
else:
spoken_time = nice_date_time(expired_time, lang, use_24hour=use_24hour, use_ampm=True)

spoken_time = nice_date_time(expired_time, lang,
use_24hour=use_24hour, use_ampm=True)
data = {
"name": alert.alert_name,
"time": spoken_time
Expand Down
15 changes: 8 additions & 7 deletions util/parse_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
from lingua_franca.parse import extract_datetime, extract_duration, normalize
from ovos_bus_client import Message
from ovos_utils.log import LOG
from ovos_utils.time import now_local, get_config_tz

from . import AlertPriority, Weekdays, AlertType
from .alert import Alert
Expand Down Expand Up @@ -74,7 +75,7 @@ def round_nearest_minute(alert_time: dt.datetime,
:param cutoff: minimum delta to consider rounding the alert time
:returns: datetime rounded to the nearest minute if delta exceeds cutoff
"""
if alert_time <= dt.datetime.now(dt.timezone.utc) + cutoff:
if alert_time <= now_local() + cutoff:
return alert_time
else:
new_alert_time = alert_time.replace(second=0).replace(microsecond=0)
Expand All @@ -92,7 +93,7 @@ def spoken_time_remaining(alert_time: dt.datetime,
:return: speakable duration string
"""
load_language(lang or _default_lang)
now_time = now_time or dt.datetime.now(dt.timezone.utc)
now_time = now_time or now_local()
remaining_time: dt.timedelta = alert_time - now_time

if remaining_time > dt.timedelta(weeks=1):
Expand Down Expand Up @@ -209,7 +210,7 @@ def tokenize_utterance(message: Message, utt: str = None) -> List[str]:
:param utt: Utterance string to tokenize (default to intent match utterance)
:returns: list of utterance tokens where a tag defines a token
"""
utterance = message.data.get("utterance", utt).lower()
utterance = message.data.get("utterance", utt or "").lower()
tags = message.data.get("__tags__", [])
tags.sort(key=lambda tag: tag["start_token"])
extracted_words = [tag.get("match") for tag in tags]
Expand Down Expand Up @@ -308,14 +309,14 @@ def parse_repeat_from_message(message: Message,

def parse_end_condition_from_message(message: Message,
tokens: Optional[list] = None,
timezone: dt.tzinfo = dt.timezone.utc) \
timezone: dt.tzinfo = get_config_tz()) \
-> Optional[dt.datetime]:
"""
Parses an end condition from the utterance. If tokens are provided, handled
tokens are removed.
:param message: Message associated with intent match
:param tokens: optional tokens parsed from message by `tokenize_utterances`
:param timezone: timezone of request, defaults to utc
:param timezone: timezone of request, defaults to config tz
:returns: extracted datetime of end condition, else None
"""
tokens = tokens or tokenize_utterance(message)
Expand Down Expand Up @@ -349,14 +350,14 @@ def parse_end_condition_from_message(message: Message,

def parse_alert_time_from_message(message: Message,
tokens: Optional[list] = None,
timezone: dt.tzinfo = dt.timezone.utc,
timezone: dt.tzinfo = get_config_tz(),
anchor_time: dt.datetime = None) -> \
Optional[dt.datetime]:
"""
Parse a requested alert time from the request utterance
:param message: Message associated with intent match
:param tokens: optional tokens parsed from message by `tokenize_utterances`
:param timezone: timezone of request, defaults to utc
:param timezone: timezone of request, defaults to config tz
:returns: Parsed datetime for the alert or None if no time is extracted
"""
anchor_time = anchor_time or dt.datetime.now(timezone)
Expand Down

0 comments on commit 3b69894

Please sign in to comment.