MCPcopy Index your code
hub / github.com/python/cpython / _str2time

Function _str2time

Lib/http/cookiejar.py:150–204  ·  view source on GitHub ↗
(day, mon, yr, hr, min, sec, tz)

Source from the content-addressed store, hash-verified

148 return offset
149
150def _str2time(day, mon, yr, hr, min, sec, tz):
151 yr = int(yr)
152 if yr > datetime.MAXYEAR:
153 return None
154
155 # translate month name to number
156 # month numbers start with 1 (January)
157 try:
158 mon = MONTHS_LOWER.index(mon.lower())+1
159 except ValueError:
160 # maybe it's already a number
161 try:
162 imon = int(mon)
163 except ValueError:
164 return None
165 if 1 <= imon <= 12:
166 mon = imon
167 else:
168 return None
169
170 # make sure clock elements are defined
171 if hr is None: hr = 0
172 if min is None: min = 0
173 if sec is None: sec = 0
174
175 day = int(day)
176 hr = int(hr)
177 min = int(min)
178 sec = int(sec)
179
180 if yr < 1000:
181 # find "obvious" year
182 cur_yr = time.localtime(time.time())[0]
183 m = cur_yr % 100
184 tmp = yr
185 yr = yr + cur_yr - m
186 m = m - tmp
187 if abs(m) > 50:
188 if m > 0: yr = yr + 100
189 else: yr = yr - 100
190
191 # convert UTC time tuple to seconds since epoch (not timezone-adjusted)
192 t = _timegm((yr, mon, day, hr, min, sec, tz))
193
194 if t is not None:
195 # adjust time using timezone string, to get absolute time since epoch
196 if tz is None:
197 tz = "UTC"
198 tz = tz.upper()
199 offset = offset_from_tz_string(tz)
200 if offset is None:
201 return None
202 t = t - offset
203
204 return t
205
206STRICT_DATE_RE = re.compile(
207 r"^[SMTWF][a-z][a-z], (\d\d) ([JFMASOND][a-z][a-z]) "

Callers 2

http2timeFunction · 0.85
iso2timeFunction · 0.85

Calls 7

absFunction · 0.85
_timegmFunction · 0.85
offset_from_tz_stringFunction · 0.85
indexMethod · 0.45
lowerMethod · 0.45
timeMethod · 0.45
upperMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…