MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / _parse_datetime

Function _parse_datetime

tools/python-3.11.9-amd64/Lib/nntplib.py:235–255  ·  view source on GitHub ↗

Parse a pair of (date, time) strings, and return a datetime object. If only the date is given, it is assumed to be date and time concatenated together (e.g. response to the DATE command).

(date_str, time_str=None)

Source from the content-addressed store, hash-verified

233 return overview
234
235def _parse_datetime(date_str, time_str=None):
236 """Parse a pair of (date, time) strings, and return a datetime object.
237 If only the date is given, it is assumed to be date and time
238 concatenated together (e.g. response to the DATE command).
239 """
240 if time_str is None:
241 time_str = date_str[-6:]
242 date_str = date_str[:-6]
243 hours = int(time_str[:2])
244 minutes = int(time_str[2:4])
245 seconds = int(time_str[4:])
246 year = int(date_str[:-4])
247 month = int(date_str[-4:-2])
248 day = int(date_str[-2:])
249 # RFC 3977 doesn't say how to interpret 2-char years. Assume that
250 # there are no dates before 1970 on Usenet.
251 if year < 70:
252 year += 2000
253 elif year < 100:
254 year += 1900
255 return datetime.datetime(year, month, day, hours, minutes, seconds)
256
257def _unparse_datetime(dt, legacy=False):
258 """Format a date or datetime object as a pair of (date, time) strings

Callers 1

dateMethod · 0.85

Calls 1

datetimeMethod · 0.80

Tested by

no test coverage detected