Create only one instance of each distinct timedelta
(seconds)
| 16 | |
| 17 | |
| 18 | def memorized_timedelta(seconds): |
| 19 | '''Create only one instance of each distinct timedelta''' |
| 20 | try: |
| 21 | return _timedelta_cache[seconds] |
| 22 | except KeyError: |
| 23 | delta = timedelta(seconds=seconds) |
| 24 | _timedelta_cache[seconds] = delta |
| 25 | return delta |
| 26 | |
| 27 | _epoch = datetime.utcfromtimestamp(0) |
| 28 | _datetime_cache = {0: _epoch} |
no outgoing calls
no test coverage detected