-
Notifications
You must be signed in to change notification settings - Fork 13
[LCHIB-612] Add a workaround for handling timezone abbreviations in d… #1043
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
Conversation
|
I understand the cause of problem. |
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This pull request addresses the issue with handling timezone abbreviations by mapping them via the tzinfos parameter in dateutil.parser.parse. Key changes include:
- Adding tests for timestamps with both known and unknown timezone abbreviations.
- Introducing a utility module (COMMON_TIMEZONES) to map common abbreviations.
- Modifying the case_event timestamp parsing to use the COMMON_TIMEZONES mapping.
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| tests/commands/record/test_case_event.py | Adds tests to verify proper handling of known and unknown timezone abbreviations. |
| launchable/utils/common_tz.py | Introduces a mapping for common timezone abbreviations using dateutil.tz.gettz. |
| launchable/commands/record/case_event.py | Updates timestamp parsing to use the tzinfos parameter with the COMMON_TIMEZONES map. |
Comments suppressed due to low confidence (1)
launchable/commands/record/case_event.py:162
- Consider adding a brief comment explaining the use of the 'timestr' and 'tzinfos' keyword parameters to clarify that this change is to support proper parsing of timezone abbreviations as per the updated dateutil behavior.
date = dateutil.parser.parse(timestr=ts, tzinfos=COMMON_TIMEZONES)
Konboi
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
But I left a question as comment
| test_path=[], duration_secs=1.0, status=CaseEvent.TEST_PASSED, timestamp=ts | ||
| ) | ||
| # Should parse to ISO format with correct offset | ||
| self.assertTrue(result["createdAt"].startswith("2024-06-23T12:34:56.789")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a question: Why did you use assertTrue and assertIn instead of assertEqual(result["createdAt"], "2024-06-23T12:34:56.789 -7:00")?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just feel like it's clearer to test them separately. The first line, assertTrue guarantees whether the time isn't changed. The second line, assertIn guarantees that the timezone is parsed correctly.
But, I don't have a strong opinion, so I'm gonna change that so that it uses assertEqual(result["createdAt"], "2024-06-23T12:34:56.789 -7:00")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| # Should output a warning to stderr | ||
| self.assertIn(UNKNOWN_TIMEZONE_WARNING, stderr.getvalue()) | ||
| # The createdAt may still start with the input timestamp, but should not have a timezone offset | ||
| self.assertTrue(result["createdAt"].startswith("2024-06-23T12:34:56.789")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is because dateutil.parser uses the default timezone if the timezone is not supported. In my local env, it's something like this: 2024-06-23T12:34:56.789000+09:00
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|



…ateutil
The dateutil package does not support timezone abbreviations like "PDT" by default.
We can reproduce the warning in the following script:
As a workaround, we need to pass the map to
tzinfosparameter.See: dateutil/dateutil#932