This is an automated email from the ASF dual-hosted git repository.
ahuber pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/isis.git
The following commit(s) were added to refs/heads/master by this push:
new 790c866c3a ISIS-3049: adds time-zone enabled format to tempus dominus
time picker (Wicket Viewer)
790c866c3a is described below
commit 790c866c3a068ab2e5fff75ed0b250dd9f909db7
Author: Andi Huber <[email protected]>
AuthorDate: Wed Jul 13 18:52:10 2022 +0200
ISIS-3049: adds time-zone enabled format to tempus dominus time picker
(Wicket Viewer)
- also iterate on the failing time-zone tests
---
.../isis/testdomain/value/ValueSemanticsTest.java | 54 ++++++++++++++------
.../datepicker/TextFieldWithDateTimePicker.java | 57 +++++++++++++---------
.../scalars/datepicker/_TimeFormatUtil.java | 56 +++++++++++++++++++++
3 files changed, 127 insertions(+), 40 deletions(-)
diff --git
a/regressiontests/stable-value/src/test/java/org/apache/isis/testdomain/value/ValueSemanticsTest.java
b/regressiontests/stable-value/src/test/java/org/apache/isis/testdomain/value/ValueSemanticsTest.java
index 912d95b933..ceb586d217 100644
---
a/regressiontests/stable-value/src/test/java/org/apache/isis/testdomain/value/ValueSemanticsTest.java
+++
b/regressiontests/stable-value/src/test/java/org/apache/isis/testdomain/value/ValueSemanticsTest.java
@@ -18,6 +18,9 @@
*/
package org.apache.isis.testdomain.value;
+import java.time.OffsetDateTime;
+import java.time.OffsetTime;
+import java.time.ZonedDateTime;
import java.util.Locale;
import java.util.Set;
import java.util.stream.Collectors;
@@ -25,6 +28,7 @@ import java.util.stream.Stream;
import javax.inject.Inject;
+import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.TestInstance.Lifecycle;
@@ -53,6 +57,8 @@ import
org.apache.isis.applib.value.semantics.ValueDecomposition;
import
org.apache.isis.applib.value.semantics.ValueSemanticsAbstract.PlaceholderLiteral;
import org.apache.isis.applib.value.semantics.ValueSemanticsProvider;
import org.apache.isis.applib.value.semantics.ValueSemanticsResolver;
+import org.apache.isis.commons.functional.Try;
+import org.apache.isis.commons.internal.base._Strings;
import org.apache.isis.commons.internal.collections._Sets;
import org.apache.isis.core.config.presets.IsisPresets;
import org.apache.isis.core.metamodel.consent.InteractionInitiatedBy;
@@ -205,29 +211,25 @@ class ValueSemanticsTest {
//debug
//System.err.printf("using %s trying to parse
'%s'%n", valueType.getName(), stringified);
- tester.assertValueEquals(
- example.getValue(),
- parser.parseTextRepresentation(context,
stringified),
- "parser roundtrip failed");
-/* fails on CI
+ assertValueEqualsParsedValue(context, parser,
stringified, "parser roundtrip failed");
+
if(valueType.equals(OffsetDateTime.class)
|| valueType.equals(OffsetTime.class)
|| valueType.equals(ZonedDateTime.class)) {
+ /* fails on CI !? ... */
+
+ val with4digitZone =
_Strings.substring(stringified, 0, -6) + "+0200";
+ val with2digitZone =
_Strings.substring(stringified, 0, -6) + "+02";
+
// test alternative time-zone format with 4
digits +-HHmm
- tester.assertValueEquals(
- example.getValue(),
- parser.parseTextRepresentation(context,
-
_Strings.substring(stringified, 0, -6) + "+0200"),
- "parser roundtrip failed (alternative
time-zone format with 4 digits +-HHmm)");
+ assertValueEqualsParsedValue(context, parser,
with4digitZone, "parser roundtrip failed "
+ + "(alternative time-zone format with
4 digits +-HHmm)");
// test alternative time-zone format with 2
digits +-HH
- tester.assertValueEquals(
- example.getValue(),
- parser.parseTextRepresentation(context,
-
_Strings.substring(stringified, 0, -6) + "+02"),
- "parser roundtrip failed (alternative
time-zone format with 2 digits +-HH)");
- }*/
+ assertValueEqualsParsedValue(context, parser,
with2digitZone, "parser roundtrip failed "
+ + "(alternative time-zone format with
2 digits +-HH)");
+ }
}
}
@@ -263,6 +265,26 @@ class ValueSemanticsTest {
// CommandDtoUtils.toXml(
// command.getCommandDto()));
}
+
+ private void assertValueEqualsParsedValue(
+ final ValueSemanticsProvider.Context context,
+ final Parser<T> parser,
+ final String textRepresentation,
+ final String failureMessage) {
+
+ val parsedValue = Try.call(()->
+ parser.parseTextRepresentation(context,
textRepresentation));
+
+ if(parsedValue.isFailure()) {
+ Assertions.fail(failureMessage,
parsedValue.getFailure().get());
+ }
+
+ tester.assertValueEquals(
+ example.getValue(),
+ parsedValue.getValue().orElse(null),
+ failureMessage);
+ }
+
});
}
diff --git
a/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/scalars/datepicker/TextFieldWithDateTimePicker.java
b/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/scalars/datepicker/TextFieldWithDateTimePicker.java
index f990284427..3eecf541ff 100644
---
a/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/scalars/datepicker/TextFieldWithDateTimePicker.java
+++
b/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/scalars/datepicker/TextFieldWithDateTimePicker.java
@@ -36,6 +36,8 @@ import org.apache.wicket.util.convert.IConverter;
import org.apache.isis.core.runtime.context.IsisAppCommonContext;
import
org.apache.isis.viewer.wicket.model.converter.ConverterBasedOnValueSemantics;
+import lombok.val;
+
import de.agilecoders.wicket.core.util.Attributes;
import static de.agilecoders.wicket.jquery.JQuery.$;
@@ -65,24 +67,41 @@ implements IConverter<T> {
final IConverter<T> converter) {
super(id, model, type);
-
- DateTimeConfig config = new DateTimeConfig();
-
setOutputMarkupId(true);
this.converter = converter;
+ /* debug
+ new IConverter<T>() {
+
+ @Override
+ public T convertToObject(final String value, final Locale locale)
throws ConversionException {
+ System.err.printf("convertToObject %s%n", value);
+ try {
+ val obj = converter.convertToObject(value, locale);
+ System.err.printf("convertedToObject %s%n", obj);
+ return obj;
+ } catch (Exception e) {
+ e.printStackTrace();
+ return null;
+ }
+ }
+
+ @Override
+ public String convertToString(final T value, final Locale locale) {
+ val s = converter.convertToString(value, locale);
+ System.err.printf("convertedToString %s%n", s);
+ return s;
+ }
+ };
+ */
+
+ val config = new DateTimeConfig();
+
// if this text field is for a LocalDate, then the pattern obtained
will just be a simple date format
// (with no hour/minute components).
- final String dateTimePattern =
((ConverterBasedOnValueSemantics<T>)this.converter).getEditingPattern();
- final String pattern = convertToMomentJsFormat(dateTimePattern);
- config.withFormat(pattern);
-
-// boolean patternContainsTimeComponent = pattern.contains("HH");
-// if (patternContainsTimeComponent) {
-// // no longer do this, since for sidebar actions takes up too
much real estate.
-// //config.sideBySide(true);
-// }
+ final String dateTimePattern =
((ConverterBasedOnValueSemantics<T>)converter).getEditingPattern();
+
config.withFormat(_TimeFormatUtil.convertToMomentJsFormat(dateTimePattern));
config.calendarWeeks(true);
config.useCurrent(false);
@@ -90,11 +109,8 @@ implements IConverter<T> {
// seems not to do anything...
//config.allowKeyboardNavigation(true);
- final String datePickerMinDate =
commonContext.getConfiguration().getViewer().getWicket().getDatePicker().getMinDate();
- final String datePickerMaxDate =
commonContext.getConfiguration().getViewer().getWicket().getDatePicker().getMaxDate();
-
- config.minDate(datePickerMinDate);
- config.maxDate(datePickerMaxDate);
+
config.minDate(commonContext.getConfiguration().getViewer().getWicket().getDatePicker().getMinDate());
+
config.maxDate(commonContext.getConfiguration().getViewer().getWicket().getDatePicker().getMaxDate());
config.readonly(!this.isEnabled());
this.config = config;
@@ -113,13 +129,6 @@ implements IConverter<T> {
});
}
- private String convertToMomentJsFormat(final String javaDateTimeFormat) {
- String momentJsFormat = javaDateTimeFormat;
- momentJsFormat = momentJsFormat.replace('d', 'D');
- momentJsFormat = momentJsFormat.replace('y', 'Y');
- return momentJsFormat;
- }
-
@Override
public T convertToObject(final String value, final Locale locale) {
return converter.convertToObject(value, locale);
diff --git
a/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/scalars/datepicker/_TimeFormatUtil.java
b/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/scalars/datepicker/_TimeFormatUtil.java
new file mode 100644
index 0000000000..55cf7288b1
--- /dev/null
+++
b/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/scalars/datepicker/_TimeFormatUtil.java
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.isis.viewer.wicket.ui.components.scalars.datepicker;
+
+import lombok.experimental.UtilityClass;
+
+@UtilityClass
+class _TimeFormatUtil {
+
+ /**
+ * Java time-zone formats<pre>
+ * V time-zone ID zone-id
America/Los_Angeles; Z; -08:30
+ * z time-zone name zone-name Pacific Standard
Time; PST
+ * O localized zone-offset offset-O GMT+8; GMT+08:00;
UTC-08:00;
+ * X zone-offset 'Z' for zero offset-X Z; -08; -0830;
-08:30; -083015; -08:30:15;
+ * x zone-offset offset-x +0000; -08;
-0830; -08:30; -083015; -08:30:15;
+ * Z zone-offset offset-Z +0000; -0800;
-08:00;
+ * </pre>
+ * <p>
+ * momentJs<pre>
+ * Z ZZ +12:00 Offset from UTC as +-HH:mm, +-HHmm, or Z
+ * </pre>
+ */
+ String convertToMomentJsFormat(final String javaDateTimeFormat) {
+ String momentJsFormat = javaDateTimeFormat;
+ momentJsFormat = momentJsFormat.replace('d', 'D');
+ momentJsFormat = momentJsFormat.replace('y', 'Y');
+
+ // time-zone format conversion: basically convert anything to Z or ZZ
+ momentJsFormat = momentJsFormat.replace('x', 'Z');
+ momentJsFormat = momentJsFormat.replace('X', 'Z');
+ // trim down any occurrence of ZZ* to just ZZ
+ while(momentJsFormat.contains("ZZZ")) {
+ momentJsFormat = momentJsFormat.replace("ZZZ", "ZZ");
+ }
+
+ return momentJsFormat.trim();
+ }
+
+}