Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat/timezone_config #180

Closed

Conversation

JarbasAl
Copy link
Collaborator

@JarbasAl JarbasAl commented Mar 29, 2021

  • all datetime extractors now default to now_local for anchorDate
  • all localized_functions now inject a tzinfo in all tz-naive datetime objects passed as arguments
  • default tz-info can be set with lingua_franca.time.set_default_tz
  • tz-info injection can be enabled/disable in lingua_franca.config(default: enabled)

in what relates to mycroft-core:

  • core should set the default timezone when setting language at intent step
  • core should expect LF to always return tz-aware objects (in user configured timezone from .conf)

@JarbasAl JarbasAl added bug Something isn't working multi_lang relates to several languages labels Mar 29, 2021
@devs-mycroft devs-mycroft added the CLA: Yes Contributor License Agreement exists (see https://github.com/MycroftAI/contributors) label Mar 29, 2021
Copy link
Contributor

@krisgesling krisgesling left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to clarify the points in the PR description as that will likely change my inline comments below.

  • all datetime extractors now default to now_local for anchorDate

This to me is the bug and what we're really trying to fix.

all localized_functions now inject a tzinfo in all tz-naive datetime objects passed as arguments

This seems to be a feature made possible by the default tz config however I'm unclear as to how you are suggesting it work. Is it 1, 2, both, or something else?

  1. LF users can pass in TZ naive datetime objects and they will have default tz info added.
  2. LF users can choose to have all datetime objects converted to the default tz.

A possible issue arises in nice_duration. If I pass in 1 tz aware and 1 tz naive datetime, do I expect them both to be treated with the tzinfo of the tz aware datetime, or with my default tz info? I can see people making strong arguments in both directions, which to me adds weight to requiring that all datetime objects passed as parameters must be tz aware.

Enforcing the use of tz aware datetime objects reduces the chance of perceived bugs by warning downstream developers if they are using tz naive datetime objects. It also reduces the amount of datetime modifications we are doing.

tz-info injection can be enabled/disable in lingua_franca.config(default: enabled)

For this I assume number 2 above, else why would it be disabled?

default tz-info can be set with lingua_franca.time.set_default_tz

Wondering if this should get moved to lingua_franca.config.set_default_tz

in what relates to mycroft-core:
core should set the default timezone when setting language at intent step
core should expect LF to always return tz-aware objects (in user configured timezone from .conf)

If the intention was only to fix the bug in extract_datetime then we could add a tz parameter to that method and have mycroft-core wrap it providing the backwards compatibility for all Skills effectively:
extract_datetime(text, anchorDate=None, default_tz=now_local(), default_time=None)

I don't think we'd want to have all datetimes returned in local tz by default. However it seems we're only talking about extract_datetime that actually returns a datetime anyway right? In which case I would expect it be returned in the timezone of anchorDate or the default_tz if no anchorDate is provided.

lingua_franca/time.py Outdated Show resolved Hide resolved
lingua_franca/time.py Show resolved Hide resolved
lingua_franca/internal.py Outdated Show resolved Hide resolved
lingua_franca/internal.py Outdated Show resolved Hide resolved
test/test_parse.py Outdated Show resolved Hide resolved
lingua_franca/config.py Show resolved Hide resolved
lingua_franca/lang/parse_da.py Outdated Show resolved Hide resolved


def to_system(dt):
"""Convert a datetime to the system's local timezone
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this method had not been migrated from mycroft-core, added in order to deprecate the mycroft side function as described in #182 (comment)

lingua_franca/config.py Show resolved Hide resolved
lingua_franca/internal.py Outdated Show resolved Hide resolved
lingua_franca/lang/parse_ca.py Show resolved Hide resolved
lingua_franca/lang/parse_cs.py Show resolved Hide resolved
lingua_franca/lang/parse_nl.py Show resolved Hide resolved
lingua_franca/time.py Show resolved Hide resolved
@ChanceNCounter
Copy link
Contributor

@chrisveilleux I do see value in implementing this directly in lingua_franca.config, but I'm hesitant to extend the current config.py. #185 is currently roadmapped for the next "major" version (we're using minor numbers cuz "alpha") and it implements a proper config API.

The current config only contains one value, and it's just a top-level variable. The file wouldn't exist at all, except Neon and Chatterbox needed config.load_langs_on_demand or they couldn't upgrade. There was no reason to deny them that in the 0.3.0 upgrade, but the consequence is now there's that ugly thing.

As I see it, there are two options here:

One way or another it's something that implementations will have to change again in the future, but that's why it's v0.x. The difference is just how disruptive the change will be. If we go with the setter function, we can deprecate that function, and take as long as we want to do so, leaving implementations plenty of time to catch up. If we go with config.py, implementations will have to change it just to make the LF0.4 --> LF0.5 upgrade.

@ChanceNCounter ChanceNCounter linked an issue May 9, 2021 that may be closed by this pull request
@JarbasAl JarbasAl closed this May 9, 2021
@JarbasAl JarbasAl deleted the feat/timezone_config branch May 9, 2021 17:28
@JarbasAl JarbasAl restored the feat/timezone_config branch May 9, 2021 17:33
@JarbasAl JarbasAl reopened this May 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working CLA: Yes Contributor License Agreement exists (see https://github.com/MycroftAI/contributors) multi_lang relates to several languages
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants