Make UTC transitions API public
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
| pytz |
Medium
|
Unassigned |
Bug Description
I just had to rewrite a script that generates .ics files from PHP to Python. PHP provides a tz->getTransiti
Changed in pytz: | |
status: | New → Incomplete |
Stuart Bishop (stub) wrote : | #1 |
Stuart Bishop (stub) wrote : | #2 |
I expect:
def getTransitions(
'''
Return a list of daylight savings transition times that occur during the given period, as a list of (utc_datetime, offset) tuples. offset is minutes offset from UTC.
min and max are datetime instances. If no timezone information is attached, they are assumed to be UTC.
'''
Eitan (eitan-mosenkis) wrote : | #3 |
Looks pretty good. I made a few changes:
1. replaced camelCase getTransitions with lowercase transitions to match the style of the rest of the public API.
2. return 'sequence' instead of 'list' to allow it to be implemented as a generator if you so choose
3. return timedeltas instead of just a number of minutes
4. attempted to tersely make clear that it always returns at least one transition, starting from the latest transition that is <= min.
def transitions(self, min, max):
'''
Return a sequnce of one or more daylight savings transitions that cover the given period, as (utc_datetime, offset) tuples. offset is a datetime.timedelta from UTC.
min and max are datetime instances. If no timezone information is attached, they are assumed to be UTC.
The utc_datetime of the first transition returned will be less than or equal to min such that the first offset is equal to utcoffset(min). The utc_datetime of the last transition returned will be less than or equal to max such that the last offset is equal to utcoffset(max).
If no transitions occur between min and max inclusive, a sequence will be returned containing the last transition that occurs before min.
'''
Changed in pytz: | |
status: | Incomplete → Triaged |
importance: | Undecided → Medium |
Jonathan Reed (jdreed) wrote : | #4 |
I'd also love to see this feature, for a similar reason. I'm dealing with scheduling data, and while the actual values are stored in UTC, I still need to display a big loud warning to the user when there's a transition that occurs in a given period. Right now I'm abusing the private attribute, but a public API would be awesome.
The only difference between what's proposed here and what I need is that I'd like the function to return None or something, if indeed there is no transition between min and max inclusive, but I suppose comparing the returned value to min is not difficult.
Mike (mike-bd) wrote : | #5 |
+1
I'll need an example of the expected Python API.
What does tz.getTransitio ns(min, max) return?
What are min and max?