MCPcopy Index your code
hub / github.com/THUDM/AgentBench / parse_timestamp

Function parse_timestamp

src/analysis.py:266–298  ·  view source on GitHub ↗
(time_str: str)

Source from the content-addressed store, hash-verified

264
265
266def parse_timestamp(time_str: str) -> float:
267 # is a int or float
268 try:
269 return float(time_str)
270 except:
271 pass
272 # is a datetime
273 try:
274 return datetime.datetime.strptime(time_str, "%Y-%m-%d %H:%M:%S").timestamp()
275 except:
276 pass
277 try:
278 return datetime.datetime.strptime(time_str, "%Y-%m-%d").timestamp()
279 except:
280 pass
281 try:
282 return datetime.datetime.strptime(time_str, "%Y-%m").timestamp()
283 except:
284 pass
285 # is a time delta (e.g. 1d, 1h, 1m, 1s)
286 num = float(re.findall(r"[\d\.]+", time_str)[0])
287 unit = re.findall(r"[a-zA-Z]+", time_str)[0]
288 if unit == "d":
289 delta = num * 24 * 60 * 60
290 elif unit == "h":
291 delta = num * 60 * 60
292 elif unit == "m":
293 delta = num * 60
294 elif unit == "s":
295 delta = num
296 else:
297 raise Exception("Unknown time unit")
298 return time.time() - delta
299
300
301def main(args):

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected