Skip to content

Commit 4025535

Browse files
FedericoQuarinAuDuarte
authored andcommitted
feat: add getValue to TimePickerPw
1 parent 27f7235 commit 4025535

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/main/java/in/virit/mopo/TimePickerPw.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
import com.microsoft.playwright.Locator;
44
import com.microsoft.playwright.Page;
5+
import java.time.LocalDate;
56
import java.time.LocalTime;
67
import java.time.format.DateTimeFormatter;
7-
8+
import java.util.Locale;
89
/**
910
* A helper class to work with vaadin-time-picker component.
1011
*/
@@ -38,7 +39,7 @@ public TimePickerPw(Page page, String id) {
3839
*/
3940
public void setValue(LocalTime value) {
4041
String formattedTime = (timeFormat == null ? value.toString()
41-
: DateTimeFormatter.ofPattern(timeFormat).format(value));
42+
: DateTimeFormatter.ofPattern(timeFormat, Locale.ROOT).format(value));
4243

4344
root.fill(formattedTime);
4445
root.press("Enter");
@@ -48,6 +49,20 @@ public void setValue(LocalTime value) {
4849
options.setState(options.state.HIDDEN);
4950
page.waitForSelector("vaadin-time-picker-overlay", options);
5051
}
52+
53+
/**
54+
* Returns the value from the client side and parses it as
55+
* {@link LocalDate} using a {@link DateTimeFormatter}.
56+
*
57+
* @return the current value of the field
58+
*/
59+
public LocalTime getValue() {
60+
String value = root.inputValue();
61+
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(timeFormat, Locale.ROOT);
62+
63+
return timeFormat == null ? LocalTime.parse(value)
64+
: LocalTime.parse(value, formatter);
65+
}
5166

5267
/**
5368
* Sets the format to be used when setting the time value.

0 commit comments

Comments
 (0)