Hi all,
We recently added the ability to pass a timezone string to get_datetime(). This is mostly as a convenience feature to save the boilerplate of having to call tz_convert('US/Eastern') when you want to be thinking in market hours instead of UTC, which is the default timezone returned by get_datetime() with no parameters.
One issue that was brought up by a user recently is how get_datetime should handle a timezone parameter when run in daily mode. Right now, get_datetime() in daily mode returns midnight UTC of the date being processed by the algorithm. This is in alignment with midnight UTC as the canonical representation of a day in much of the numpy/scipy ecosystem (See, for instance, pandas.tseries.tools.normalize_date.) If you pass a timezone string like "US/Eastern" to get_datetime here, you end up getting the equivalent of doing get_datetime().tz_convert("US/Eastern"), which resolves to 7 or 8 PM the previous day, depending on daylight savings. This is particularly confusing if you're immediately calling .date() on the output, because you get the unintuitive result that
get_datetime().date() != get_datetime('US/Eastern').date()
As I see it, there are three sane things we could be doing to handle this case better.
- Continue with the current semantics, but show an appropriate warning if a timezone is passed in daily mode.
- Ignore the timezone parameter in daily mode (possibly also showing a warning that this is happening.)
- Throw an exception if a timezone parameter is passed in daily mode.
Of these three, I'm most inclined to go with the second option, but I'd like to get some feedback from the community about what your expectations would be here.
Thanks,
-Scott