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