Commit d4bc885f authored by Marijan Milicevic's avatar Marijan Milicevic Committed by Jeroen Hoffman

CMS-11068 [back port to 11.2] Error in calendardate field in hippo

- fix date format printing

(cherry picked from commit 49a6d0c8)
parent 02c13808
/*
* Copyright 2016 Hippo B.V. (http://www.onehippo.com)
* Copyright 2016-2018 Hippo B.V. (http://www.onehippo.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -32,7 +32,16 @@ public class DateTimeLabel extends Label {
public DateTimeLabel(final String id, final IModel<Date> model, final FormatStyle style) {
super(id, new DateTimePrinterModel(model, printer -> printer.print(style)));
}
public DateTimeLabel(final String id, final IModel<Date> model, final FormatStyle dateStyle, final FormatStyle timeStyle, final boolean dateOnly) {
super(id, new DateTimePrinterModel(model, printer -> {
if (dateOnly) {
return printer.printDate(dateStyle);
} else {
return printer.print(dateStyle, timeStyle);
}
}));
}
public DateTimeLabel(final String id, final IModel<Date> model, final FormatStyle dateStyle, final FormatStyle timeStyle) {
super(id, new DateTimePrinterModel(model, printer -> printer.print(dateStyle, timeStyle)));
}
......@@ -46,7 +55,6 @@ public class DateTimeLabel extends Label {
}
private static class DateTimePrinterModel extends AbstractReadOnlyModel<String> {
private final IModel<Date> dateModel;
private final Printer printer;
......
/*
* Copyright 2016 Hippo B.V. (http://www.onehippo.com)
* Copyright 2016-2018 Hippo B.V. (http://www.onehippo.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -38,6 +38,7 @@ public interface DateTimePrinter extends IClusterable {
/**
* Print with default style (medium-short).
*
* @return the date as a string formatted in default style
*/
String print();
......@@ -45,6 +46,7 @@ public interface DateTimePrinter extends IClusterable {
/**
* Print with specified pattern. See <a href="https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html#patterns">patterns</a>
* for all pattern options.
*
* @param pattern the pattern to use, not null
* @return the date as a string based on the pattern
*/
......@@ -53,14 +55,24 @@ public interface DateTimePrinter extends IClusterable {
/**
* Print with specified FormatStyle. Check <a href="https://docs.oracle.com/javase/8/docs/api/java/time/format/FormatStyle.html">here</a>
* for all possible styles. The specified style will be used for both the date and the time part.
*
* @param style the formatter style to obtain, not null
* @return the date as a string based on the style
*/
String print(final FormatStyle style);
/**
* Print with specified FormatStyle. Check <a href="https://docs.oracle.com/javase/8/docs/api/java/time/format/FormatStyle.html">here</a>
* for all possible styles. The specified style will be used for date only
*
* @param style the formatter style to obtain, not null
* @return the date as a string based on the style
*/
String printDate(final FormatStyle style);
/**
* Print with specified FormatStyles. Check <a href="https://docs.oracle.com/javase/8/docs/api/java/time/format/FormatStyle.html">here</a>
* for all possible styles. The dateStyle will be used for the date part, the timeStyle for the time part.
*
* @param dateStyle the formatter style to use for the date part, not null
* @param timeStyle the formatter style to use for the time part, not null
* @return the date as a string based the both styles
......@@ -71,6 +83,7 @@ public interface DateTimePrinter extends IClusterable {
* Append an explanatory string to the printed date if it is in Daylight Saving Time.
* Java shifts the time zone +1 if a date is in DST (e.g. CET becomes CEST), so to avoid confusion we add
* a description after the time zone (e.g. " (DST)" in English).
*
* @return the DateTimePrinter instance
*/
DateTimePrinter appendDST();
......@@ -132,6 +145,11 @@ public interface DateTimePrinter extends IClusterable {
return print(style, style);
}
@Override
public String printDate(final FormatStyle style) {
return print(DateTimeFormatter.ofLocalizedDate(style));
}
@Override
public String print(final FormatStyle dateStyle, final FormatStyle timeStyle) {
return print(DateTimeFormatter.ofLocalizedDateTime(dateStyle, timeStyle));
......@@ -174,6 +192,11 @@ public interface DateTimePrinter extends IClusterable {
return print();
}
@Override
public String printDate(final FormatStyle style) {
return print();
}
@Override
public String print(final FormatStyle dateStyle, final FormatStyle timeStyle) {
return print();
......
/*
* Copyright 2016 Hippo B.V. (http://www.onehippo.com)
* Copyright 2016-2018 Hippo B.V. (http://www.onehippo.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -31,6 +31,7 @@ import org.apache.wicket.model.IModel;
* Label component that represents only the date (year-month-day) of the
* {@link ZonedDateTime} model object in current session locale format.
*/
@Deprecated
public class ZonedDateLabel extends Label {
public ZonedDateLabel(final String id, final IModel<ZonedDateTime> model, final FormatStyle dateStyle) {
......
......@@ -58,20 +58,20 @@ public class YuiDateTimeField extends DateTimeField {
private final YuiDatePickerSettings settings;
private boolean todayLinkVisible = true;
private boolean hideTime;
private final boolean hideTime;
public YuiDateTimeField(final String id, final IModel<Date> model) {
this(id, model, null);
}
public YuiDateTimeField(final String id, final IModel<Date> model, YuiDatePickerSettings settings, boolean hideTime) {
this(id, model, settings);
this.hideTime = hideTime;
}
public YuiDateTimeField(final String id, final IModel<Date> model, YuiDatePickerSettings settings) {
super(id, model);
this(id, model, settings, false);
}
public YuiDateTimeField(final String id, final IModel<Date> model, YuiDatePickerSettings settings, final boolean hideTime) {
super(id, model);
this.hideTime = hideTime;
if (settings == null) {
settings = new YuiDatePickerSettings();
settings.setLanguage(getLocale().getLanguage());
......
......@@ -64,9 +64,8 @@ public class DatePickerPlugin extends RenderPlugin<Date> {
}
private Label newLabel(final IModel<Date> valueModel) {
final boolean isHideTime = getPluginConfig().getAsBoolean(DateFieldWidget.CONFIG_HIDE_TIME, false);
return isHideTime ? new DateTimeLabel(VALUE, valueModel, "MMMM, dd yyyy") :
new DateTimeLabel(VALUE, valueModel, FormatStyle.LONG, FormatStyle.SHORT);
final boolean dateOnly = getPluginConfig().getAsBoolean(DateFieldWidget.CONFIG_HIDE_TIME, false);
return new DateTimeLabel(VALUE, valueModel, FormatStyle.LONG, FormatStyle.SHORT, dateOnly);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment