diff --git a/app/src/main/java/org/dhis2/bindings/StringExtensions.kt b/app/src/main/java/org/dhis2/bindings/StringExtensions.kt index 026140e2824..b938f7fb49e 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 diff --git a/app/src/test/java/org/dhis2/bindings/DateExtensionsTest.kt b/app/src/test/java/org/dhis2/bindings/DateExtensionsTest.kt index e5c2552dcb1..9a446af3a0b 100644 --- a/app/src/test/java/org/dhis2/bindings/DateExtensionsTest.kt +++ b/app/src/test/java/org/dhis2/bindings/DateExtensionsTest.kt @@ -7,7 +7,6 @@ import org.dhis2.commons.date.toOverdueOrScheduledUiText import org.dhis2.commons.date.toUiText import org.dhis2.commons.resources.ResourceManager import org.junit.Test -import org.mockito.Mockito.`when` import org.mockito.kotlin.doReturn import org.mockito.kotlin.mock import org.mockito.kotlin.whenever @@ -15,6 +14,8 @@ import java.text.SimpleDateFormat import java.util.Calendar import java.util.Date import java.util.Locale +import java.util.TimeZone + class DateExtensionsTest { @@ -259,7 +260,10 @@ class DateExtensionsTest { assert(date.toOverdueOrScheduledUiText(resourceManager, currentDate) == "In 3 years") } - private fun currentCalendar() = Calendar.getInstance().apply { - time = "2020-03-02T00:00:00.00Z".toDate() + private fun currentCalendar() : Calendar { + TimeZone.setDefault(TimeZone.getTimeZone("UTC")) + return Calendar.getInstance(TimeZone.getTimeZone("UTC")).apply { + time = "2020-03-02T00:00:00.00Z".toDate() + } } } 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 70f5d4a4cfa..70072fcf405 100644 --- a/commons/src/main/java/org/dhis2/commons/date/DateUtils.java +++ b/commons/src/main/java/org/dhis2/commons/date/DateUtils.java @@ -37,6 +37,7 @@ public static DateUtils getInstance() { 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 DATABASE_FORMAT_EXPRESSION_MILLIS = "yyyy-MM-dd'T'HH:mm:ss.SSS"; public Date[] getDateFromDateAndPeriod(Date date, Period period) { switch (period) { @@ -206,6 +207,11 @@ public static SimpleDateFormat databaseDateFormatNoSeconds() { return new SimpleDateFormat(DATABASE_FORMAT_EXPRESSION_NO_SECONDS, Locale.US); } + @NonNull + public static SimpleDateFormat databaseDateFormatMillis() { + return new SimpleDateFormat(DATABASE_FORMAT_EXPRESSION_MILLIS, Locale.US); + } + @NonNull public static Boolean dateHasNoSeconds(String dateTime) { try {