Freemarker Date Handling improved
git-svn-id: https://svn.libreccm.org/ccm/trunk@6092 8810af33-2d31-482b-a856-94f89814c4dfmaster
parent
433b246cfa
commit
3a89139105
|
|
@ -498,10 +498,10 @@ public class FreeMarkerPresentationManager implements PresentationManager {
|
||||||
.get(2))
|
.get(2))
|
||||||
.getAsNumber()
|
.getAsNumber()
|
||||||
.intValue();
|
.intValue();
|
||||||
final int dayOfMonth = ((TemplateNumberModel) list
|
final int dayOfMonth = fixDayOfMonth(
|
||||||
.get(3))
|
((TemplateNumberModel) list.get(3)).getAsNumber().intValue(),
|
||||||
.getAsNumber()
|
month,
|
||||||
.intValue();
|
year);
|
||||||
final int hour = ((TemplateNumberModel) list
|
final int hour = ((TemplateNumberModel) list
|
||||||
.get(4))
|
.get(4))
|
||||||
.getAsNumber()
|
.getAsNumber()
|
||||||
|
|
@ -530,6 +530,42 @@ public class FreeMarkerPresentationManager implements PresentationManager {
|
||||||
return formatter.format(localDateTime);
|
return formatter.format(localDateTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int fixDayOfMonth(final int dayOfMonth,
|
||||||
|
final int month,
|
||||||
|
final int year) {
|
||||||
|
|
||||||
|
// Febrary is the most complex
|
||||||
|
if (month == 2) {
|
||||||
|
if (year % 4 == 0 && year % 400 == 0) {
|
||||||
|
if (dayOfMonth > 29) {
|
||||||
|
return 29;
|
||||||
|
} else {
|
||||||
|
return dayOfMonth;
|
||||||
|
}
|
||||||
|
} else if (year % 4 == 0 && year % 100 != 0) {
|
||||||
|
if (dayOfMonth > 29) {
|
||||||
|
return 29;
|
||||||
|
} else {
|
||||||
|
return dayOfMonth;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (dayOfMonth > 28) {
|
||||||
|
return 28;
|
||||||
|
} else {
|
||||||
|
return dayOfMonth;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (month == 4 || month == 6 || month == 9 || month == 11) {
|
||||||
|
if (dayOfMonth > 30) {
|
||||||
|
return 30;
|
||||||
|
} else {
|
||||||
|
return dayOfMonth;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return dayOfMonth;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private Optional<String> findFormat(
|
private Optional<String> findFormat(
|
||||||
final List<DateFormat> dateFormats,
|
final List<DateFormat> dateFormats,
|
||||||
final String style,
|
final String style,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue