From 10074ded32686a12635f347b05f5ebc19dcec4d8 Mon Sep 17 00:00:00 2001 From: foralost Date: Sun, 25 Feb 2024 13:45:33 +0100 Subject: [PATCH 1/2] UTC Calendar fix --- .../org/isoron/uhabits/core/utils/DateUtilsTest.kt | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/uhabits-core/src/jvmTest/java/org/isoron/uhabits/core/utils/DateUtilsTest.kt b/uhabits-core/src/jvmTest/java/org/isoron/uhabits/core/utils/DateUtilsTest.kt index 19534a5bd..2834bcfc4 100644 --- a/uhabits-core/src/jvmTest/java/org/isoron/uhabits/core/utils/DateUtilsTest.kt +++ b/uhabits-core/src/jvmTest/java/org/isoron/uhabits/core/utils/DateUtilsTest.kt @@ -120,10 +120,16 @@ class DateUtilsTest : BaseUnitTest() { @Test fun getWeekdaysInMonth() { - val february = GregorianCalendar(2018, Calendar.FEBRUARY, 1) - val leapFebruary = GregorianCalendar(2020, Calendar.FEBRUARY, 1) - val month = GregorianCalendar(2020, Calendar.APRIL, 1) - val longMonth = GregorianCalendar(2020, Calendar.AUGUST, 1) + fun getCalendarUTC(year: Int, month: Int, dayOfMonth: Int): GregorianCalendar { + val gregCalendar = GregorianCalendar(year, month, dayOfMonth) + gregCalendar.timeZone = TimeZone.getTimeZone("UTC") + return gregCalendar + } + + val february = getCalendarUTC(2018, Calendar.FEBRUARY, 1) + val leapFebruary = getCalendarUTC(2020, Calendar.FEBRUARY, 1) + val month = getCalendarUTC(2020, Calendar.APRIL, 1) + val longMonth = getCalendarUTC(2020, Calendar.AUGUST, 1) assertThat( arrayOf(4, 4, 4, 4, 4, 4, 4), From 7f6248123c5ff2a4ad23d597f0b85214afdd0e07 Mon Sep 17 00:00:00 2001 From: "Alinson S. Xavier" Date: Thu, 4 Apr 2024 21:55:01 -0500 Subject: [PATCH 2/2] DateUtilsTest: Simplify getCalendarUTC --- .../java/org/isoron/uhabits/core/utils/DateUtilsTest.kt | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/uhabits-core/src/jvmTest/java/org/isoron/uhabits/core/utils/DateUtilsTest.kt b/uhabits-core/src/jvmTest/java/org/isoron/uhabits/core/utils/DateUtilsTest.kt index 2834bcfc4..8969e414f 100644 --- a/uhabits-core/src/jvmTest/java/org/isoron/uhabits/core/utils/DateUtilsTest.kt +++ b/uhabits-core/src/jvmTest/java/org/isoron/uhabits/core/utils/DateUtilsTest.kt @@ -120,11 +120,10 @@ class DateUtilsTest : BaseUnitTest() { @Test fun getWeekdaysInMonth() { - fun getCalendarUTC(year: Int, month: Int, dayOfMonth: Int): GregorianCalendar { - val gregCalendar = GregorianCalendar(year, month, dayOfMonth) - gregCalendar.timeZone = TimeZone.getTimeZone("UTC") - return gregCalendar - } + fun getCalendarUTC(year: Int, month: Int, dayOfMonth: Int) = + GregorianCalendar(year, month, dayOfMonth).apply { + timeZone = TimeZone.getTimeZone("UTC") + } val february = getCalendarUTC(2018, Calendar.FEBRUARY, 1) val leapFebruary = getCalendarUTC(2020, Calendar.FEBRUARY, 1)