MCPcopy Create free account
hub / github.com/coooodeer/parse-rust / test_datetimes

Function test_datetimes

tests/test_parse.py:456–613  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

454
455
456def test_datetimes():
457 def y(fmt, s, e, tz=None):
458 p = parse.compile(fmt)
459 r = p.parse(s)
460 assert r is not None
461 r = r.fixed[0]
462 assert r == e
463 assert tz is None or r.tzinfo == tz
464
465 utc = parse.FixedTzOffset(0, "UTC")
466 assert repr(utc) == "<FixedTzOffset UTC 0:00:00>"
467 aest = parse.FixedTzOffset(10 * 60, "+1000")
468 tz60 = parse.FixedTzOffset(60, "+01:00")
469
470 # ISO 8660 variants
471 # YYYY-MM-DD (eg 1997-07-16)
472 y("a {:ti} b", "a 1997-07-16 b", datetime(1997, 7, 16))
473
474 # YYYY-MM-DDThh:mmTZD (eg 1997-07-16T19:20+01:00)
475 y("a {:ti} b", "a 1997-07-16 19:20 b", datetime(1997, 7, 16, 19, 20, 0))
476 y("a {:ti} b", "a 1997-07-16T19:20 b", datetime(1997, 7, 16, 19, 20, 0))
477 y(
478 "a {:ti} b",
479 "a 1997-07-16T19:20Z b",
480 datetime(1997, 7, 16, 19, 20, tzinfo=utc),
481 )
482 y(
483 "a {:ti} b",
484 "a 1997-07-16T19:20+0100 b",
485 datetime(1997, 7, 16, 19, 20, tzinfo=tz60),
486 )
487 y(
488 "a {:ti} b",
489 "a 1997-07-16T19:20+01:00 b",
490 datetime(1997, 7, 16, 19, 20, tzinfo=tz60),
491 )
492 y(
493 "a {:ti} b",
494 "a 1997-07-16T19:20 +01:00 b",
495 datetime(1997, 7, 16, 19, 20, tzinfo=tz60),
496 )
497
498 # YYYY-MM-DDThh:mm:ssTZD (eg 1997-07-16T19:20:30+01:00)
499 y("a {:ti} b", "a 1997-07-16 19:20:30 b", datetime(1997, 7, 16, 19, 20, 30))
500 y("a {:ti} b", "a 1997-07-16T19:20:30 b", datetime(1997, 7, 16, 19, 20, 30))
501 y(
502 "a {:ti} b",
503 "a 1997-07-16T19:20:30Z b",
504 datetime(1997, 7, 16, 19, 20, 30, tzinfo=utc),
505 )
506 y(
507 "a {:ti} b",
508 "a 1997-07-16T19:20:30+01:00 b",
509 datetime(1997, 7, 16, 19, 20, 30, tzinfo=tz60),
510 )
511 y(
512 "a {:ti} b",
513 "a 1997-07-16T19:20:30 +01:00 b",

Callers

nothing calls this directly

Calls 1

yFunction · 0.85

Tested by

no test coverage detected