100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps
Java asset-managementbuildingdashboarddataplatformdevice-managementedge-computingenergyenergy-managementenergy-monitorfleet-managementfleet-telematicsiotiot-applicationiot-platformmodbusmqttmqtt-brokerota-updaterules-enginesmartcity
Implement datetime field in vaadin input (#3129)
Koen3fbd21c39d4a
diff --git a/project.gradle b/project.gradleindex 9f46f2648..a5c350f4f 100644--- a/project.gradle+++ b/project.gradle@@ -180,6 +180,13 @@ if (project == rootProject) {OR_APP_DOCROOT: "manager/build/install/manager/web"]}+ "Date Time Setup"(Application) {+ moduleName = getProject().idea.module.name + ".setup.datetime"+ envs = [+ OR_SETUP_TYPE: "datetime",+ OR_APP_DOCROOT: "manager/build/install/manager/web"+ ]+ }"Test Setup"(Application) {moduleName = getProject().idea.module.name + ".setup.integration"}diff --git a/setup/build.gradle b/setup/build.gradleindex 68a0d5503..09c58f1dd 100644--- a/setup/build.gradle+++ b/setup/build.gradle@@ -10,6 +10,7 @@ base {sourceSets {clustering+ datetimedemointegrationload1@@ -20,6 +21,7 @@ sourceSets {// dependencies declarationconfigurations {clusteringImplementation.extendsFrom(implementation)+ datetimeImplementation.extendsFrom(implementation)demoImplementation.extendsFrom(implementation)integrationImplementation.extendsFrom(implementation)load1Implementation.extendsFrom(implementation)@@ -44,6 +46,11 @@ tasks.register('clusteringJar', Jar) {from sourceSets.clustering.output}+tasks.register('datetimeJar', Jar) {+ archiveBaseName.set("openremote-datetime-${project.name}")+ from sourceSets.datetime.output+}+tasks.register('load1Jar', Jar) {archiveBaseName.set("openremote-load1-${project.name}")from sourceSets.load1.outputdiff --git a/setup/src/datetime/java/org/openremote/setup/datetime/ManagerDateTimeSetup.java b/setup/src/datetime/java/org/openremote/setup/datetime/ManagerDateTimeSetup.javanew file mode 100644index 000000000..f4616f05b--- /dev/null+++ b/setup/src/datetime/java/org/openremote/setup/datetime/ManagerDateTimeSetup.java@@ -0,0 +1,118 @@+/*+ * Copyright 2026, OpenRemote Inc.+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License as+ * published by the Free Software Foundation, either version 3 of the+ * License, or (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <https://www.gnu.org/licenses/>.+ *+ * SPDX-License-Identifier: AGPL-3.0-or-later+ */+package org.openremote.setup.datetime;++import static org.openremote.model.Constants.MASTER_REALM;++import java.time.Instant;+import java.time.temporal.ChronoUnit;+import java.util.Date;+import java.util.List;+import java.util.logging.Logger;+import org.openremote.manager.setup.ManagerSetup;+import org.openremote.model.Container;+import org.openremote.model.asset.impl.GroupAsset;+import org.openremote.model.geo.GeoJSONPoint;+import org.openremote.model.value.AttributeDescriptor;+import org.openremote.setup.datetime.model.DateTimeTestAsset;++/**+ * Creates a {@link DateTimeTestAsset} in the master realm. Every attribute except the empty one+ * gets the same instant with seconds and milliseconds, so trimming to the precision of each picker+ * shows, in the representation of its value type.+ *+ * <p>The asset is the child of a group, whose asset page lists the values as display text, and has+ * a location, so the map card shows the display text too.+ */+public class ManagerDateTimeSetup extends ManagerSetup {++ private static final Logger LOG = Logger.getLogger(ManagerDateTimeSetup.class.getName());++ /** 2026-01-02T10:30:45.123 in Europe/Amsterdam. */+ public static final Instant VALUE = Instant.parse("2026-01-02T09:30:45.123Z");++ /** Rotterdam, as longitude and latitude. */+ public static final GeoJSONPoint LOCATION =+ new GeoJSONPoint(4.4840943240837134, 51.91550228909358);++ public ManagerDateTimeSetup(Container container) {+ super(container);+ }++ @Override+ public void onStart() throws Exception {+ super.onStart();++ GroupAsset group = new GroupAsset("Date Time Test Assets", DateTimeTestAsset.class);+ group.setRealm(MASTER_REALM);+ group = assetStorageService.merge(group);++ DateTimeTestAsset asset = new DateTimeTestAsset("Date Time Test Asset");+ asset.setParent(group);+ asset.setLocation(LOCATION);++ List<AttributeDescriptor<Long>> timestamps =+ List.of(+ DateTimeTestAsset.TIMESTAMP,+ DateTimeTestAsset.LONG_AS_DATE,+ DateTimeTestAsset.MOMENT_SECONDS,+ DateTimeTestAsset.MOMENT_MILLISECONDS,+ DateTimeTestAsset.MOMENT_UNIX_MILLISECONDS,+ DateTimeTestAsset.MOMENT_UNIX_SECONDS,+ DateTimeTestAsset.MOMENT_LOCALIZED_SECONDS,+ DateTimeTestAsset.MOMENT_LITERAL_LAST_SEEN,+ DateTimeTestAsset.MOMENT_LITERAL_SENSOR,+ DateTimeTestAsset.TIMESTAMP_WITH_SECOND,+ DateTimeTestAsset.PAST,+ DateTimeTestAsset.RANGE,+ DateTimeTestAsset.READ_ONLY_TIMESTAMP);+ timestamps.forEach(+ descriptor -> asset.getAttributes().getOrCreate(descriptor).setValue(VALUE.toEpochMilli()));++ List<AttributeDescriptor<String>> isoTimestamps =+ List.of(+ DateTimeTestAsset.TIMESTAMP_ISO8601,+ DateTimeTestAsset.TIMESTAMP_ISO8601_SECONDS,+ DateTimeTestAsset.TIMESTAMP_ISO8601_MILLISECONDS);+ isoTimestamps.forEach(+ descriptor -> asset.getAttributes().getOrCreate(descriptor).setValue(VALUE.toString()));++ List<AttributeDescriptor<Date>> dates =+ List.of(+ DateTimeTestAsset.DATE_AND_TIME,+ DateTimeTestAsset.INTL_SECONDS,+ DateTimeTestAsset.INTL_FRACTIONAL_SECONDS,+ DateTimeTestAsset.INTL_TIME_STYLE_MEDIUM,+ DateTimeTestAsset.INTL_TIME_STYLE_SHORT);+ dates.forEach(+ descriptor -> asset.getAttributes().getOrCreate(descriptor).setValue(Date.from(VALUE)));++ // Future constraints need a value after now+ long future = Instant.now().plus(30, ChronoUnit.DAYS).toEpochMilli();+ asset.getAttributes().getOrCreate(DateTimeTestAsset.FUTURE).setValue(future);+ asset.getAttributes().getOrCreate(DateTimeTestAsset.FUTURE_OR_PRESENT).setValue(future);+ asset+ .getAttributes()+ .getOrCreate(DateTimeTestAsset.MIN_BETWEEN_MINUTES)+ .setValue(VALUE.plus(30, ChronoUnit.MINUTES).toEpochMilli());++ DateTimeTestAsset stored = assetStorageService.merge(asset);+ LOG.info("Created date time test asset " + stored.getId() + " in group " + group.getId());+ }+}diff --git a/setup/src/datetime/java/org/openremote/setup/datetime/SetupTasks.java b/setup/src/datetime/java/org/openremote/setup/datetime/SetupTasks.javanew file mode 100644index 000000000..424c26314--- /dev/null+++ b/setup/src/datetime/java/org/openremote/setup/datetime/SetupTasks.java@@ -0,0 +1,31 @@+/*+ * Copyright 2026, OpenRemote Inc.+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License as+ * published by the Free Software Foundation, either version 3 of the+ * License, or (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <https://www.gnu.org/licenses/>.+ *+ * SPDX-License-Identifier: AGPL-3.0-or-later+ */+package org.openremote.setup.datetime;++import java.util.List;+import org.openremote.model.Container;+import org.openremote.model.setup.Setup;++public class SetupTasks implements org.openremote.model.setup.SetupTasks {++ @Override+ public List<Setup> createTasks(Container container, String setupType, boolean keycloakEnabled) {+ return List.of(new ManagerDateTimeSetup(container));+ }+}diff --git a/setup/src/datetime/java/org/openremote/setup/datetime/model/DateTimeAssetModelProvider.java b/setup/src/datetime/java/org/openremote/setup/datetime/model/DateTimeAssetModelProvider.javanew file mode 100644index 000000000..bb1484c12--- /dev/null+++ b/setup/src/datetime/java/org/openremote/setup/datetime/model/DateTimeAssetModelProvider.java@@ -0,0 +1,28 @@+/*+ * Copyright 2026, OpenRemote Inc.+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License as+ * published by the Free Software Foundation, either version 3 of the+ * License, or (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <https://www.gnu.org/licenses/>.+ *+ * SPDX-License-Identifier: AGPL-3.0-or-later+ */+package org.openremote.setup.datetime.model;++import org.openremote.model.AssetModelProvider;++public class DateTimeAssetModelProvider implements AssetModelProvider {+ @Override+ public boolean useAutoScan() {+ return true;+ }+}diff --git a/setup/src/datetime/java/org/openremote/setup/datetime/model/DateTimeTestAsset.java b/setup/src/datetime/java/org/openremote/setup/datetime/model/DateTimeTestAsset.javanew file mode 100644index 000000000..0cb7ed51e--- /dev/null+++ b/setup/src/datetime/java/org/openremote/setup/datetime/model/DateTimeTestAsset.java@@ -0,0 +1,282 @@+/*+ * Copyright 2026, OpenRemote Inc.+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License as+ * published by the Free Software Foundation, either version 3 of the+ * License, or (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <https://www.gnu.org/licenses/>.+ *+ * SPDX-License-Identifier: AGPL-3.0-or-later+ */+package org.openremote.setup.datetime.model;++import static org.openremote.model.value.ValueFormat.StyleRepresentation.DIGIT_2;+import static org.openremote.model.value.ValueFormat.StyleRepresentation.MEDIUM;+import static org.openremote.model.value.ValueFormat.StyleRepresentation.NUMERIC;+import static org.openremote.model.value.ValueFormat.StyleRepresentation.SHORT;++import jakarta.persistence.Entity;+import java.time.Instant;+import java.util.Date;+import org.openremote.model.asset.Asset;+import org.openremote.model.asset.AssetDescriptor;+import org.openremote.model.attribute.MetaItem;+import org.openremote.model.value.AttributeDescriptor;+import org.openremote.model.value.MetaItemType;+import org.openremote.model.value.ValueConstraint;+import org.openremote.model.value.ValueFormat;+import org.openremote.model.value.ValueType;++/**+ * Has a date and time attribute for every case of the date time input: each value type, each way a+ * value format sets the precision of the picker, and the date constraints. The label of each+ * attribute states what the picker is expected to do.+ *+ * <p>Formats and constraints are meta items, which attributes copy from their descriptor, so they+ * also show on assets created in the UI.+ */+@Entity+public class DateTimeTestAsset extends Asset<DateTimeTestAsset> {++ // Value types++ public static final AttributeDescriptor<Long> TIMESTAMP =+ new AttributeDescriptor<>(+ "timestamp",+ ValueType.TIMESTAMP,+ new MetaItem<>(MetaItemType.LABEL, "Timestamp: minutes, writes a number"));++ public static final AttributeDescriptor<String> TIMESTAMP_ISO8601 =+ new AttributeDescriptor<>(+ "timestampISO8601",+ ValueType.TIMESTAMP_ISO8601,+ new MetaItem<>(MetaItemType.LABEL, "ISO 8601 timestamp: minutes, writes an ISO string"));++ public static final AttributeDescriptor<String> TIMESTAMP_ISO8601_SECONDS =+ new AttributeDescriptor<>(+ "timestampISO8601Seconds",+ ValueType.TIMESTAMP_ISO8601,+ new MetaItem<>(+ MetaItemType.LABEL,+ "ISO 8601 timestamp with moment ss: seconds, writes an ISO string"),+ new MetaItem<>(+ MetaItemType.FORMAT, new ValueFormat().setMomentJsFormat("DD-MM-YYYY HH:mm:ss")));++ public static final AttributeDescriptor<String> TIMESTAMP_ISO8601_MILLISECONDS =+ new AttributeDescriptor<>(+ "timestampISO8601Milliseconds",+ ValueType.TIMESTAMP_ISO8601,+ new MetaItem<>(+ MetaItemType.LABEL,+ "ISO 8601 timestamp with moment ss.SSS: milliseconds, writes an ISO string"),+ new MetaItem<>(+ MetaItemType.FORMAT, new ValueFormat().setMomentJsFormat("DD-MM-YYYY HH:mm:ss.SSS")));++ public static final AttributeDescriptor<Date> DATE_AND_TIME =+ new AttributeDescriptor<>(+ "dateAndTime",+ ValueType.DATE_AND_TIME,+ new MetaItem<>(MetaItemType.LABEL, "Date and time: minutes, writes a number"));++ public static final AttributeDescriptor<Long> LONG_AS_DATE =+ new AttributeDescriptor<>(+ "longAsDate",+ ValueType.LONG,+ new MetaItem<>(MetaItemType.LABEL, "Long as date: minutes"),+ new MetaItem<>(MetaItemType.FORMAT, new ValueFormat().setAsDate(true)));++ public static final AttributeDescriptor<Long> EMPTY_TIMESTAMP =+ new AttributeDescriptor<>(+ "emptyTimestamp",+ ValueType.TIMESTAMP,+ new MetaItem<>(MetaItemType.LABEL, "Empty timestamp: minutes"));++ // Precision from a moment format++ public static final AttributeDescriptor<Long> MOMENT_SECONDS =+ new AttributeDescriptor<>(+ "momentSeconds",+ ValueType.TIMESTAMP,+ new MetaItem<>(MetaItemType.LABEL, "Moment ss: seconds"),+ new MetaItem<>(+ MetaItemType.FORMAT, new ValueFormat().setMomentJsFormat("DD-MM-YYYY HH:mm:ss")));++ public static final AttributeDescriptor<Long> MOMENT_MILLISECONDS =+ new AttributeDescriptor<>(+ "momentMilliseconds",+ ValueType.TIMESTAMP,+ new MetaItem<>(MetaItemType.LABEL, "Moment ss.SSS: milliseconds"),+ new MetaItem<>(+ MetaItemType.FORMAT, new ValueFormat().setMomentJsFormat("DD-MM-YYYY HH:mm:ss.SSS")));++ public static final AttributeDescriptor<Long> MOMENT_UNIX_MILLISECONDS =+ new AttributeDescriptor<>(+ "momentUnixMilliseconds",+ ValueType.TIMESTAMP,+ new MetaItem<>(MetaItemType.LABEL, "Moment x: milliseconds"),+ new MetaItem<>(MetaItemType.FORMAT, new ValueFormat().setMomentJsFormat("x")));++ public static final AttributeDescriptor<Long> MOMENT_UNIX_SECONDS =+ new AttributeDescriptor<>(+ "momentUnixSeconds",+ ValueType.TIMESTAMP,+ new MetaItem<>(MetaItemType.LABEL, "Moment X: seconds"),+ new MetaItem<>(MetaItemType.FORMAT, new ValueFormat().setMomentJsFormat("X")));++ public static final AttributeDescriptor<Long> MOMENT_LOCALIZED_SECONDS =+ new AttributeDescriptor<>(+ "momentLocalizedSeconds",+ ValueType.TIMESTAMP,+ new MetaItem<>(MetaItemType.LABEL, "Moment L LTS: seconds"),+ new MetaItem<>(MetaItemType.FORMAT, new ValueFormat().setMomentJsFormat("L LTS")));++ public static final AttributeDescriptor<Long> MOMENT_LITERAL_LAST_SEEN =+ new AttributeDescriptor<>(+ "momentLiteralLastSeen",+ ValueType.TIMESTAMP,+ new MetaItem<>(MetaItemType.LABEL, "Moment [Last seen] literal: minutes"),+ new MetaItem<>(+ MetaItemType.FORMAT,+ new ValueFormat().setMomentJsFormat("[Last seen] DD-MM-YYYY HH:mm")));++ public static final AttributeDescriptor<Long> MOMENT_LITERAL_SENSOR =+ new AttributeDescriptor<>(+ "momentLiteralSensor",+ ValueType.TIMESTAMP,+ new MetaItem<>(MetaItemType.LABEL, "Moment [Sensor] literal: minutes"),+ new MetaItem<>(+ MetaItemType.FORMAT,+ new ValueFormat().setMomentJsFormat("[Sensor] DD-MM-YYYY HH:mm")));++ // Precision from Intl options, with asDate so the display formats the epoch milliseconds as dates++ public static final AttributeDescriptor<Date> INTL_SECONDS =+ new AttributeDescriptor<>(+ "intlSeconds",+ ValueType.DATE_AND_TIME,+ new MetaItem<>(MetaItemType.LABEL, "Intl second: seconds"),+ new MetaItem<>(MetaItemType.FORMAT, dateTimeFormat().setSecond(DIGIT_2)));++ public static final AttributeDescriptor<Date> INTL_FRACTIONAL_SECONDS =+ new AttributeDescriptor<>(+ "intlFractionalSeconds",+ ValueType.DATE_AND_TIME,+ new MetaItem<>(MetaItemType.LABEL, "Intl fractionalSecondDigits: milliseconds"),+ new MetaItem<>(+ MetaItemType.FORMAT,+ dateTimeFormat().setSecond(DIGIT_2).setFractionalSecondDigits(3)));++ public static final AttributeDescriptor<Date> INTL_TIME_STYLE_MEDIUM =+ new AttributeDescriptor<>(+ "intlTimeStyleMedium",+ ValueType.DATE_AND_TIME,+ new MetaItem<>(MetaItemType.LABEL, "Intl timeStyle medium: seconds"),+ new MetaItem<>(+ MetaItemType.FORMAT,+ new ValueFormat().setAsDate(true).setDateStyle(SHORT).setTimeStyle(MEDIUM)));++ public static final AttributeDescriptor<Date> INTL_TIME_STYLE_SHORT =+ new AttributeDescriptor<>(+ "intlTimeStyleShort",+ ValueType.DATE_AND_TIME,+ new MetaItem<>(MetaItemType.LABEL, "Intl timeStyle short: minutes"),+ new MetaItem<>(+ MetaItemType.FORMAT,+ new ValueFormat().setAsDate(true).setDateStyle(SHORT).setTimeStyle(SHORT)));++ // The display elsewhere uses the built-in moment format of the timestamp type, in minutes+ public static final AttributeDescriptor<Long> TIMESTAMP_WITH_SECOND =+ new AttributeDescriptor<>(+ "timestampWithSecond",+ ValueType.TIMESTAMP,+ new MetaItem<>(+ MetaItemType.LABEL,+ "Timestamp with Intl second: seconds, displayed elsewhere in minutes"),+ new MetaItem<>(MetaItemType.FORMAT, new ValueFormat().setSecond(DIGIT_2)));++ // Constraints and state++ public static final AttributeDescriptor<Long> PAST =+ new AttributeDescriptor<>(+ "past",+ ValueType.TIMESTAMP,+ new MetaItem<>(MetaItemType.LABEL, "Past: latest selectable is now"),+ new MetaItem<>(+ MetaItemType.CONSTRAINTS, ValueConstraint.constraints(new ValueConstraint.Past())));++ public static final AttributeDescriptor<Long> FUTURE =+ new AttributeDescriptor<>(+ "future",+ ValueType.TIMESTAMP,+ new MetaItem<>(MetaItemType.LABEL, "Future: earliest selectable is the minute after now"),+ new MetaItem<>(+ MetaItemType.CONSTRAINTS, ValueConstraint.constraints(new ValueConstraint.Future())));++ public static final AttributeDescriptor<Long> FUTURE_OR_PRESENT =+ new AttributeDescriptor<>(+ "futureOrPresent",+ ValueType.TIMESTAMP,+ new MetaItem<>(+ MetaItemType.LABEL, "Future or present: earliest selectable is the minute after now"),+ new MetaItem<>(+ MetaItemType.CONSTRAINTS,+ ValueConstraint.constraints(new ValueConstraint.FutureOrPresent())));++ public static final AttributeDescriptor<Long> MIN_BETWEEN_MINUTES =+ new AttributeDescriptor<>(+ "minBetweenMinutes",+ ValueType.TIMESTAMP,+ new MetaItem<>(+ MetaItemType.LABEL,+ "Min 10:30:45 on 2 Jan 2026 (Amsterdam): earliest selectable that day is 10:31"),+ new MetaItem<>(+ MetaItemType.CONSTRAINTS,+ ValueConstraint.constraints(+ new ValueConstraint.Min(+ Instant.parse("2026-01-02T09:30:45.123Z").toEpochMilli()))));++ public static final AttributeDescriptor<Long> RANGE =+ new AttributeDescriptor<>(+ "range",+ ValueType.TIMESTAMP,+ new MetaItem<>(MetaItemType.LABEL, "Range: only 2026 (UTC)"),+ new MetaItem<>(+ MetaItemType.CONSTRAINTS,+ ValueConstraint.constraints(+ new ValueConstraint.Min(Instant.parse("2026-01-01T00:00:00Z").toEpochMilli()),+ new ValueConstraint.Max(Instant.parse("2026-12-31T23:59:59Z").toEpochMilli()))));++ public static final AttributeDescriptor<Long> READ_ONLY_TIMESTAMP =+ new AttributeDescriptor<>(+ "readOnlyTimestamp",+ ValueType.TIMESTAMP,+ new MetaItem<>(MetaItemType.LABEL, "Read only timestamp: minutes"),+ new MetaItem<>(MetaItemType.READ_ONLY, true));++ public static final AssetDescriptor<DateTimeTestAsset> DESCRIPTOR =+ new AssetDescriptor<>("calendar-clock", "3d85c6", DateTimeTestAsset.class);++ protected DateTimeTestAsset() {}++ public DateTimeTestAsset(String name) {+ super(name);+ }++ private static ValueFormat dateTimeFormat() {+ return new ValueFormat()+ .setAsDate(true)+ .setYear(NUMERIC)+ .setMonth(DIGIT_2)+ .setDay(DIGIT_2)+ .setHour(DIGIT_2)+ .setMinute(DIGIT_2);+ }+}diff --git a/setup/src/datetime/resources/META-INF/services/org.openremote.model.AssetModelProvider b/setup/src/datetime/resources/META-INF/services/org.openremote.model.AssetModelProvidernew file mode 100644index 000000000..a53b72d15--- /dev/null+++ b/setup/src/datetime/resources/META-INF/services/org.openremote.model.AssetModelProvider@@ -0,0 +1 @@+org.openremote.setup.datetime.model.DateTimeAssetModelProviderdiff --git a/setup/src/datetime/resources/META-INF/services/org.openremote.model.setup.SetupTasks b/setup/src/datetime/resources/META-INF/services/org.openremote.model.setup.SetupTasksnew file mode 100644index 000000000..e77c74dd3--- /dev/null+++ b/setup/src/datetime/resources/META-INF/services/org.openremote.model.setup.SetupTasks@@ -0,0 +1 @@+org.openremote.setup.datetime.SetupTasksdiff --git a/ui/AGENTS.md b/ui/AGENTS.mdindex c31f7be2f..7f80a3a55 100644--- a/ui/AGENTS.md+++ b/ui/AGENTS.md@@ -34,6 +34,8 @@ New packages under `ui/component/` are picked up automatically by the yarn worksVaadin-based components live in `ui/component/or-vaadin-components/src/` as thin wrappers that extend a Vaadin class and re-register it under an `or-vaadin-<name>` tag, e.g. `export class OrVaadinX extends (X as new () => X & LitElement)` with `@customElement("or-vaadin-x")`. Keep all `@vaadin/*` dependency versions aligned.+The date and time picker wrappers set their `i18n` themselves: the date order, clock and first day of the week follow the browser locale, so users keep their regional format, while month and weekday names and button labels follow the app language and update when it changes. Do not set `i18n` on them from outside.+### Styling the component's shadow-DOM internalsPick the approach by how much of the base component you need to keep. The base + Lumo styles are keyed off the element's `static get is()`, so a wrapper that does _not_ override `is` still reports the base tag (e.g. `vaadin-checkbox-group`) and inherits the full base + Lumo theme.@@ -53,7 +55,7 @@ Pick the approach by how much of the base component you need to keep. The base +### Registering an input type in the input pipeline-To make an input type usable through the input pipeline, register it in `or-vaadin-input.ts` (`TEMPLATES` map + a `getXTemplate`, and `nativeValue` if it is a boolean that exposes `checked` instead of `value`) and update `value-input-provider.ts` (boolean/checked types use the `checked` attribute, not `value`).+To make an input type usable through the input pipeline, register it in `or-vaadin-input.ts` (`TEMPLATES` map + a `getXTemplate`, and `nativeValue` if it is a boolean that exposes `checked` instead of `value`) and update `value-input-provider.ts` (boolean/checked types use the `checked` attribute, not `value`). Where the Vaadin component represents the value differently than the attribute does, such as the date time picker taking a local ISO string instead of a timestamp, convert the value and any min/max there and convert back through `valueConverter`.## Storybook@@ -75,6 +77,7 @@ Stories call `getORStorybookHelpers(tagName)` (from `ui/component/storybook-util- **Avoid Redundant Actions:** Do not create methods in fixtures that simply wrap native Playwright actions (e.g., `click()`, `getByRole()`, `expect()`). Use native Playwright actions directly in the tests where possible.- **Provide Locators:** Provide fixture methods for locators with non-standard or complex paths (e.g., reliant on specific DOM structures) so others can reuse the correct locators across tests.+- **Data Fixtures:** Keep test data, such as assets, schemas or complex structures, in `test/fixtures/data/` rather than in the test file.### App tests@@ -86,8 +89,9 @@ Stories call `getORStorybookHelpers(tagName)` (from `ui/component/storybook-util### Component testing- **Location:** Define tests in `ui/component/<component-name>/test/`. Define fixtures in `ui/component/<component-name>/test/fixtures/`.+- **One `ct`:** The package's `test/fixtures/index.ts` exports a single `ct` with all its fixtures registered and re-exports `expect`, and tests import both from `./fixtures`. Settings that differ per test go through that `ct` instead of additional exported test objects. Options that Playwright only takes per file or describe block, such as `locale`, can be set per test by overriding the fixture to read a test annotation.-Component tests use Playwright component testing (`@sand4rt/experimental-ct-web`). They live in each package's `test/*.test.ts`, import `{ ct, expect }` from `@openremote/test`, and `mount(ComponentClass, { props, slots, on })`. Run them with `npm test` in the package (which does `tsc -b && playwright test`). CI runs `./gradlew -p ui/component npmTest`, which only executes packages that register an `npmTest` task, so when adding the first test to a package also register `npmTest` in its `build.gradle` file; copy the tasks from a sibling package. Prefer web-first, role-based assertions (`getByRole("checkbox", { name }).toBeChecked()`, `toHaveCount(...)`) over poking at JS properties (`toHaveJSProperty`) or internal locators. Some important quirks to know about:+Component tests use Playwright component testing (`@sand4rt/experimental-ct-web`). They live in each package's `test/*.test.ts`, import `{ ct, expect }` from the package's `./fixtures` (or from `@openremote/test` when the package has no fixtures), and `mount(ComponentClass, { props, slots, on })`. Run them with `npm test` in the package (which does `tsc -b && playwright test`). CI runs `./gradlew -p ui/component npmTest`, which only executes packages that register an `npmTest` task, so when adding the first test to a package also register `npmTest` in its `build.gradle` file; copy the tasks from a sibling package. Prefer web-first, role-based assertions (`getByRole("checkbox", { name }).toBeChecked()`, `toHaveCount(...)`) over poking at JS properties (`toHaveJSProperty`) or internal locators. Some important quirks to know about:- **Custom elements used as slotted/appended children must be eagerly registered.** Playwright CT turns each imported component into a _lazy_ dynamic import that only runs when that component is `mount()`ed, so a child element that is never mounted itself (e.g. `or-vaadin-toggle` slotted inside `or-vaadin-toggle-group`) never gets `customElements.define`d and stays an inert, unupgraded tag that appends to the DOM but does not render. Declare such components in the test itself via `mount(..., { hooksConfig: { components: [OrVaadinToggle] } })`; the `beforeMount` hook in `ui/test/playwright/index.js` resolves their import refs, which runs their modules and registers them before the mount.- **Use only one `mount()` call per test.** Multiple mounts do not resolve to separate locator paths and can hang until the test times out on a strict mode violation.diff --git a/ui/component/or-asset-viewer/src/index.ts b/ui/component/or-asset-viewer/src/index.tsindex f35a9c08b..a8de158f4 100644--- a/ui/component/or-asset-viewer/src/index.ts+++ b/ui/component/or-asset-viewer/src/index.ts@@ -69,6 +69,7 @@ import { when } from "lit/directives/when.js";import { ifDefined } from "lit/directives/if-defined.js";import type { OrVaadinCheckbox } from "@openremote/or-vaadin-components/or-vaadin-checkbox";import type { OrVaadinInput } from "@openremote/or-vaadin-components/or-vaadin-input";+import { OrVaadinDateTimePicker } from "@openremote/or-vaadin-components/or-vaadin-date-time-picker";import { getConfirmDialogContent, showConfirmDialog } from "@openremote/or-vaadin-components/or-vaadin-confirm-dialog";declare function require(name: string): any;@@ -1050,6 +1051,7 @@ export function getPropertyTemplate(break;case "createdOn":type = InputType.DATETIME;+ value = OrVaadinDateTimePicker.getLocalizedISOString(new Date(value));break;case "accessPublicRead":type = InputType.CHECKBOX;diff --git a/ui/component/or-asset-viewer/test/asset-viewer.test.ts b/ui/component/or-asset-viewer/test/asset-viewer.test.tsindex 50635dbb0..ba50b22ed 100644--- a/ui/component/or-asset-viewer/test/asset-viewer.test.ts+++ b/ui/component/or-asset-viewer/test/asset-viewer.test.ts@@ -40,6 +40,26 @@ ct("Should not show asset invalid error", async ({ mount }) => {await expect(component).not.toContainText("Asset is not valid");});+ct.describe("Created on", () => {+ // The picker shows local time in the format of the browser locale, so both are pinned for the expected value.+ ct.use({ timezoneId: "Europe/Amsterdam", locale: "en-US" });++ ct("should show the date and time the asset was created", async ({ mount }) => {+ const component = await mount(OrAssetViewer, {+ props: {+ assetId: validId,+ // The default config shows no properties.+ config: { default: { panels: [{ type: "info", properties: { include: ["createdOn"] }, attributes: {} }] } },+ },+ });++ const createdOn = component.locator("#property-createdOn");+ // The timestamp used to reach the picker as is, which only takes local ISO strings, leaving it empty.+ await expect(createdOn.getByRole("combobox").first()).toHaveValue("01/02/2026");+ await expect(createdOn.getByRole("combobox").last()).toHaveValue("10:30 AM");+ });+});+// Due to how the component tests resolve imports, imported data with an object reference gets// confused for a component that is meant to be registered in the playwright component test app.// Which causes the data to be transformed to an intermediate object referencing the data.diff --git a/ui/component/or-asset-viewer/test/fixtures/data/asset.ts b/ui/component/or-asset-viewer/test/fixtures/data/asset.tsindex fb81726b5..b162adcce 100644--- a/ui/component/or-asset-viewer/test/fixtures/data/asset.ts+++ b/ui/component/or-asset-viewer/test/fixtures/data/asset.ts@@ -26,6 +26,8 @@ export const validAsset: Asset = {name: "Thing",realm: "master",type: "ThingAsset",+ // 2026-01-02T10:30 in Europe/Amsterdam (UTC+1)+ createdOn: Date.UTC(2026, 0, 2, 9, 30),attributes: { ...commonAttrs },};export const invalidAsset: Asset = {diff --git a/ui/component/or-vaadin-components/package.json b/ui/component/or-vaadin-components/package.jsonindex 69e1e0e5b..a9e00e1d5 100644--- a/ui/component/or-vaadin-components/package.json+++ b/ui/component/or-vaadin-components/package.json@@ -60,6 +60,7 @@"@vaadin/text-field": "~25.2.11","@vaadin/time-picker": "~25.2.11","@vaadin/vaadin-themable-mixin": "~25.2.11",+ "i18next": "^21.5.3","lit": "^3.3.1"},"publishConfig": {diff --git a/ui/component/or-vaadin-components/src/date-time-i18n.ts b/ui/component/or-vaadin-components/src/date-time-i18n.tsnew file mode 100644index 000000000..1c474bd92--- /dev/null+++ b/ui/component/or-vaadin-components/src/date-time-i18n.ts@@ -0,0 +1,286 @@+/*+ * Copyright 2026, OpenRemote Inc.+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License as+ * published by the Free Software Foundation, either version 3 of the+ * License, or (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <https://www.gnu.org/licenses/>.+ *+ * SPDX-License-Identifier: AGPL-3.0-or-later+ */+import i18next from "i18next";+import { I18NEXT_TO_MOMENT_LOCALE } from "@openremote/core";+import type { DatePickerDate, DatePickerI18n } from "@vaadin/date-picker";+import type { TimePickerI18n } from "@vaadin/time-picker";+import type { TimePickerTime } from "@vaadin/time-picker/src/vaadin-time-picker-helper.js";++// Dates and times are formatted in the browser locale, so users keep their regional format whatever the app language+// is, while names and labels follow the app language.++/**+ * Calls `update` now and whenever the app language changes.+ * @returns A function that stops the updates+ */+export function syncWithLanguage(update: () => void): () => void {+ update();+ i18next.on("languageChanged", update);+ return () => i18next.off("languageChanged", update);+}++/**+ * Returns the Vaadin date picker i18n: the order of the date fields and the first day of the week of the browser+ * locale, and the month and weekday names and button labels of the app language.+ */+export function getDatePickerI18n(): DatePickerI18n {+ const dateFormat = getUTCFormat(undefined, { day: "2-digit", month: "2-digit", year: "numeric" });+ const fieldOrder = dateFormat+ .formatToParts(0)+ .map((part) => part.type)+ .filter((type) => type === "day" || type === "month" || type === "year");++ const language = getLanguageLocale();+ const monthFormat = getUTCFormat(language, { month: "long" });+ const weekdayFormat = getUTCFormat(language, { weekday: "long" });+ const shortWeekdayFormat = getUTCFormat(language, { weekday: "short" });+ const today = new Intl.RelativeTimeFormat(language, { numeric: "auto" }).format(0, "day");++ const i18n: DatePickerI18n = {+ monthNames: Array.from({ length: 12 }, (_, month) => monthFormat.format(Date.UTC(2000, month, 1))),+ // The weekday names start on Sunday, and 2 January 2000 is one+ weekdays: Array.from({ length: 7 }, (_, day) => weekdayFormat.format(Date.UTC(2000, 0, 2 + day))),+ weekdaysShort: Array.from({ length: 7 }, (_, day) => shortWeekdayFormat.format(Date.UTC(2000, 0, 2 + day))),+ today: today.charAt(0).toLocaleUpperCase(language) + today.slice(1),+ formatDate: (date) => formatDate(dateFormat, date),+ parseDate: (text) => parseDate(fieldOrder, text),+ };++ const firstDayOfWeek = getFirstDayOfWeek(dateFormat.resolvedOptions().locale);+ if (firstDayOfWeek !== undefined) {+ i18n.firstDayOfWeek = firstDayOfWeek;+ }+ if (i18next.exists("cancel")) {+ i18n.cancel = i18next.t("cancel");+ }+ return i18n;+}++/**+ * Returns the Vaadin time picker i18n: a 12-hour clock in the layout of the browser locale where it uses one, or the+ * default 24-hour format of the picker otherwise.+ */+export function getTimePickerI18n(): TimePickerI18n {+ const timeFormat = getUTCFormat(undefined, { hour: "numeric", minute: "2-digit" });+ if (!timeFormat.resolvedOptions().hour12) {+ return {};+ }++ const locale = timeFormat.resolvedOptions().locale;+ const [am, pm] = [0, 12].map(+ (hours) =>+ timeFormat.formatToParts(Date.UTC(2000, 0, 1, hours)).find((part) => part.type === "dayPeriod")?.value ??+ (hours < 12 ? "AM" : "PM")+ );+ // The parts of 1:02 give the order of the day period and the time, and the literals around them. Spaces are made+ // plain, as Intl may use a narrow no-break space that cannot be typed.+ const parts = timeFormat+ .formatToParts(Date.UTC(2000, 0, 1, 1, 2))+ .map((part) => (part.type === "literal" ? { ...part, value: part.value.replace(/\s/gu, " ") } : part));+ const separator =+ parts.find((part, index) => part.type === "literal" && parts[index - 1]?.type === "hour")?.value ?? ":";+ const timePattern = createTimePattern(separator);+ const normalize = (text: string) => text.toLocaleLowerCase(locale).replace(/[\s.]/gu, "");++ return {+ formatTime: (time) => formatTime(time, parts, separator, am, pm),+ parseTime: (text) => parseTime(text, timePattern, normalize(am), normalize(pm), normalize),+ };+}++/**+ * Returns the Intl locale of the app language, or undefined for the browser locale when Intl does not support it.+ */+function getLanguageLocale(): string | undefined {+ const language = i18next.language;+ if (!language) {+ return undefined;+ }+ try {+ return Intl.DateTimeFormat.supportedLocalesOf(I18NEXT_TO_MOMENT_LOCALE[language] ?? language)[0];+ } catch {+ return undefined;+ }+}++/**+ * Returns a UTC date format in the locale, where an undefined locale is the browser locale.+ */+function getUTCFormat(locale: string | undefined, options: Intl.DateTimeFormatOptions) {+ return new Intl.DateTimeFormat(locale, { ...options, timeZone: "UTC", numberingSystem: "latn" });+}++/**+ * Returns the first day of the week of the locale, where 0 is Sunday, or undefined when the browser has no week info.+ */+function getFirstDayOfWeek(locale: string): number | undefined {+ const intlLocale = new Intl.Locale(locale) as Intl.Locale & {+ getWeekInfo?: () => { firstDay: number };+ weekInfo?: { firstDay: number };+ };+ const weekInfo = intlLocale.getWeekInfo?.() ?? intlLocale.weekInfo;+ return weekInfo && weekInfo.firstDay % 7;+}++function formatDate(format: Intl.DateTimeFormat, { day, month, year }: DatePickerDate): string {+ const date = new Date(0);+ date.setUTCFullYear(year, month, day);+ // A padded year keeps years below 1000 from parsing back as two-digit years+ return format+ .formatToParts(date)+ .map((part) => (part.type === "year" ? String(year).padStart(4, "0") : part.value))+ .join("");+}++/**+ * Parses the numbers of the text in the field order of the date format. Leaving out numbers drops the year and then the+ * month, which default to the current ones.+ */+function parseDate(fieldOrder: string[], text: string): DatePickerDate | undefined {+ const numbers = text.match(/\d+/gu) ?? [];+ if (numbers.length < 1 || numbers.length > 3) {+ return undefined;+ }++ let fields = ["day"];+ if (numbers.length === 3) {+ fields = fieldOrder;+ } else if (numbers.length === 2) {+ fields = fieldOrder.filter((field) => field !== "year");+ }+ const parts = Object.fromEntries(fields.map((field, index) => [field, numbers[index]]));++ const today = new Date();+ const day = parseInt(parts.day);+ const month = parts.month === undefined ? today.getMonth() : parseInt(parts.month) - 1;+ let year = today.getFullYear();+ if (parts.year !== undefined) {+ year = parts.year.length < 3 ? getAdjustedYear(today, parseInt(parts.year), month, day) : parseInt(parts.year);+ }+ return { day, month, year };+}++/**+ * Returns the year ending in the two given digits that lies within 50 years of the reference date.+ */+function getAdjustedYear(referenceDate: Date, year: number, month: number, day: number): number {+ let adjustedYear = year + Math.floor(referenceDate.getFullYear() / 100) * 100;+ if (referenceDate < new Date(adjustedYear - 50, month, day)) {+ adjustedYear -= 100;+ } else if (referenceDate > new Date(adjustedYear + 50, month, day)) {+ adjustedYear += 100;+ }+ return adjustedYear;+}++/**+ * Formats a time on a 12-hour clock in the layout of the parts of the locale, with any seconds and milliseconds after+ * the minutes.+ */+function formatTime(+ time: TimePickerTime | undefined,+ parts: Intl.DateTimeFormatPart[],+ separator: string,+ am: string,+ pm: string+): string {+ if (!time) {+ return "";+ }+ const pad = (value: number | string, length = 2) => String(value).padStart(length, "0");+ const hours = Number(time.hours);+ let minutes = pad(time.minutes);+ if (time.seconds !== undefined) {+ minutes += `${separator}${pad(time.seconds)}`;+ }+ if (time.milliseconds !== undefined) {+ minutes += `.${pad(time.milliseconds, 3)}`;+ }++ return parts+ .map((part) => {+ switch (part.type) {+ case "hour":+ return part.value.length === 2 ? pad(hours % 12 || 12) : String(hours % 12 || 12);+ case "minute":+ return minutes;+ case "dayPeriod":+ return hours < 12 ? am : pm;+ default:+ return part.value;+ }+ })+ .join("");+}++/**+ * Returns the pattern of a time with the given separator, and a day period before or after it.+ */+function createTimePattern(separator: string): RegExp {+ const s = separator.replace(/[.*+?^${}()|[\]\\]/gu, "\\$&");+ return new RegExp(+ `^\\s*(\\D*?)\\s*(\\d{1,2})(?:${s}(\\d{1,2})(?:${s}(\\d{1,2})(?:\\.(\\d{1,3}))?)?)?\\s*(\\D*?)\\s*$`,+ "u"+ );+}++/**+ * Parses a time on a 12-hour clock with the day period before or after it, or on a 24-hour clock when the text has no+ * day period. A prefix of the day period is enough, such as "p" for "PM".+ */+function parseTime(+ text: string,+ pattern: RegExp,+ am: string,+ pm: string,+ normalize: (text: string) => string+): TimePickerTime | undefined {+ const match = pattern.exec(text);+ if (!match) {+ return undefined;+ }++ const [, leadingPeriod, hourText, minuteText, secondText, millisecondText, trailingPeriod] = match;+ const periods = [leadingPeriod, trailingPeriod].map(normalize).filter((period) => period);+ if (periods.length > 1) {+ return undefined;+ }+ const [period] = periods;+ let hours = parseInt(hourText);+ const minutes = minuteText === undefined ? 0 : parseInt(minuteText);+ const seconds = secondText === undefined ? undefined : parseInt(secondText);+ if (period) {+ const isAm = am.startsWith(period);+ const isPm = pm.startsWith(period);+ if (isAm === isPm || hours < 1 || hours > 12) {+ return undefined;+ }+ hours = (hours % 12) + (isPm ? 12 : 0);+ }+ if (hours > 23 || minutes > 59 || (seconds ?? 0) > 59) {+ return undefined;+ }++ return {+ hours,+ minutes,+ seconds,+ milliseconds: millisecondText === undefined ? undefined : parseInt(millisecondText.padEnd(3, "0")),+ };+}diff --git a/ui/component/or-vaadin-components/src/or-vaadin-date-picker.ts b/ui/component/or-vaadin-components/src/or-vaadin-date-picker.tsindex 560ebd08d..c241e083c 100644--- a/ui/component/or-vaadin-components/src/or-vaadin-date-picker.ts+++ b/ui/component/or-vaadin-components/src/or-vaadin-date-picker.ts@@ -16,9 +16,25 @@** SPDX-License-Identifier: AGPL-3.0-or-later*/+import type { LitElement } from "lit";import { customElement } from "lit/decorators.js";import { DatePicker } from "@vaadin/date-picker";+import { getDatePickerI18n, syncWithLanguage } from "./date-time-i18n";import type { OrVaadinComponent } from "./util";@customElement("or-vaadin-date-picker")-export class OrVaadinDatePicker extends DatePicker implements OrVaadinComponent {}+export class OrVaadinDatePicker extends (DatePicker as new () => DatePicker & LitElement) implements OrVaadinComponent {+ protected _stopLanguageSync?: () => void;++ connectedCallback() {+ super.connectedCallback();+ this._stopLanguageSync = syncWithLanguage(() => {+ this.i18n = getDatePickerI18n();+ });+ }++ disconnectedCallback() {+ super.disconnectedCallback();+ this._stopLanguageSync?.();+ }+}diff --git a/ui/component/or-vaadin-components/src/or-vaadin-date-time-picker.ts b/ui/component/or-vaadin-components/src/or-vaadin-date-time-picker.tsindex 52bc771cf..af3c7009a 100644--- a/ui/component/or-vaadin-components/src/or-vaadin-date-time-picker.ts+++ b/ui/component/or-vaadin-components/src/or-vaadin-date-time-picker.ts@@ -16,13 +16,69 @@** SPDX-License-Identifier: AGPL-3.0-or-later*/+import type { LitElement } from "lit";import { customElement } from "lit/decorators.js";import { DateTimePicker } from "@vaadin/date-time-picker";+import { ValueFormatStyleRepresentation, type ValueFormat } from "@openremote/model";+import { getDatePickerI18n, getTimePickerI18n, syncWithLanguage } from "./date-time-i18n";import type { OrVaadinComponent } from "./util";@customElement("or-vaadin-date-time-picker")-export class OrVaadinDateTimePicker extends DateTimePicker implements OrVaadinComponent {- public static getLocalizedISOString(d?: Date) {- return d && new Date(d.getTime() - d.getTimezoneOffset() * 60000).toISOString().slice(0, 16);+export class OrVaadinDateTimePicker+ extends (DateTimePicker as new () => DateTimePicker & LitElement)+ implements OrVaadinComponent+{+ protected _stopLanguageSync?: () => void;++ /**+ * Returns the date as a local ISO string in the precision of the picker step, which is minutes without a step,+ * rounded down or, with roundUp, up to that precision, or undefined for an invalid date.+ */+ public static getLocalizedISOString(d?: Date, step?: number, roundUp = false) {+ if (!d || Number.isNaN(d.getTime())) {+ return undefined;+ }+ let format = "YYYY-MM-DDTHH:mm";+ let precision = 60000;+ if (step !== undefined && step % 60 !== 0) {+ format = step % 1 === 0 ? "YYYY-MM-DDTHH:mm:ss" : "YYYY-MM-DDTHH:mm:ss.sss";+ precision = step % 1 === 0 ? 1000 : 1;+ }+ const date = roundUp ? new Date(Math.ceil(d.getTime() / precision) * precision) : d;+ return new Date(date.getTime() - date.getTimezoneOffset() * 60000).toISOString().slice(0, format.length);+ }++ /**+ * Returns the step for the time precision a value format shows: milliseconds for fractional seconds, seconds for+ * seconds, or undefined for the default of minutes.+ */+ public static getStep(format?: ValueFormat): number | undefined {+ // Text in brackets is literal in moment formats, and LTS is the localized time with seconds+ const momentJsFormat = (format?.momentJsFormat ?? "").replace(/\[[^\]]*\]/gu, "");+ const momentTokens = momentJsFormat.replace(/LTS/gu, "");+ if (format?.fractionalSecondDigits || /[Sx]/u.test(momentTokens)) {+ return 0.001;+ }+ if (+ format?.second ||+ (format?.timeStyle && format.timeStyle !== ValueFormatStyleRepresentation.SHORT) ||+ momentJsFormat.includes("LTS") ||+ /[sX]/u.test(momentTokens)+ ) {+ return 1;+ }+ return undefined;+ }++ connectedCallback() {+ super.connectedCallback();+ this._stopLanguageSync = syncWithLanguage(() => {+ this.i18n = { ...getDatePickerI18n(), ...getTimePickerI18n() };+ });+ }++ disconnectedCallback() {+ super.disconnectedCallback();+ this._stopLanguageSync?.();}}diff --git a/ui/component/or-vaadin-components/src/or-vaadin-input.ts b/ui/component/or-vaadin-components/src/or-vaadin-input.tsindex e9e7cfce0..4af29a6b4 100644--- a/ui/component/or-vaadin-components/src/or-vaadin-input.ts+++ b/ui/component/or-vaadin-components/src/or-vaadin-input.ts@@ -21,6 +21,7 @@ import { OrElement } from "@openremote/or-element";import { customElement, property, query } from "lit/decorators.js";import { InputType } from "./util";import "./or-vaadin-checkbox";+import "./or-vaadin-date-time-picker";import "./or-vaadin-email-field";import "./or-vaadin-number-field";import "./or-vaadin-password-field";@@ -59,6 +60,7 @@ export class OrVaadinInput extends OrElement {* Be aware: all CustomElements defined here need to be imported during initialization; dynamic imports are not expected to work.*/public static readonly VAADIN_CLASSES: (CustomElementConstructor | undefined)[] = [+ customElements.get("or-vaadin-date-time-picker"),customElements.get("or-vaadin-number-field"),customElements.get("or-vaadin-password-field"),customElements.get("or-vaadin-select"),@@ -75,6 +77,7 @@ export class OrVaadinInput extends OrElement {public static readonly TEMPLATES = new Map<InputType, (onChange: (ev: Event) => void) => TemplateResult>([[InputType.BIG_INT, OrVaadinInput.getNumberFieldTemplate],[InputType.CHECKBOX, OrVaadinInput.getCheckboxTemplate],+ [InputType.DATETIME, OrVaadinInput.getDateTimePickerTemplate],[InputType.NUMBER, OrVaadinInput.getNumberFieldTemplate],[InputType.PASSWORD, OrVaadinInput.getPasswordFieldTemplate],[InputType.RANGE, OrVaadinInput.getSliderTemplate],@@ -257,6 +260,10 @@ export class OrVaadinInput extends OrElement {return html`<or-vaadin-checkbox id="elem" @change=${onChange}></or-vaadin-checkbox>`;}+ public static getDateTimePickerTemplate(onChange?: (e: Event) => void) {+ return html`<or-vaadin-date-time-picker id="elem" @change=${onChange}></or-vaadin-date-time-picker>`;+ }+public static getNumberFieldTemplate(onChange?: (e: Event) => void) {return html`<or-vaadin-number-field id="elem" @change=${onChange}></or-vaadin-number-field>`;}diff --git a/ui/component/or-vaadin-components/src/or-vaadin-time-picker.ts b/ui/component/or-vaadin-components/src/or-vaadin-time-picker.tsindex 3fa9fb859..f41087fd5 100644--- a/ui/component/or-vaadin-components/src/or-vaadin-time-picker.ts+++ b/ui/component/or-vaadin-components/src/or-vaadin-time-picker.ts@@ -16,9 +16,25 @@** SPDX-License-Identifier: AGPL-3.0-or-later*/+import type { LitElement } from "lit";import { customElement } from "lit/decorators.js";import { TimePicker } from "@vaadin/time-picker";+import { getTimePickerI18n, syncWithLanguage } from "./date-time-i18n";import type { OrVaadinComponent } from "./util";@customElement("or-vaadin-time-picker")-export class OrVaadinTimePicker extends TimePicker implements OrVaadinComponent {}+export class OrVaadinTimePicker extends (TimePicker as new () => TimePicker & LitElement) implements OrVaadinComponent {+ protected _stopLanguageSync?: () => void;++ connectedCallback() {+ super.connectedCallback();+ this._stopLanguageSync = syncWithLanguage(() => {+ this.i18n = getTimePickerI18n();+ });+ }++ disconnectedCallback() {+ super.disconnectedCallback();+ this._stopLanguageSync?.();+ }+}diff --git a/ui/component/or-vaadin-components/src/value-input-provider.ts b/ui/component/or-vaadin-components/src/value-input-provider.tsindex 9ca16c5a4..a686f22ee 100644--- a/ui/component/or-vaadin-components/src/value-input-provider.ts+++ b/ui/component/or-vaadin-components/src/value-input-provider.ts@@ -55,6 +55,7 @@ import {type SupportedWellknownValueTypes,} from "./util";import { OrVaadinInput } from "./or-vaadin-input";+import { OrVaadinDateTimePicker } from "./or-vaadin-date-time-picker";export interface ValueInputProviderOptions {label?: string;@@ -361,6 +362,21 @@ export const getValueHolderInputTemplateProvider: ValueInputProviderGenerator =}}+ // or-vaadin-date-time-picker works with local ISO strings, while the value is a timestamp or an ISO 8601 string+ if (inputType === InputType.DATETIME) {+ step = OrVaadinDateTimePicker.getStep(format);+ // A minimum rounds up, so that the earliest value the picker allows still meets it+ min = min === undefined ? undefined : OrVaadinDateTimePicker.getLocalizedISOString(new Date(min), step, true);+ max = max === undefined ? undefined : OrVaadinDateTimePicker.getLocalizedISOString(new Date(max), step);+ valueConverter = (v) => {+ const timestamp = v ? Date.parse(v) : Number.NaN;+ if (Number.isNaN(timestamp)) {+ return null;+ }+ return valueDescriptor.jsonType === "string" ? new Date(timestamp).toISOString() : timestamp;+ };+ }+if (inputType === InputType.NUMBER && format?.resolution) {step = format.resolution;}@@ -389,7 +405,7 @@ export const getValueHolderInputTemplateProvider: ValueInputProviderGenerator =if (elem?.checkValidity()) {const doRemoteUpdate =!OrVaadinInput.CHANGE_EVENTS.has(inputType) || OrVaadinInput.CHANGE_EVENTS.get(inputType) === ev.type;- valueChangeNotifier(valueConverter?.(elem.nativeValue) ?? elem.nativeValue, doRemoteUpdate);+ valueChangeNotifier(valueConverter ? valueConverter(elem.nativeValue) : elem.nativeValue, doRemoteUpdate);}};@@ -399,8 +415,11 @@ export const getValueHolderInputTemplateProvider: ValueInputProviderGenerator =if (inputType === InputType.CHECKBOX || inputType === InputType.SWITCH) {checked = Boolean(value);value = undefined;+ } else if (inputType === InputType.DATETIME && value !== undefined && value !== null) {+ value = OrVaadinDateTimePicker.getLocalizedISOString(new Date(value), step);}+ // The step is set before the value, so that a date time picker does not trim the value to its default precision.return html`<or-vaadin-input${ref(inputRef)}@@ -408,6 +427,7 @@ export const getValueHolderInputTemplateProvider: ValueInputProviderGenerator =style="${ifDefined(inputStyle)}"type=${ifDefined(inputType)}label=${ifDefined(label)}+ step=${ifDefined(step)}value=${ifDefined(value)}?checked="${checked}"pattern=${ifDefined(pattern)}@@ -420,7 +440,6 @@ export const getValueHolderInputTemplateProvider: ValueInputProviderGenerator =?readonly=${readonly}?disabled=${disabled}.items=${ifDefined(selectOptions)}- step=${ifDefined(step)}helper-text="${ifDefined(helperText)}"?resizeVertical="${resizeVertical}"min-rows="${ifDefined(inputType === InputType.TEXTAREA ? options.minRows : undefined)}"diff --git a/ui/component/or-vaadin-components/test/fixtures/data/locales.ts b/ui/component/or-vaadin-components/test/fixtures/data/locales.tsnew file mode 100644index 000000000..65296f967--- /dev/null+++ b/ui/component/or-vaadin-components/test/fixtures/data/locales.ts@@ -0,0 +1,74 @@+/*+ * Copyright 2026, OpenRemote Inc.+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License as+ * published by the Free Software Foundation, either version 3 of the+ * License, or (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <https://www.gnu.org/licenses/>.+ *+ * SPDX-License-Identifier: AGPL-3.0-or-later+ */+export interface BrowserLocale {+ locale: string;+ /** 2026-01-02 as shown in the date format of the locale */+ date: string;+ /** 10:30 as shown in the time format of the locale */+ time: string;+ /** 2026-01-03 as typed in the date format of the locale */+ typedDate: string;+ /** 14:15 as typed in the time format of the locale */+ typedTime: string;+ /** English short name of the first day of the week in the locale */+ firstWeekday: string;+}++export const browserLocales: BrowserLocale[] = [+ {+ locale: "en-US",+ date: "01/02/2026",+ time: "10:30 AM",+ typedDate: "1/3/2026",+ typedTime: "2:15 PM",+ firstWeekday: "Sun",+ },+ {+ locale: "nl-NL",+ date: "02-01-2026",+ time: "10:30",+ typedDate: "3-1-2026",+ typedTime: "14:15",+ firstWeekday: "Mon",+ },+ {+ locale: "de-DE",+ date: "02.01.2026",+ time: "10:30",+ typedDate: "3.1.2026",+ typedTime: "14:15",+ firstWeekday: "Mon",+ },+ {+ locale: "ko-KR",+ date: "2026. 01. 02.",+ time: "오전 10:30",+ typedDate: "2026. 1. 3.",+ typedTime: "오후 2:15",+ firstWeekday: "Sun",+ },+ {+ locale: "zh-TW",+ date: "2026/01/02",+ time: "上午10:30",+ typedDate: "2026/1/3",+ typedTime: "下午2:15",+ firstWeekday: "Sun",+ },+];diff --git a/ui/component/or-vaadin-components/test/fixtures/index.ts b/ui/component/or-vaadin-components/test/fixtures/index.tsindex 44bc0f723..5bff0081d 100644--- a/ui/component/or-vaadin-components/test/fixtures/index.ts+++ b/ui/component/or-vaadin-components/test/fixtures/index.ts@@ -17,7 +17,8 @@* SPDX-License-Identifier: AGPL-3.0-or-later*/import type { InputType } from "@openremote/or-vaadin-components/util";-import type { Page, Locator } from "@openremote/test";+import { ct as base, type Locator, type Page, type SharedComponentTestFixtures, withPage } from "@openremote/test";+export { expect } from "@openremote/test";export class VaadinInput {constructor(private readonly page: Page) {}@@ -40,3 +41,41 @@ export class VaadinDialog {return this.page.locator("or-vaadin-dialog");}}++export class VaadinDateTimePicker {+ constructor(private readonly page: Page) {}++ /**+ * Returns the locator of the date input of the or-vaadin-date-time-picker+ */+ getDateInput(locator?: Locator): Locator {+ return (locator ?? this.page).locator("[slot=date-picker] input");+ }++ /**+ * Returns the locator of the time input of the or-vaadin-date-time-picker, which has no combobox role when the step of+ * the picker is below 15 minutes+ */+ getTimeInput(locator?: Locator): Locator {+ return (locator ?? this.page).locator("[slot=time-picker] input");+ }++ /**+ * Returns the locator of the first weekday header of the open calendar, which is hidden from the accessibility tree+ */+ getFirstWeekdayHeader(): Locator {+ return this.page.locator("th[scope='col'][part~='weekday']").first();+ }+}++interface ComponentFixtures extends SharedComponentTestFixtures {+ vaadinDateTimePicker: VaadinDateTimePicker;+}++export const ct = base.extend<ComponentFixtures>({+ vaadinDateTimePicker: withPage(VaadinDateTimePicker),+ // The locale option only applies per file or describe block, so a test sets its browser locale with a locale annotation+ locale: async ({ locale }, use, testInfo) => {+ await use(testInfo.annotations.find((annotation) => annotation.type === "locale")?.description ?? locale);+ },+});diff --git a/ui/component/or-vaadin-components/test/fixtures/value-input-provider-harness.js b/ui/component/or-vaadin-components/test/fixtures/value-input-provider-harness.jsnew file mode 100644index 000000000..0f421e48d--- /dev/null+++ b/ui/component/or-vaadin-components/test/fixtures/value-input-provider-harness.js@@ -0,0 +1,64 @@+/*+ * Copyright 2026, OpenRemote Inc.+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License as+ * published by the Free Software Foundation, either version 3 of the+ * License, or (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <https://www.gnu.org/licenses/>.+ *+ * SPDX-License-Identifier: AGPL-3.0-or-later+ */+// Plain JS on purpose: the component-test bundle compiles .ts files against ui/test's tsconfig+// (rootDir ui/test), so TS component sources outside that dir fail the build.+import { html, LitElement } from "lit";+import { AssetModelUtil } from "@openremote/model";+import { getValueHolderInputTemplateProvider } from "@openremote/or-vaadin-components/value-input-provider";++/**+ * Renders the input for a ThingAsset attribute of `valueType` the way or-attribute-input does: the descriptors are+ * resolved from the asset model, the provider is built once per attribute and its template is re-rendered with the+ * current value. Every value the input reports is re-dispatched as a `value-change` event carrying it as the detail.+ */+export class ValueInputProviderHarness extends LitElement {+ static properties = {+ valueType: { type: String },+ value: {},+ constraints: { type: Array },+ format: { type: Object },+ };++ willUpdate(changed) {+ if (changed.has("valueType") || changed.has("constraints") || changed.has("format")) {+ const meta = {};+ if (this.constraints) meta.constraints = this.constraints;+ if (this.format) meta.format = this.format;+ const attribute = { name: "attribute", type: this.valueType, meta };+ const [attributeDescriptor, valueDescriptor] = AssetModelUtil.getAttributeAndValueDescriptors(+ "ThingAsset",+ attribute.name,+ attribute+ );+ this._provider = getValueHolderInputTemplateProvider(+ "ThingAsset",+ attribute,+ attributeDescriptor,+ valueDescriptor,+ (value) => this.dispatchEvent(new CustomEvent("value-change", { detail: value })),+ { label: "Attribute" }+ );+ }+ }++ render() {+ return this._provider?.templateFunction?.(this.value, false, false, false, false, undefined) ?? html``;+ }+}+customElements.define("test-value-input-provider-harness", ValueInputProviderHarness);diff --git a/ui/component/or-vaadin-components/test/or-vaadin-date-time-picker.test.ts b/ui/component/or-vaadin-components/test/or-vaadin-date-time-picker.test.tsnew file mode 100644index 000000000..35fdf8ecc--- /dev/null+++ b/ui/component/or-vaadin-components/test/or-vaadin-date-time-picker.test.ts@@ -0,0 +1,87 @@+/*+ * Copyright 2026, OpenRemote Inc.+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License as+ * published by the Free Software Foundation, either version 3 of the+ * License, or (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <https://www.gnu.org/licenses/>.+ *+ * SPDX-License-Identifier: AGPL-3.0-or-later+ */+import { ct, expect } from "./fixtures";+import { browserLocales } from "./fixtures/data/locales";++import { OrVaadinDateTimePicker } from "@openremote/or-vaadin-components/or-vaadin-date-time-picker";++ct.beforeEach(async ({ shared }) => {+ await shared.locales();+});++ct.describe("Date and time format", () => {+ for (const { locale, date, time, typedDate, typedTime } of browserLocales) {+ ct(+ `should show and parse the date and time in the format of ${locale}`,+ { annotation: { type: "locale", description: locale } },+ async ({ mount }) => {+ const component = await mount(OrVaadinDateTimePicker, { props: { value: "2026-01-02T10:30" } });++ const dateInput = component.getByRole("combobox").first();+ const timeInput = component.getByRole("combobox").last();+ await expect(dateInput).toHaveValue(date);+ await expect(timeInput).toHaveValue(time);+ await dateInput.fill(typedDate);+ await dateInput.press("Enter");+ await timeInput.fill(typedTime);+ await timeInput.press("Enter");++ await expect(component).toHaveJSProperty("value", "2026-01-03T14:15");+ }+ );+ }+});++ct.describe("Calendar", () => {+ for (const { locale, firstWeekday } of browserLocales) {+ ct(+ `should name the calendar in the app language with the first weekday of ${locale}`,+ { annotation: { type: "locale", description: locale } },+ async ({ mount, page, vaadinDateTimePicker }) => {+ const component = await mount(OrVaadinDateTimePicker, { props: { value: "2026-01-02T10:30" } });+ await component.getByRole("combobox").first().click();++ await expect(page.getByText("January 2026")).toBeVisible();+ await expect(vaadinDateTimePicker.getFirstWeekdayHeader()).toHaveText(firstWeekday);+ await expect(page.getByRole("button", { name: "Today" })).toBeVisible();+ await expect(page.getByRole("button", { name: "Cancel" })).toBeVisible();+ }+ );+ }++ ct(+ "should follow a change of the app language in the names only",+ { annotation: { type: "locale", description: "en-US" } },+ async ({ mount, page, vaadinDateTimePicker }) => {+ const component = await mount(OrVaadinDateTimePicker, { props: { value: "2026-01-02T10:30" } });++ const dateInput = component.getByRole("combobox").first();+ await dateInput.click();+ await expect(page.getByText("January 2026")).toBeVisible();++ await page.evaluate(() => window._i18next.changeLanguage("nl"));+ await expect(page.getByText("januari 2026")).toBeVisible();+ // The week still starts on Sunday in the United States.+ await expect(vaadinDateTimePicker.getFirstWeekdayHeader()).toHaveText("zo");+ await expect(page.getByRole("button", { name: "Vandaag" })).toBeVisible();+ await expect(page.getByRole("button", { name: "Annuleren" })).toBeVisible();+ await expect(dateInput).toHaveValue("01/02/2026");+ }+ );+});diff --git a/ui/component/or-vaadin-components/test/or-vaadin-input.test.ts b/ui/component/or-vaadin-components/test/or-vaadin-input.test.tsnew file mode 100644index 000000000..e46fdda12--- /dev/null+++ b/ui/component/or-vaadin-components/test/or-vaadin-input.test.ts@@ -0,0 +1,56 @@+/*+ * Copyright 2026, OpenRemote Inc.+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License as+ * published by the Free Software Foundation, either version 3 of the+ * License, or (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <https://www.gnu.org/licenses/>.+ *+ * SPDX-License-Identifier: AGPL-3.0-or-later+ */+import { ct, expect } from "@openremote/test";++import { OrVaadinInput } from "@openremote/or-vaadin-components/or-vaadin-input";++// The date time picker shows the format of the browser locale.+ct.use({ locale: "en-US" });++ct("should render a date time picker for the datetime-local type", async ({ mount }) => {+ const component = await mount(OrVaadinInput, { props: { type: "datetime-local" } });++ await expect(component.locator("or-vaadin-date-time-picker")).toBeVisible();+ // The date and the time field are separate inputs of the picker.+ await expect(component.getByRole("combobox")).toHaveCount(2);+});++ct("should expose the picked date and time as a local ISO string", async ({ mount }) => {+ let changeCount = 0;+ const component = await mount(OrVaadinInput, {+ props: { type: "datetime-local" },+ on: {+ // The `change` CustomEvent carries no detail, so it can only be counted.+ change: () => {+ changeCount += 1;+ },+ },+ });++ // Typed dates follow the date format of the browser locale, so the date is set through the local ISO value instead.+ await component.evaluate((el: OrVaadinInput) => el.setAttribute("value", "2026-01-02T10:30"));+ const time = component.getByRole("combobox").last();+ await expect(time).toHaveValue("10:30 AM");+ await time.fill("11:45 AM");+ await time.press("Enter");++ await expect.poll(() => component.evaluate((el: OrVaadinInput) => el.nativeValue)).toBe("2026-01-02T11:45");+ // Setting the value does not count as a change, only the picked time does.+ await expect.poll(() => changeCount).toBe(1);+});diff --git a/ui/component/or-vaadin-components/test/value-input-provider.test.ts b/ui/component/or-vaadin-components/test/value-input-provider.test.tsnew file mode 100644index 000000000..880414e3a--- /dev/null+++ b/ui/component/or-vaadin-components/test/value-input-provider.test.ts@@ -0,0 +1,162 @@+/*+ * Copyright 2026, OpenRemote Inc.+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License as+ * published by the Free Software Foundation, either version 3 of the+ * License, or (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <https://www.gnu.org/licenses/>.+ *+ * SPDX-License-Identifier: AGPL-3.0-or-later+ */+import { ct, expect } from "./fixtures";++import { ValueInputProviderHarness } from "./fixtures/value-input-provider-harness.js";++// The picker shows local time in the format of the browser locale, so both are pinned for the expected values.+ct.use({ timezoneId: "Europe/Amsterdam", locale: "en-US" });++/** Returns the timestamp of a local time on 2026-01-02 in Europe/Amsterdam (UTC+1). */+function localTime(hours: number, minutes: number, seconds = 0, milliseconds = 0): number {+ return Date.UTC(2026, 0, 2, hours - 1, minutes, seconds, milliseconds);+}++// Every date and time value type (durations excluded), with the conversion of a timestamp to the JSON representation of+// that type. WellknownValueTypes names are inlined to keep @openremote/model out of the Node test body.+const DATE_TIME_VALUE_TYPES = [+ { valueType: "timestamp", toValue: (timestamp: number) => timestamp },+ { valueType: "timestampISO8601", toValue: (timestamp: number) => new Date(timestamp).toISOString() },+ { valueType: "dateAndTime", toValue: (timestamp: number) => timestamp },+];++for (const { valueType, toValue } of DATE_TIME_VALUE_TYPES) {+ ct.describe(`Date time input for ${valueType}`, () => {+ ct(+ "should show the value as local date and time and write back the edited value",+ async ({ mount, vaadinDateTimePicker }) => {+ const values: unknown[] = [];+ const component = await mount(ValueInputProviderHarness, {+ props: { valueType, value: toValue(localTime(10, 30)) },+ on: { "value-change": (value: unknown) => values.push(value) },+ });++ const timeInput = vaadinDateTimePicker.getTimeInput(component);+ await expect(vaadinDateTimePicker.getDateInput(component)).toHaveValue("01/02/2026");+ await expect(timeInput).toHaveValue("10:30 AM");+ await timeInput.fill("11:45 AM");+ await timeInput.press("Enter");++ // String types used to get a number written back, which fails their ISO 8601 pattern.+ await expect.poll(() => values).toEqual([toValue(localTime(11, 45))]);+ }+ );++ ct("should edit seconds when the value format shows seconds", async ({ mount, vaadinDateTimePicker }) => {+ const values: unknown[] = [];+ const component = await mount(ValueInputProviderHarness, {+ props: { valueType, value: toValue(localTime(10, 30, 45, 123)), format: { second: "numeric" } },+ on: { "value-change": (value: unknown) => values.push(value) },+ });++ const timeInput = vaadinDateTimePicker.getTimeInput(component);+ await expect(timeInput).toHaveValue("10:30:45 AM");+ await timeInput.fill("11:45:50 AM");+ await timeInput.press("Enter");++ await expect.poll(() => values).toEqual([toValue(localTime(11, 45, 50))]);+ });++ ct(+ "should edit milliseconds when the value format shows fractional seconds",+ async ({ mount, vaadinDateTimePicker }) => {+ const values: unknown[] = [];+ const component = await mount(ValueInputProviderHarness, {+ props: { valueType, value: toValue(localTime(10, 30, 45, 123)), format: { fractionalSecondDigits: 3 } },+ on: { "value-change": (value: unknown) => values.push(value) },+ });++ const timeInput = vaadinDateTimePicker.getTimeInput(component);+ await expect(timeInput).toHaveValue("10:30:45.123 AM");+ await timeInput.fill("11:45:50.456 AM");+ await timeInput.press("Enter");++ await expect.poll(() => values).toEqual([toValue(localTime(11, 45, 50, 456))]);+ }+ );++ ct("should write back null when the date and time are cleared", async ({ mount, vaadinDateTimePicker }) => {+ const values: unknown[] = [];+ const component = await mount(ValueInputProviderHarness, {+ props: { valueType, value: toValue(localTime(10, 30)) },+ on: { "value-change": (value: unknown) => values.push(value) },+ });++ const dateInput = vaadinDateTimePicker.getDateInput(component);+ const timeInput = vaadinDateTimePicker.getTimeInput(component);+ await dateInput.fill("");+ await dateInput.press("Enter");+ await timeInput.fill("");+ await timeInput.press("Enter");++ await expect.poll(() => values).toEqual([null]);+ });++ ct(+ "should render an empty picker for a value that is not a date and time",+ async ({ mount, vaadinDateTimePicker }) => {+ const component = await mount(ValueInputProviderHarness, {+ props: { valueType, value: "10:30:00" },+ });++ // Rendering used to throw on the invalid date, leaving no input at all.+ await expect(vaadinDateTimePicker.getDateInput(component)).toHaveValue("");+ await expect(vaadinDateTimePicker.getTimeInput(component)).toHaveValue("");+ }+ );+ });+}++ct("should edit seconds when the moment format shows seconds", async ({ mount, vaadinDateTimePicker }) => {+ const component = await mount(ValueInputProviderHarness, {+ props: { valueType: "timestamp", value: localTime(10, 30, 45), format: { momentJsFormat: "DD-MM-YYYY HH:mm:ss" } },+ });++ await expect(vaadinDateTimePicker.getTimeInput(component)).toHaveValue("10:30:45 AM");+});++ct("should show a number formatted as a date in minutes", async ({ mount, vaadinDateTimePicker }) => {+ const component = await mount(ValueInputProviderHarness, {+ props: { valueType: "long", value: localTime(10, 30, 45), format: { asDate: true } },+ });++ // The whole-number step of the number input used to reach the picker, which then showed seconds.+ await expect(vaadinDateTimePicker.getTimeInput(component)).toHaveValue("10:30 AM");+});++ct("should round up a minimum that falls between two picker values", async ({ mount, vaadinDateTimePicker }) => {+ const values: unknown[] = [];+ const component = await mount(ValueInputProviderHarness, {+ props: {+ valueType: "timestamp",+ value: localTime(11, 0),+ constraints: [{ type: "min", min: localTime(10, 30, 45) }],+ },+ on: { "value-change": (value: unknown) => values.push(value) },+ });++ const timeInput = vaadinDateTimePicker.getTimeInput(component);+ await timeInput.fill("10:30 AM");+ await timeInput.press("Enter");+ await timeInput.fill("10:31 AM");+ await timeInput.press("Enter");++ // The minimum used to round down to 10:30, which the picker then allowed although it is before the minimum.+ await expect.poll(() => values).toEqual([localTime(10, 31)]);+});diff --git a/ui/test/fixtures/data.ts b/ui/test/fixtures/data.tsindex b837e4f48..3d58bda53 100644--- a/ui/test/fixtures/data.ts+++ b/ui/test/fixtures/data.ts@@ -121,6 +121,39 @@ export const valueDescriptors = {type: "java.math.BigDecimal",jsonType: "number",},+ timestamp: {+ name: "timestamp",+ type: "java.lang.Long",+ constraints: [+ {+ type: "min",+ min: 0,+ message: "{ValueConstraint.Min.message}",+ },+ ],+ format: {+ asDate: true,+ momentJsFormat: "DD-MMM-YYYY hh:mm A",+ },+ jsonType: "number",+ },+ timestampISO8601: {+ name: "timestampISO8601",+ type: "java.lang.String",+ constraints: [+ {+ type: "pattern",+ regexp:+ "^(?:[1-9]\\d{3}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1\\d|2[0-8])|(?:0[13-9]|1[0-2])-(?:29|30)|(?:0[13578]|1[02])-31)|(?:[1-9]\\d(?:0[48]|[2468][048]|[13579][26])|(?:[2468][048]|[13579][26])00)-02-29)T(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:[\\.,]\\d{1,9})?(?:Z|[+-][01]\\d:[0-5]\\d)$",+ message: "{ValueConstraint.Pattern.message}",+ },+ ],+ format: {+ asDate: true,+ momentJsFormat: "DD-MMM-YYYY hh:mm A",+ },+ jsonType: "string",+ },agentLink: {name: "agentLink",type: "org.openremote.model.asset.agent.AgentLink",diff --git a/yarn.lock b/yarn.lockindex a72f85790..8f4dccffd 100644--- a/yarn.lock+++ b/yarn.lock@@ -2424,6 +2424,7 @@ __metadata:"@vaadin/text-field": "npm:~25.2.11""@vaadin/time-picker": "npm:~25.2.11""@vaadin/vaadin-themable-mixin": "npm:~25.2.11"+ i18next: "npm:^21.5.3"lit: "npm:^3.3.1"languageName: unknownlinkType: soft