Skip to content

Commit

Permalink
feat: Improve Data Visualizer with fixed period "Weekly (Start Sunday…
Browse files Browse the repository at this point in the history
…)" labels [2.39-DHIS2-17955-backport] (#18480)
  • Loading branch information
d-bernat authored Aug 29, 2024
1 parent 4302aa3 commit 8cefa15
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
14 changes: 13 additions & 1 deletion dhis-2/dhis-api/src/main/java/org/hisp/dhis/i18n/I18nFormat.java
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,16 @@ public String formatDateTime(Date date) {
* @param period the value to format.
*/
public String formatPeriod(Period period) {
return formatPeriod(period, false);
}

/**
* Formats a period. Returns null if value is null. Returns INVALID_DATE if formatting string is
* invalid.
*
* @param period the value to format.
*/
public String formatPeriod(Period period, boolean shortVersion) {
if (period == null) {
return null;
}
Expand Down Expand Up @@ -282,7 +292,9 @@ public String formatPeriod(Period period) {

if (isWeeklyPeriodType(periodType)) {
return String.format(
"Week %s %d-%02d-%02d - %d-%02d-%02d",
shortVersion
? "W%s %d-%02d-%02d - %d-%02d-%02d"
: "Week %s %d-%02d-%02d - %d-%02d-%02d",
week,
startDate.getYear(),
startDate.getMonth().getValue(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@
import org.hisp.dhis.period.PeriodType;
import org.hisp.dhis.period.RelativePeriodEnum;
import org.hisp.dhis.period.RelativePeriods;
import org.hisp.dhis.period.WeeklyPeriodType;
import org.hisp.dhis.period.comparator.AscendingPeriodComparator;
import org.hisp.dhis.security.acl.AclService;
import org.hisp.dhis.setting.SettingKey;
Expand Down Expand Up @@ -537,12 +536,10 @@ private DimensionalObject getDimension(

for (Period period : periods) {
String name = format != null ? format.formatPeriod(period) : null;

if (!period.getPeriodType().getName().contains(WeeklyPeriodType.NAME)) {
period.setShortName(name);
}
String shortName = format != null ? format.formatPeriod(period, true) : null;

period.setName(name);
period.setShortName(shortName);

if (!calendar.isIso8601()) {
period.setUid(getLocalPeriodIdentifier(period, calendar));
Expand Down

0 comments on commit 8cefa15

Please sign in to comment.