Skip to content

Commit

Permalink
fix: [ANDROAPP-5753] date format
Browse files Browse the repository at this point in the history
  • Loading branch information
mmmateos committed Jul 5, 2024
1 parent 514de89 commit 30e26fc
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions app/src/main/java/org/dhis2/bindings/StringExtensions.kt
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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) ?: "",
)

Expand All @@ -86,6 +87,8 @@ fun checkValueTypeValue(d2: D2, valueType: ValueType?, value: String): String {
DateUtils.timeFormat().parse(value) ?: "",
)

ValueType.PERCENTAGE -> value.toPercentage()

else -> value
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
4 changes: 2 additions & 2 deletions commons/src/main/java/org/dhis2/commons/date/DateUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 30e26fc

Please sign in to comment.