Fixed locale bug.

This commit is contained in:
Christian P. MOMON 2020-01-27 15:47:43 +01:00
parent d410a7d029
commit 57c208e242
4 changed files with 38 additions and 7 deletions

View File

@ -21,6 +21,7 @@ package org.april.agirstatool.cli;
import java.io.File;
import java.sql.Connection;
import java.time.LocalDateTime;
import java.util.Locale;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.BasicConfigurator;
@ -128,6 +129,9 @@ public final class AgirStatoolCLI
}
});
// Set the locale to France is required for week alignment.
Locale.setDefault(Locale.FRANCE);
logger.info("{} AgirStatool call: {}", LocalDateTime.now(), new StringList(args).toStringSeparatedBy(" "));
// logger.info("Single connection opened with [{}].", this.url);

View File

@ -23,6 +23,7 @@ import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.Locale;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
@ -43,8 +44,8 @@ public class AgirStatoolUtils
{
private static Logger logger = LoggerFactory.getLogger(ProjectPage.class);
public static final DateTimeFormatter PATTERN_SHORTDATE = DateTimeFormatter.ofPattern("dd/MM/yyyy");
public static final DateTimeFormatter PATTERN_LONGDATE = DateTimeFormatter.ofPattern("dd/MM/yyyy hh'h'mm");
public static final DateTimeFormatter PATTERN_SHORTDATE = DateTimeFormatter.ofPattern("dd/MM/yyyy", Locale.FRANCE);
public static final DateTimeFormatter PATTERN_LONGDATE = DateTimeFormatter.ofPattern("dd/MM/yyyy hh':'mm", Locale.FRANCE);
/**
* Normalise week date.
@ -89,14 +90,14 @@ public class AgirStatoolUtils
LocalDate normalizedEnd = normaliseWeekDate(end);
LocalDate date = normaliseWeekDate(start);
int index = source.indexOf(start.format(DateTimeFormatter.ofPattern("yyyyww")));
int index = source.indexOf(toYearWeek(start));
if (index == -1)
{
index = 0;
}
while (date.isBefore(normalizedEnd) || date.isEqual(normalizedEnd))
{
String dateToken = date.format(DateTimeFormatter.ofPattern("yyyyww"));
String dateToken = toYearWeek(date);
long count;
if (index < source.size())
{
@ -145,7 +146,7 @@ public class AgirStatoolUtils
long count = 0;
while (date.isBefore(end) || date.isEqual(end))
{
String dateToken = date.format(DateTimeFormatter.ofPattern("yyyyww"));
String dateToken = toYearWeek(date);
DateCount current = source.get(dateToken);
if (current != null)
{
@ -398,4 +399,28 @@ public class AgirStatoolUtils
//
return result;
}
/**
* To year week.
*
* @param source
* the source
* @return the string
*/
public static String toYearWeek(final LocalDate source)
{
String result;
if (source == null)
{
result = null;
}
else
{
result = source.format(DateTimeFormatter.ofPattern("yyyyww", Locale.FRANCE));
}
//
return result;
}
}

View File

@ -21,6 +21,7 @@ package org.april.agirstatool.core.pages;
import java.io.IOException;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Locale;
import org.apache.commons.codec.digest.DigestUtils;
import org.april.agirstatool.charts.DateCountList;
@ -229,7 +230,7 @@ public class CreatedClosedCountChartView
LocalDate date = AgirStatoolUtils.normaliseWeekDate(start);
while (date.isBefore(normalizedEnd) || date.isEqual(normalizedEnd))
{
String label = date.format(DateTimeFormatter.ofPattern("yyyy-MMM"));
String label = date.format(DateTimeFormatter.ofPattern("yyyy-MMM", Locale.FRANCE));
result.add(label);
date = date.plusWeeks(1);
}

View File

@ -21,6 +21,7 @@ package org.april.agirstatool.core.pages;
import java.io.IOException;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Locale;
import org.apache.commons.codec.digest.DigestUtils;
import org.april.agirstatool.charts.DateCount;
@ -214,7 +215,7 @@ public class CreatedClosedDiffChartView
LocalDate date = AgirStatoolUtils.normaliseWeekDate(start);
while (date.isBefore(normalizedEnd) || date.isEqual(normalizedEnd))
{
String label = date.format(DateTimeFormatter.ofPattern("yyyy-MMM"));
String label = date.format(DateTimeFormatter.ofPattern("yyyy-MMM", Locale.FRANCE));
result.add(label);
date = date.plusWeeks(1);
}