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

Duration from str does not account for negative sign #349

Closed
ChristopherRabotin opened this issue Dec 17, 2024 · 0 comments · Fixed by #350
Closed

Duration from str does not account for negative sign #349

ChristopherRabotin opened this issue Dec 17, 2024 · 0 comments · Fixed by #350

Comments

@ChristopherRabotin
Copy link
Member

ChristopherRabotin commented Dec 17, 2024

When durations are represented as string, they may be negative. As a user, I expect these to be valid when passed to the from_str function (or to the initializer in Python). However, that leads to an InvalidTimezone error.

For example, from python:

>>> Duration("-1 h 6 s")
---------------------------------------------------------------------------
HifitimeError                             Traceback (most recent call last)
Cell In[12], line 1
----> 1 Duration("-1 h 6 s")

HifitimeError: InvalidTimezone, invalid timezone format [+/-]HH:MM

This issue should also export the neg function to Python. Until then, the only way to negate a duration in Python is by the unnecessarily complicated: Duration.ZERO() - Duration("1 h 6 min") or Unit.Second*(-Duration("1 h 6 min").to_seconds()).

Finally, the from_str function should also support the UTF8 characters used in the formatting, like the micro:

In [32]: value_str = "-54 ms 102 μs 616 ns"

In [33]: Duration(value_str[1:])
---------------------------------------------------------------------------
HifitimeError                             Traceback (most recent call last)
Cell In[33], line 1
----> 1 Duration(value_str[1:])

HifitimeError: UnknownOrMissingUnit, unknown unit
ChristopherRabotin added a commit that referenced this issue Dec 23, 2024
…egative

Fix parsing of microseconds with UTF8 symbol and parsing negative durations
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant