Create only one instance of each distinct datetime
(seconds)
| 29 | |
| 30 | |
| 31 | def memorized_datetime(seconds): |
| 32 | '''Create only one instance of each distinct datetime''' |
| 33 | try: |
| 34 | return _datetime_cache[seconds] |
| 35 | except KeyError: |
| 36 | # NB. We can't just do datetime.utcfromtimestamp(seconds) as this |
| 37 | # fails with negative values under Windows (Bug #90096) |
| 38 | dt = _epoch + timedelta(seconds=seconds) |
| 39 | _datetime_cache[seconds] = dt |
| 40 | return dt |
| 41 | |
| 42 | _ttinfo_cache = {} |
| 43 |