-
Notifications
You must be signed in to change notification settings - Fork 446
Initial implementation to address #102 and provide datetime objects #103
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
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c86992b
Initial implementation to address #102 and provide datetime objects
b2e9e08
Fix pep8 failures
68fa442
Remove setters and move to doing the conversion during parsing
ff23f08
removing attempt to import pytz
db0dac1
fixing yet another pep8 failure
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
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 |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| import datetime | ||
|
|
||
|
|
||
| # This code below is from the python documentation for tzinfo: https://docs.python.org/2.3/lib/datetime-tzinfo.html | ||
| ZERO = datetime.timedelta(0) | ||
| HOUR = datetime.timedelta(hours=1) | ||
|
|
||
| # A UTC class. | ||
|
|
||
|
|
||
| class UTC(datetime.tzinfo): | ||
| """UTC""" | ||
|
|
||
| def utcoffset(self, dt): | ||
| return ZERO | ||
|
|
||
| def tzname(self, dt): | ||
| return "UTC" | ||
|
|
||
| def dst(self, dt): | ||
| return ZERO | ||
|
|
||
|
|
||
| utc = UTC() | ||
|
|
||
| TABLEAU_DATE_FORMAT = "%Y-%m-%dT%H:%M:%SZ" | ||
|
|
||
|
|
||
| def parse_datetime(date): | ||
| if date is None: | ||
| return None | ||
|
|
||
| return datetime.datetime.strptime(date, TABLEAU_DATE_FORMAT).replace(tzinfo=utc) | ||
|
|
||
|
|
||
| def format_datetime(date): | ||
| return date.astimezone(tz=utc).strftime(TABLEAU_DATE_FORMAT) |
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 |
|---|---|---|
| @@ -1,5 +1,12 @@ | ||
| import datetime | ||
| import re | ||
| from functools import wraps | ||
| from ..datetime_helpers import parse_datetime | ||
| try: | ||
| basestring | ||
| except NameError: | ||
| # In case we are in python 3 the string check is different | ||
| basestring = str | ||
|
|
||
|
|
||
| def property_is_enum(enum_type): | ||
|
|
@@ -99,3 +106,25 @@ def validate_regex_decorator(self, value): | |
| return func(self, value) | ||
| return validate_regex_decorator | ||
| return wrapper | ||
|
|
||
|
|
||
| def property_is_datetime(func): | ||
|
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. Even though this isn't being used right now, I left it in. If you feel like I should delete it, I can.
Contributor
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. I am happy to leave this |
||
| """ Takes the following datetime format and turns it into a datetime object: | ||
|
|
||
| 2016-08-18T18:25:36Z | ||
|
|
||
| Because we return everything with Z as the timezone, we assume everything is in UTC and create | ||
| a timezone aware datetime. | ||
| """ | ||
|
|
||
| @wraps(func) | ||
| def wrapper(self, value): | ||
| if isinstance(value, datetime.datetime): | ||
| return func(self, value) | ||
| if not isinstance(value, basestring): | ||
| raise ValueError("Cannot convert {} into a datetime, cannot update {}".format(value.__class__.__name__, | ||
| func.__name__)) | ||
|
|
||
| dt = parse_datetime(value) | ||
| return func(self, dt) | ||
| return wrapper | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| import datetime | ||
| import unittest | ||
| import tableauserverclient as TSC | ||
|
|
||
|
|
||
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.
Why are you doing this?
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.
A recent update to pycodestyle (since we always install the latest in the travis run) is picking up files that are outside of our control (libraries installed), so now we want to limit to specifically code we have control over.