From d51584c926e7906a4ebe704823d0aa633900954a Mon Sep 17 00:00:00 2001 From: manu Date: Wed, 3 Jul 2024 15:54:28 +0200 Subject: [PATCH] fix: [ANDROAPP-5753] date format --- app/src/main/java/org/dhis2/bindings/StringExtensions.kt | 4 ++-- .../dataSetTable/dataSetSection/MapFieldValueToUser.kt | 2 +- .../teiProgramList/TeiProgramListRepositoryImpl.java | 5 +---- .../java/org/dhis2/commons/bindings/ValueExtensions.kt | 7 +++++-- .../src/main/java/org/dhis2/commons/date/DateExtensions.kt | 2 +- .../src/main/java/org/dhis2/commons/date/DateUtils.java | 4 ++-- .../java/org/dhis2/commons/resources/DhisPeriodUtils.kt | 2 +- 7 files changed, 13 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/org/dhis2/bindings/StringExtensions.kt b/app/src/main/java/org/dhis2/bindings/StringExtensions.kt index 026140e2824..9e2dd7797f5 100644 --- a/app/src/main/java/org/dhis2/bindings/StringExtensions.kt +++ b/app/src/main/java/org/dhis2/bindings/StringExtensions.kt @@ -1,8 +1,8 @@ package org.dhis2.bindings import android.content.Context +import org.dhis2.commons.date.DateUtils import org.dhis2.commons.date.toDateSpan -import org.dhis2.utils.DateUtils import timber.log.Timber import java.util.Date @@ -38,7 +38,7 @@ fun String.toDate(): Date { } if (date == null) { try { - date = DateUtils.databaseDateFormatMillis().parse(this) + date = DateUtils.databaseDateFormat().parse(this) } catch (e: Exception) { Timber.d("wrong format") } diff --git a/app/src/main/java/org/dhis2/usescases/datasets/dataSetTable/dataSetSection/MapFieldValueToUser.kt b/app/src/main/java/org/dhis2/usescases/datasets/dataSetTable/dataSetSection/MapFieldValueToUser.kt index ea27653e452..b122f9478f5 100644 --- a/app/src/main/java/org/dhis2/usescases/datasets/dataSetTable/dataSetSection/MapFieldValueToUser.kt +++ b/app/src/main/java/org/dhis2/usescases/datasets/dataSetTable/dataSetSection/MapFieldValueToUser.kt @@ -2,9 +2,9 @@ package org.dhis2.usescases.datasets.dataSetTable.dataSetSection import org.dhis2.R import org.dhis2.bindings.toDate +import org.dhis2.commons.date.DateUtils import org.dhis2.commons.resources.ResourceManager import org.dhis2.data.forms.dataentry.tablefields.FieldViewModel -import org.dhis2.utils.DateUtils import org.hisp.dhis.android.core.common.ValueType import org.hisp.dhis.android.core.dataelement.DataElement diff --git a/app/src/main/java/org/dhis2/usescases/teiDashboard/teiProgramList/TeiProgramListRepositoryImpl.java b/app/src/main/java/org/dhis2/usescases/teiDashboard/teiProgramList/TeiProgramListRepositoryImpl.java index 973e128a509..ece43b5b34a 100644 --- a/app/src/main/java/org/dhis2/usescases/teiDashboard/teiProgramList/TeiProgramListRepositoryImpl.java +++ b/app/src/main/java/org/dhis2/usescases/teiDashboard/teiProgramList/TeiProgramListRepositoryImpl.java @@ -2,20 +2,17 @@ import androidx.annotation.NonNull; -import org.dhis2.R; +import org.dhis2.commons.date.DateUtils; import org.dhis2.commons.resources.MetadataIconProvider; -import org.dhis2.commons.resources.ResourceManager; import org.dhis2.usescases.main.program.ProgramDownloadState; import org.dhis2.usescases.main.program.ProgramViewModel; import org.dhis2.usescases.main.program.ProgramViewModelMapper; -import org.dhis2.utils.DateUtils; import org.hisp.dhis.android.core.D2; import org.hisp.dhis.android.core.common.State; import org.hisp.dhis.android.core.enrollment.EnrollmentCreateProjection; import org.hisp.dhis.android.core.enrollment.EnrollmentStatus; import org.hisp.dhis.android.core.organisationunit.OrganisationUnit; import org.hisp.dhis.android.core.program.Program; -import org.hisp.dhis.mobile.ui.designsystem.theme.SurfaceColor; import java.util.ArrayList; import java.util.Collections; diff --git a/commons/src/main/java/org/dhis2/commons/bindings/ValueExtensions.kt b/commons/src/main/java/org/dhis2/commons/bindings/ValueExtensions.kt index 85c0602f01b..48586b7653b 100644 --- a/commons/src/main/java/org/dhis2/commons/bindings/ValueExtensions.kt +++ b/commons/src/main/java/org/dhis2/commons/bindings/ValueExtensions.kt @@ -1,6 +1,7 @@ package org.dhis2.bindings import org.dhis2.commons.date.DateUtils +import org.dhis2.commons.extensions.toPercentage import org.hisp.dhis.android.core.D2 import org.hisp.dhis.android.core.common.ValueType import org.hisp.dhis.android.core.trackedentity.TrackedEntityAttributeValue @@ -71,13 +72,13 @@ fun checkValueTypeValue(d2: D2, valueType: ValueType?, value: String): String { ValueType.IMAGE, ValueType.FILE_RESOURCE -> d2.fileResourceModule().fileResources().uid(value).blockingGet()?.path() ?: "" - ValueType.DATE -> + ValueType.DATE, ValueType.AGE -> DateUtils.uiDateFormat().format( DateUtils.oldUiDateFormat().parse(value) ?: "", ) ValueType.DATETIME -> - DateUtils.dateTimeFormat().format( + DateUtils.uiDateTimeFormat().format( DateUtils.databaseDateFormatNoSeconds().parse(value) ?: "", ) @@ -86,6 +87,8 @@ fun checkValueTypeValue(d2: D2, valueType: ValueType?, value: String): String { DateUtils.timeFormat().parse(value) ?: "", ) + ValueType.PERCENTAGE -> value.toPercentage() + else -> value } } diff --git a/commons/src/main/java/org/dhis2/commons/date/DateExtensions.kt b/commons/src/main/java/org/dhis2/commons/date/DateExtensions.kt index 17b532a4464..e8e0275fed9 100644 --- a/commons/src/main/java/org/dhis2/commons/date/DateExtensions.kt +++ b/commons/src/main/java/org/dhis2/commons/date/DateExtensions.kt @@ -155,4 +155,4 @@ private fun getString( } fun Date?.toUi(): String? = - this?.let { SimpleDateFormat("d/M/yyyy", Locale.getDefault()).format(this) } + this?.let { DateUtils.uiDateFormat().format(this) } diff --git a/commons/src/main/java/org/dhis2/commons/date/DateUtils.java b/commons/src/main/java/org/dhis2/commons/date/DateUtils.java index 542380e0ed8..362c9b89eb3 100644 --- a/commons/src/main/java/org/dhis2/commons/date/DateUtils.java +++ b/commons/src/main/java/org/dhis2/commons/date/DateUtils.java @@ -43,10 +43,10 @@ public static DateUtils getInstance() { public static final String WEEKLY_FORMAT_EXPRESSION = "w yyyy"; public static final String MONTHLY_FORMAT_EXPRESSION = "MMM yyyy"; public static final String YEARLY_FORMAT_EXPRESSION = "yyyy"; - public static final String SIMPLE_DATE_FORMAT = "d/M/yyyy"; + public static final String SIMPLE_DATE_FORMAT = "dd/MM/yyyy"; public static final String TIME_12H_EXPRESSION = "hh:mm a"; public static final String UI_LIBRARY_FORMAT = "ddMMyyyy"; - public static final String SIMPLE_DATE_TIME_FORMAT = "d/M/yyyy HH:mm"; + public static final String SIMPLE_DATE_TIME_FORMAT = "dd/MM/yyyy - HH:mm"; public Date[] getDateFromDateAndPeriod(Date date, Period period) { switch (period) { diff --git a/commons/src/main/java/org/dhis2/commons/resources/DhisPeriodUtils.kt b/commons/src/main/java/org/dhis2/commons/resources/DhisPeriodUtils.kt index 153a851d347..a9e53c2be29 100644 --- a/commons/src/main/java/org/dhis2/commons/resources/DhisPeriodUtils.kt +++ b/commons/src/main/java/org/dhis2/commons/resources/DhisPeriodUtils.kt @@ -11,7 +11,7 @@ import java.util.regex.Pattern const val DATE_FORMAT_EXPRESSION = "yyyy-MM-dd" const val MONTHLY_FORMAT_EXPRESSION = "MMM yyyy" const val YEARLY_FORMAT_EXPRESSION = "yyyy" -const val SIMPLE_DATE_FORMAT = "d/M/yyyy" +const val SIMPLE_DATE_FORMAT = "dd/MM/yyyy" class DhisPeriodUtils( d2: D2,