-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Update to use timespan #20233
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
Merged
Merged
Update to use timespan #20233
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f6049d5
Update to use timespan
rakshith91 e8fedd6
lint
rakshith91 4dde404
lint
rakshith91 cc2b73a
lint + test
rakshith91 286fe9f
Update test_logs_client.py
f96188a
comments
rakshith91 179b556
improve message
rakshith91 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ | |
| # Licensed under the MIT License. See License.txt in the project root for | ||
| # license information. | ||
| # -------------------------------------------------------------------------- | ||
| from datetime import datetime, timedelta | ||
| from typing import TYPE_CHECKING | ||
| from msrest import Serializer | ||
| from azure.core.exceptions import HttpResponseError | ||
|
|
@@ -49,26 +50,34 @@ def order_results(request_order, responses): | |
| ordered = [mapping[id] for id in request_order] | ||
| return ordered | ||
|
|
||
| def construct_iso8601(start=None, end=None, duration=None): | ||
| if duration is not None: | ||
| duration = 'PT{}S'.format(duration.total_seconds()) | ||
| def construct_iso8601(timespan=None): | ||
| if not timespan: | ||
| return None | ||
| try: | ||
| start, end, duration = None, None, None | ||
| if isinstance(timespan[1], datetime): # we treat thi as start_time, end_time | ||
| start, end = timespan[0], timespan[1] | ||
| elif isinstance(timespan[1], timedelta): # we treat this as start_time, duration | ||
| start, duration = timespan[0], timespan[1] | ||
| else: | ||
| raise ValueError('Tuple must be a start datetime with a timedelta or an end datetime.') | ||
| except TypeError: | ||
| duration = timespan # it means only duration (timedelta) is provideds | ||
| if duration: | ||
| try: | ||
| duration = 'PT{}S'.format(duration.total_seconds()) | ||
| except AttributeError: | ||
| raise ValueError('timespan must be a timedelta or a tuple.') | ||
| iso_str = None | ||
| if start is not None: | ||
| start = Serializer.serialize_iso(start) | ||
| if end and duration: | ||
| raise ValueError("start_time can only be provided with duration or end_time, but not both.") | ||
| if end is not None: | ||
| end = Serializer.serialize_iso(end) | ||
| iso_str = start + '/' + end | ||
| elif duration is not None: | ||
| iso_str = start + '/' + duration | ||
| else: | ||
| raise ValueError("Start time must be provided along with duration or end time.") | ||
| elif end is not None: | ||
| if not duration: | ||
| raise ValueError("End time must be provided along with duration or start time.") | ||
| end = Serializer.serialize_iso(end) | ||
| iso_str = duration + '/' + end | ||
| else: # means that an invalid value None that is provided with start_time | ||
| raise ValueError("Duration or end_time cannot be None when provided with start_time.") | ||
| else: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, in which case will enter here?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in case timespan is a timedelta and no start is provided |
||
| iso_str = duration | ||
| return iso_str | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Could you add some comments to describe the situation?
e.g. if isinstance(timespan[1], datetime): # if timespan is tuple[datetime, datetime], we treat it as [start time, end time].