Returns time in seconds since epoch of time represented by a string. Return value is an integer. None is returned if the format of str is unrecognized, the time is outside the representable range, or the timezone string is not recognized. If the string contains no timezone, UTC is
(text)
| 230 | \s* |
| 231 | )?$""", re.X | re.ASCII) |
| 232 | def http2time(text): |
| 233 | """Returns time in seconds since epoch of time represented by a string. |
| 234 | |
| 235 | Return value is an integer. |
| 236 | |
| 237 | None is returned if the format of str is unrecognized, the time is outside |
| 238 | the representable range, or the timezone string is not recognized. If the |
| 239 | string contains no timezone, UTC is assumed. |
| 240 | |
| 241 | The timezone in the string may be numerical (like "-0800" or "+0100") or a |
| 242 | string timezone (like "UTC", "GMT", "BST" or "EST"). Currently, only the |
| 243 | timezone strings equivalent to UTC (zero offset) are known to the function. |
| 244 | |
| 245 | The function loosely parses the following formats: |
| 246 | |
| 247 | Wed, 09 Feb 1994 22:23:32 GMT -- HTTP format |
| 248 | Tuesday, 08-Feb-94 14:15:29 GMT -- old rfc850 HTTP format |
| 249 | Tuesday, 08-Feb-1994 14:15:29 GMT -- broken rfc850 HTTP format |
| 250 | 09 Feb 1994 22:23:32 GMT -- HTTP format (no weekday) |
| 251 | 08-Feb-94 14:15:29 GMT -- rfc850 format (no weekday) |
| 252 | 08-Feb-1994 14:15:29 GMT -- broken rfc850 format (no weekday) |
| 253 | |
| 254 | The parser ignores leading and trailing whitespace. The time may be |
| 255 | absent. |
| 256 | |
| 257 | If the year is given with only 2 digits, the function will select the |
| 258 | century that makes the year closest to the current date. |
| 259 | |
| 260 | """ |
| 261 | # fast exit for strictly conforming string |
| 262 | m = STRICT_DATE_RE.search(text) |
| 263 | if m: |
| 264 | g = m.groups() |
| 265 | mon = MONTHS_LOWER.index(g[1].lower()) + 1 |
| 266 | tt = (int(g[2]), mon, int(g[0]), |
| 267 | int(g[3]), int(g[4]), float(g[5])) |
| 268 | return _timegm(tt) |
| 269 | |
| 270 | # No, we need some messy parsing... |
| 271 | |
| 272 | # clean up |
| 273 | text = text.lstrip() |
| 274 | text = WEEKDAY_RE.sub("", text, 1) # Useless weekday |
| 275 | |
| 276 | # tz is time zone specifier string |
| 277 | day, mon, yr, hr, min, sec, tz = [None]*7 |
| 278 | |
| 279 | # loose regexp parse |
| 280 | m = LOOSE_HTTP_DATE_RE.search(text) |
| 281 | if m is not None: |
| 282 | day, mon, yr, hr, min, sec, tz = m.groups() |
| 283 | else: |
| 284 | return None # bad format |
| 285 | |
| 286 | return _str2time(day, mon, yr, hr, min, sec, tz) |
| 287 | |
| 288 | ISO_DATE_RE = re.compile( |
| 289 | r"""^ |
searching dependent graphs…