Skip to content

Commit

Permalink
chore: fix datetime parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
mxschmitt committed Feb 26, 2024
1 parent a4d5fcc commit a67c336
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion playwright/_impl/_js_handle.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def parse_value(value: Any, refs: Optional[Dict[int, Any]] = None) -> Any:
return a

if "d" in value:
return datetime.fromisoformat(value["d"][:-1])
return datetime.strptime(value["d"], "%Y-%m-%dT%H:%M:%S.%fZ")

if "o" in value:
o: Dict = {}
Expand Down
6 changes: 3 additions & 3 deletions tests/async/test_evaluate.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,17 +216,17 @@ async def test_evaluate_evaluate_date(page: Page) -> None:
result = await page.evaluate(
'() => ({ date: new Date("2020-05-27T01:31:38.506Z") })'
)
assert result == {"date": datetime.fromisoformat("2020-05-27T01:31:38.506")}
assert result == {"date": datetime.fromisoformat("2020-05-27T01:31:38.506Z")}


async def test_evaluate_roundtrip_date(page: Page) -> None:
date = datetime.fromisoformat("2020-05-27T01:31:38.506")
date = datetime.fromisoformat("2020-05-27T01:31:38.506Z")
result = await page.evaluate("date => date", date)
assert result == date


async def test_evaluate_jsonvalue_date(page: Page) -> None:
date = datetime.fromisoformat("2020-05-27T01:31:38.506")
date = datetime.fromisoformat("2020-05-27T01:31:38.506Z")
result = await page.evaluate(
'() => ({ date: new Date("2020-05-27T01:31:38.506Z") })'
)
Expand Down
4 changes: 3 additions & 1 deletion tests/async/test_jshandle.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,9 @@ async def test_jshandle_json_value_work(page: Page) -> None:
async def test_jshandle_json_value_work_with_dates(page: Page) -> None:
handle = await page.evaluate_handle('() => new Date("2020-05-27T01:31:38.506Z")')
json = await handle.json_value()
assert json == datetime.fromisoformat("2020-05-27T01:31:38.506")
assert json == datetime.strptime(
"2020-05-27T01:31:38.506Z", "%Y-%m-%dT%H:%M:%S.%fZ"
)


async def test_jshandle_json_value_should_work_for_circular_object(page: Page) -> None:
Expand Down

0 comments on commit a67c336

Please sign in to comment.