You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openmeetings.apache.org by so...@apache.org on 2020/05/07 02:55:38 UTC
[openmeetings] branch master updated: [OPENMEETINGS-2334] fr-CA
date-time parsing/formatting should work
This is an automated email from the ASF dual-hosted git repository.
solomax pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/openmeetings.git
The following commit(s) were added to refs/heads/master by this push:
new 128a145 [OPENMEETINGS-2334] fr-CA date-time parsing/formatting should work
128a145 is described below
commit 128a145366def0f4b53a840a29256e50a6bf0988
Author: Maxim Solodovnik <so...@gmail.com>
AuthorDate: Thu May 7 09:55:00 2020 +0700
[OPENMEETINGS-2334] fr-CA date-time parsing/formatting should work
---
.../web/common/AbstractOmDateTimePicker.java | 21 ++++++++++++++++++---
.../org/apache/openmeetings/util/TestDateTime.java | 13 +++++++++++++
2 files changed, 31 insertions(+), 3 deletions(-)
diff --git a/openmeetings-web/src/main/java/org/apache/openmeetings/web/common/AbstractOmDateTimePicker.java b/openmeetings-web/src/main/java/org/apache/openmeetings/web/common/AbstractOmDateTimePicker.java
index 062da09..96450c2 100644
--- a/openmeetings-web/src/main/java/org/apache/openmeetings/web/common/AbstractOmDateTimePicker.java
+++ b/openmeetings-web/src/main/java/org/apache/openmeetings/web/common/AbstractOmDateTimePicker.java
@@ -20,6 +20,7 @@ package org.apache.openmeetings.web.common;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
+import java.util.Locale;
import org.apache.openmeetings.web.app.WebSession;
import org.apache.wicket.model.IModel;
@@ -41,7 +42,7 @@ public abstract class AbstractOmDateTimePicker<T> extends AbstractDateTimePicker
public AbstractOmDateTimePicker(String id, IModel<T> model, String format) {
super(id, model, new DatetimePickerConfig()
//.useLocale(WebSession.get().getLocale().toLanguageTag())
- .withFormat(format)
+ .withFormat(patch(format))
.with(new DatetimePickerIconConfig()
.useDateIcon(FontAwesome5IconType.calendar_s)
.useTimeIcon(FontAwesome5IconType.clock_s)
@@ -56,8 +57,18 @@ public abstract class AbstractOmDateTimePicker<T> extends AbstractDateTimePicker
setRenderBodyOnly(false);
}
+ public static String patch(String format) {
+ // in Java free text is escaped with single-quotes
+ // moment.js uses []
+ return format.replaceFirst("(.*)([']{1}(.*)[']{1})(.*)", "$1\\[$3\\]$4");
+ }
+
public static String getDateTimeFormat() {
- DateFormat fmt = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, WebSession.get().getLocale());
+ return getDateTimeFormat(WebSession.get().getLocale());
+ }
+
+ public static String getDateTimeFormat(Locale loc) {
+ DateFormat fmt = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT, loc);
if (fmt instanceof SimpleDateFormat) {
return ((SimpleDateFormat)fmt).toPattern();
}
@@ -65,7 +76,11 @@ public abstract class AbstractOmDateTimePicker<T> extends AbstractDateTimePicker
}
public static String getDateFormat() {
- DateFormat fmt = DateFormat.getDateInstance(DateFormat.SHORT, WebSession.get().getLocale());
+ return getDateFormat(WebSession.get().getLocale());
+ }
+
+ public static String getDateFormat(Locale loc) {
+ DateFormat fmt = DateFormat.getDateInstance(DateFormat.SHORT, loc);
if (fmt instanceof SimpleDateFormat) {
return ((SimpleDateFormat)fmt).toPattern();
}
diff --git a/openmeetings-web/src/test/java/org/apache/openmeetings/util/TestDateTime.java b/openmeetings-web/src/test/java/org/apache/openmeetings/util/TestDateTime.java
index ac9120d..a5f5c32 100644
--- a/openmeetings-web/src/test/java/org/apache/openmeetings/util/TestDateTime.java
+++ b/openmeetings-web/src/test/java/org/apache/openmeetings/util/TestDateTime.java
@@ -29,6 +29,7 @@ import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
+import org.apache.openmeetings.web.common.AbstractOmDateTimePicker;
import org.junit.jupiter.api.Test;
public class TestDateTime {
@@ -73,4 +74,16 @@ public class TestDateTime {
.toFormatter(Locale.ENGLISH);
assertNotNull(formatter1.parse(jsDateStr));
}
+
+ @Test
+ public void test3() throws Exception {
+ final Locale loc = new Locale.Builder()
+ .setLanguage("fr")
+ .setRegion("CA")
+ .build();
+ String format = AbstractOmDateTimePicker.getDateTimeFormat(loc);
+ assertEquals("yy-MM-dd HH [h] mm", AbstractOmDateTimePicker.patch(format));
+ format = AbstractOmDateTimePicker.getDateTimeFormat(Locale.ENGLISH);
+ assertEquals(format, AbstractOmDateTimePicker.patch(format));
+ }
}