Skip to content

Commit d557b7b

Browse files
authored
cherry-pick(#31420): docs(java): correctly parse time (#31422)
1 parent 1368bca commit d557b7b

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

docs/src/api/class-clock.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,8 @@ page.clock.pause_at("2020-02-02")
136136
```
137137

138138
```java
139-
page.clock().pauseAt(Instant.parse("2020-02-02"));
139+
SimpleDateFormat format = new SimpleDateFormat("yyy-MM-dd");
140+
page.clock().pauseAt(format.parse("2020-02-02"));
140141
page.clock().pauseAt("2020-02-02");
141142
```
142143

@@ -182,8 +183,8 @@ page.clock.set_fixed_time("2020-02-02")
182183
```
183184

184185
```java
185-
page.clock().setFixedTime(Instant.now());
186-
page.clock().setFixedTime(Instant.parse("2020-02-02"));
186+
page.clock().setFixedTime(new Date());
187+
page.clock().setFixedTime(new SimpleDateFormat("yyy-MM-dd").parse("2020-02-02"));
187188
page.clock().setFixedTime("2020-02-02");
188189
```
189190

@@ -225,8 +226,8 @@ page.clock.set_system_time("2020-02-02")
225226
```
226227

227228
```java
228-
page.clock().setSystemTime(Instant.now());
229-
page.clock().setSystemTime(Instant.parse("2020-02-02"));
229+
page.clock().setSystemTime(new Date());
230+
page.clock().setSystemTime(new SimpleDateFormat("yyy-MM-dd").parse("2020-02-02"));
230231
page.clock().setSystemTime("2020-02-02");
231232
```
232233

docs/src/clock.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,14 @@ expect(page.get_by_test_id("current-time")).to_have_text("2/2/2024, 10:30:00 AM"
118118
```java
119119
// Initialize clock with some time before the test time and let the page load
120120
// naturally. `Date.now` will progress as the timers fire.
121-
page.clock().install(new Clock.InstallOptions().setTime(Instant.parse("2024-02-02T08:00:00")));
121+
SimpleDateFormat format = new SimpleDateFormat("yyy-MM-dd'T'HH:mm:ss");
122+
page.clock().install(new Clock.InstallOptions().setTime(format.parse("2024-02-02T08:00:00")));
122123
page.navigate("http://localhost:3333");
123124
Locator locator = page.getByTestId("current-time");
124125

125126
// Pretend that the user closed the laptop lid and opened it again at 10am.
126127
// Pause the time once reached that point.
127-
page.clock().pauseAt(Instant.parse("2024-02-02T10:00:00"));
128+
page.clock().pauseAt(format.parse("2024-02-02T10:00:00"));
128129

129130
// Assert the page state.
130131
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")
315316
```
316317

317318
```java
319+
SimpleDateFormat format = new SimpleDateFormat("yyy-MM-dd'T'HH:mm:ss");
318320
// Initialize clock with a specific time, let the page load naturally.
319321
page.clock().install(new Clock.InstallOptions()
320-
.setTime(Instant.parse("2024-02-02T08:00:00")));
322+
.setTime(format.parse("2024-02-02T08:00:00")));
321323
page.navigate("http://localhost:3333");
322324
Locator locator = page.getByTestId("current-time");
323325

324326
// Pause the time flow, stop the timers, you now have manual control
325327
// over the page time.
326-
page.clock().pauseAt(Instant.parse("2024-02-02T10:00:00"));
328+
page.clock().pauseAt(format.parse("2024-02-02T10:00:00"));
327329
assertThat(locator).hasText("2/2/2024, 10:00:00 AM");
328330

329331
// Tick through time manually, firing all timers in the process.

0 commit comments

Comments
 (0)