mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-09-30 01:16:40 +00:00
Integrated different event date formattings based on locales
This commit is contained in:
@@ -45,5 +45,13 @@
|
||||
<inherits name="com.sap.sailing.gwt.ui.SourceLeaderboard"/>
|
||||
<inherits name='com.sap.sse.gwt.CommonControlCSS'/>
|
||||
|
||||
<replace-with class="com.sap.sailing.gwt.home.shared.utils.dateformatter.CustomEventDatesFormatter">
|
||||
<when-type-is class="com.sap.sailing.gwt.home.shared.utils.dateformatter.DefaultEventDatesFormatter"/>
|
||||
<any>
|
||||
<when-property-is name="locale" value="en"/>
|
||||
<when-property-is name="locale" value="de"/>
|
||||
</any>
|
||||
</replace-with>
|
||||
|
||||
<entry-point class="com.sap.sailing.gwt.home.shared.SwitchingEntryPoint" />
|
||||
</module>
|
||||
|
||||
+7
-42
@@ -2,7 +2,8 @@ package com.sap.sailing.gwt.home.shared.utils;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import com.google.gwt.i18n.client.DateTimeFormat;
|
||||
import com.google.gwt.core.client.GWT;
|
||||
import com.sap.sailing.gwt.home.shared.utils.dateformatter.DefaultEventDatesFormatter;
|
||||
|
||||
/**
|
||||
* Formatter for event dates and date ranges
|
||||
@@ -10,50 +11,14 @@ import com.google.gwt.i18n.client.DateTimeFormat;
|
||||
*
|
||||
*/
|
||||
public class EventDatesFormatterUtil {
|
||||
private final static DateTimeFormat dayFormat = DateTimeFormat.getFormat("dd");
|
||||
private final static DateTimeFormat dayAndMonthFormat = DateTimeFormat.getFormat("MMMM dd");
|
||||
private final static DateTimeFormat monthFormat = DateTimeFormat.getFormat("MMMM");
|
||||
private final static DateTimeFormat yearFormat = DateTimeFormat.getFormat("yyyy");
|
||||
|
||||
|
||||
private final static DefaultEventDatesFormatter FORMATTER = GWT.create(DefaultEventDatesFormatter.class);
|
||||
|
||||
public static String formatDateRangeWithYear(Date from, Date to) {
|
||||
final String result;
|
||||
final String fromMonth = monthFormat.format(from);
|
||||
final String toMonth = monthFormat.format(to);
|
||||
if (fromMonth.equals(toMonth)) {
|
||||
// same month
|
||||
final String fromDay = dayFormat.format(from);
|
||||
final String toDay = dayFormat.format(to);
|
||||
if (fromDay.equals(toDay)) {
|
||||
// same day
|
||||
result = fromMonth + " " + fromDay + ", " + yearFormat.format(from);
|
||||
} else {
|
||||
result = fromMonth + " " + fromDay + " - " + toDay + ", "
|
||||
+ yearFormat.format(from);
|
||||
}
|
||||
} else {
|
||||
result = dayAndMonthFormat.format(from) + " - " + dayAndMonthFormat.format(to) + ", "
|
||||
+ yearFormat.format(from);
|
||||
}
|
||||
return result;
|
||||
return FORMATTER.formatDateRangeWithYear(from, to);
|
||||
}
|
||||
|
||||
public static String formatDateRangeWithoutYear(Date from, Date to) {
|
||||
final String result;
|
||||
final String fromMonth = monthFormat.format(from);
|
||||
final String toMonth = monthFormat.format(to);
|
||||
if (fromMonth.equals(toMonth)) {
|
||||
// same month
|
||||
final String fromDay = dayFormat.format(from);
|
||||
final String toDay = dayFormat.format(to);
|
||||
if (fromDay.equals(toDay)) {
|
||||
// same day
|
||||
result = fromMonth + " " + fromDay;
|
||||
} else {
|
||||
result = fromMonth + " " + fromDay + " - " + toDay;
|
||||
}
|
||||
} else {
|
||||
result = dayAndMonthFormat.format(from) + " - " + dayAndMonthFormat.format(to);
|
||||
}
|
||||
return result;
|
||||
return FORMATTER.formatDateRangeWithoutYear(from, to);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user