| Total Complexity | 3 |
| Total Lines | 27 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | # -*- coding: utf-8 -*- |
||
| 2 | """ |
||
| 3 | Extra tools for value parsing |
||
| 4 | """ |
||
| 5 | from datetime import datetime |
||
| 6 | |||
| 7 | |||
| 8 | def timestamp_to_epoch_time(rfc1123_date=''): |
||
| 9 | """ |
||
| 10 | literal date time string (use in DAV:getlastmodified) to Epoch time |
||
| 11 | |||
| 12 | No longer, Only rfc1123-date productions are legal as values for DAV:getlastmodified |
||
| 13 | However, the value may be broken or invalid. |
||
| 14 | |||
| 15 | Args: |
||
| 16 | rfc1123_date (str): rfc1123-date (defined in RFC2616) |
||
| 17 | Return: |
||
| 18 | int or None : Epoch time, if date string value is invalid return None |
||
| 19 | """ |
||
| 20 | try: |
||
| 21 | epoch_time = datetime.strptime( |
||
| 22 | rfc1123_date, '%a, %d %b %Y %H:%M:%S GMT').timestamp() |
||
| 23 | except ValueError: |
||
| 24 | return |
||
| 25 | else: |
||
| 26 | return int(epoch_time) |
||
| 27 |