| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
|
Thanks for working on this! So my proposal was implementing something like this: >>> parse("00:00", defaulttz=tzutc())And it seems that this would be the proposed implementation from this PR a6aae67: >>> from dateutil.utils import default_tzinfo
>>> default_tzinfo(parse("0:00"), tzutc())I guess that works, and if people get their date objects from somewhere other than parse, it is indeed more general. But it is less discoverable for people looking at the parse documentation. Would it make sense to put an example there? |
Sorry, something went wrong.
|
I guess a practical example would be something that takes two strings to be parsed from some list of meeting times, in which one string has timezone info, and the other doesn't. Both could be parsed, with a default of the NYC timezone provided, and the results printed out. |
Sorry, something went wrong.
| """ | ||
|
|
||
| dt = datetime.now(tzinfo) | ||
| return datetime.combine(dt.date(), time(0, tzinfo=tzinfo)) |
There was a problem hiding this comment.
+1 for today(tzinfo), but I'm very wary of implementing behavior that differs from same-named stdlib behavior. btw:
>>> tz = pytz.timezone('US/Pacific')
>>> pd.Timestamp.today(tz)
Timestamp('2017-10-14 17:19:04.081315-0700', tz='US/Pacific')
Sorry, something went wrong.
There was a problem hiding this comment.
@jbrockmendel Sorry, I miscalculated what would be shown in the diff here, this discussion should be taking place on #474, so I've responded here
Sorry, something went wrong.
| if dt.tzinfo is not None: | ||
| return dt | ||
| else: | ||
| return dt.replace(tzinfo=tzinfo) |
There was a problem hiding this comment.
lgtm
Sorry, something went wrong.
| from dateutil import utils | ||
| from dateutil.utils import within_delta | ||
|
|
||
| from freezegun import freeze_time |
There was a problem hiding this comment.
+1. Now if I can figure out #463 to mock tzlocal, we'll make a mockery of this whole endeavor.
Sorry, something went wrong.
|
@nealmcb Yes, that's not a bad idea. After we settle on the final interface here, I can add it in to the documentation for the parser. |
Sorry, something went wrong.
|
@nealmcb Added an example in the default_tzinfo documentation. Look good? |
Sorry, something went wrong.
|
LGTM |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
As a partial and possibly more general fix to #94, this adds a tzinfo to any datetime that doesn't have one, and otherwise leaves it alone.