Hi, I refer Olli Tietäväinen suggestion to fork one and edited it.
but the source git is marked read only, link is: https://github.com/vaadin/vaadin-time-picker-flow
And i forked at https://github.com/CNBroderick/vaadin-time-picker-flow
You can clone and install it (Which is Vaadin TimePicker).
I change 3 files in this repo.
After install, the Test method:
DateTimePicker startTimePicker = new DateTimePickerFactory().lumoSmall()
.peekTimePicker(timePicker -> timePicker.setHour24Format(true))
.value(Optional.ofNullable(getStartTime()).orElseGet(LocalDateTime::now)).get();
DateTimePicker endTimePicker = new DateTimePickerFactory().lumoSmall()
.peekTimePicker(timePicker -> timePicker.setHour12Format(true))
.value(Optional.ofNullable(getEndTime()).orElseGet(() -> LocalDateTime.now().plusYears(20))).get();
Get time picker in DateTimePicker 's method
public TimePicker getTimePicker() {
try {
Class<? extends Component> asSubclass = Class.forName(
"com.vaadin.flow.component.datetimepicker.DateTimePickerTimePicker"
).asSubclass(Component.class);
return (TimePicker) get().getElement().getChild(1).as(asSubclass);
} catch (ClassNotFoundException e) {
throw new RuntimeException("Convert error: " + e.getMessage());
}
}
- timepickerConnector.js
const getTimeFormatOptions = function () {
// calculate the format options if none done cached or step has changed
if (!cachedOptions || cachedStep !== timepicker.step) {
cachedOptions = {
** hour12: timepicker.hour12 === null || timepicker.hour12 === undefined || timepicker.hour12,**
hour: "numeric",
minute: "numeric",
second: includeSeconds() ? "numeric" : undefined,
};
cachedStep = timepicker.step;
}
return cachedOptions;
};
- GeneratedVaadinTimePicker.java add method
/**
* Is use 12 hours format
* <table>
* <tr>
* <td>Value</td>
* <td>Format</td>
* </tr>
* <tr>
* <td>true</td>
* <td>11:23:45 PM</td>
* </tr>
* <tr>
* <td>false</td>
* <td>23:23:45 PM</td>
* </tr>
*
* </table>
*
* @param hour12 use 12 hours format
*/
protected void setHour12Format(boolean hour12) {
getElement().setProperty("hour12", hour12);
}
- TimePicker.java add method
/**
* Is use 12 hours format
* <table>
* <tr>
* <td>Value</td>
* <td>Format</td>
* </tr>
* <tr>
* <td>true</td>
* <td>11:23:45 PM</td>
* </tr>
* <tr>
* <td>false</td>
* <td>23:23:45 PM</td>
* </tr>
*
* </table>
*
* @param hour12 use 12 hours format
*/
public void setHour12Format(boolean hour12) {
super.setHour12Format(hour12);
}
/**
* Is use 24 hours format
* <table>
* <tr>
* <td>Value</td>
* <td>Format</td>
* </tr>
* <tr>
* <td>true</td>
* <td>23:23:45 PM</td>
* </tr>
* <tr>
* <td>false</td>
* <td>11:23:45 PM</td>
* </tr>
*
* </table>
*
* @param hour24 use 24 hours format
*/
public void setHour24Format(boolean hour24) {
super.setHour12Format(!hour24);
}
Factory Class use Fluent Vaadin Flow: https://vaadin.com/directory/component/fluent-vaadin-flow/
18553815.zip (461 KB)