From d557b7b2566ecf4535329810c59b53156c2f476b Mon Sep 17 00:00:00 2001 From: Yury Semikhatsky Date: Mon, 24 Jun 2024 12:24:13 -0700 Subject: [PATCH] cherry-pick(#31420): docs(java): correctly parse time (#31422) --- docs/src/api/class-clock.md | 11 ++++++----- docs/src/clock.md | 10 ++++++---- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/docs/src/api/class-clock.md b/docs/src/api/class-clock.md index 1a87cdffa0cc1..6f70e72a02f00 100644 --- a/docs/src/api/class-clock.md +++ b/docs/src/api/class-clock.md @@ -136,7 +136,8 @@ page.clock.pause_at("2020-02-02") ``` ```java -page.clock().pauseAt(Instant.parse("2020-02-02")); +SimpleDateFormat format = new SimpleDateFormat("yyy-MM-dd"); +page.clock().pauseAt(format.parse("2020-02-02")); page.clock().pauseAt("2020-02-02"); ``` @@ -182,8 +183,8 @@ page.clock.set_fixed_time("2020-02-02") ``` ```java -page.clock().setFixedTime(Instant.now()); -page.clock().setFixedTime(Instant.parse("2020-02-02")); +page.clock().setFixedTime(new Date()); +page.clock().setFixedTime(new SimpleDateFormat("yyy-MM-dd").parse("2020-02-02")); page.clock().setFixedTime("2020-02-02"); ``` @@ -225,8 +226,8 @@ page.clock.set_system_time("2020-02-02") ``` ```java -page.clock().setSystemTime(Instant.now()); -page.clock().setSystemTime(Instant.parse("2020-02-02")); +page.clock().setSystemTime(new Date()); +page.clock().setSystemTime(new SimpleDateFormat("yyy-MM-dd").parse("2020-02-02")); page.clock().setSystemTime("2020-02-02"); ``` diff --git a/docs/src/clock.md b/docs/src/clock.md index b89dfd93d6cf1..86d0ad9a10be5 100644 --- a/docs/src/clock.md +++ b/docs/src/clock.md @@ -118,13 +118,14 @@ expect(page.get_by_test_id("current-time")).to_have_text("2/2/2024, 10:30:00 AM" ```java // Initialize clock with some time before the test time and let the page load // naturally. `Date.now` will progress as the timers fire. -page.clock().install(new Clock.InstallOptions().setTime(Instant.parse("2024-02-02T08:00:00"))); +SimpleDateFormat format = new SimpleDateFormat("yyy-MM-dd'T'HH:mm:ss"); +page.clock().install(new Clock.InstallOptions().setTime(format.parse("2024-02-02T08:00:00"))); page.navigate("http://localhost:3333"); Locator locator = page.getByTestId("current-time"); // Pretend that the user closed the laptop lid and opened it again at 10am. // Pause the time once reached that point. -page.clock().pauseAt(Instant.parse("2024-02-02T10:00:00")); +page.clock().pauseAt(format.parse("2024-02-02T10:00:00")); // Assert the page state. assertThat(locator).hasText("2/2/2024, 10:00:00 AM"); @@ -315,15 +316,16 @@ expect(locator).to_have_text("2/2/2024, 10:00:02 AM") ``` ```java +SimpleDateFormat format = new SimpleDateFormat("yyy-MM-dd'T'HH:mm:ss"); // Initialize clock with a specific time, let the page load naturally. page.clock().install(new Clock.InstallOptions() - .setTime(Instant.parse("2024-02-02T08:00:00"))); + .setTime(format.parse("2024-02-02T08:00:00"))); page.navigate("http://localhost:3333"); Locator locator = page.getByTestId("current-time"); // Pause the time flow, stop the timers, you now have manual control // over the page time. -page.clock().pauseAt(Instant.parse("2024-02-02T10:00:00")); +page.clock().pauseAt(format.parse("2024-02-02T10:00:00")); assertThat(locator).hasText("2/2/2024, 10:00:00 AM"); // Tick through time manually, firing all timers in the process.