mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 09:08:52 -06:00
Calendar tests for DateUtils
This commit is contained in:
@@ -37,6 +37,7 @@ import org.isoron.uhabits.core.utils.DateUtils.Companion.truncate
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import java.util.Calendar
|
||||
import java.util.GregorianCalendar
|
||||
import java.util.Locale
|
||||
import java.util.TimeZone
|
||||
|
||||
@@ -297,6 +298,45 @@ class DateUtilsTest : BaseUnitTest() {
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testGetStartOfTodayCalendar() {
|
||||
setFixedLocalTime(FIXED_LOCAL_TIME)
|
||||
setFixedLocale(Locale.GERMANY)
|
||||
val expectedStartOfDay = unixTime(2015, Calendar.JANUARY, 25, 0, 0)
|
||||
val expectedCalendar = GregorianCalendar(TimeZone.getTimeZone("GMT"), Locale.GERMANY)
|
||||
expectedCalendar.timeInMillis = expectedStartOfDay
|
||||
val startOfTodayCalendar = DateUtils.getStartOfTodayCalendar()
|
||||
assertThat(expectedCalendar, equalTo(startOfTodayCalendar))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testGetStartOfTodayCalendarWithOffset_priorToOffset() {
|
||||
val hourOffset = 3
|
||||
setStartDayOffset(hourOffset, 0)
|
||||
val priorToOffset = unixTime(2017, Calendar.JANUARY, 2, hourOffset - 1, 0)
|
||||
setFixedLocalTime(priorToOffset)
|
||||
setFixedLocale(Locale.GERMANY)
|
||||
val startOfYesterday = unixTime(2017, Calendar.JANUARY, 2, 0, 0)
|
||||
val expectedCalendar = GregorianCalendar(TimeZone.getTimeZone("GMT"), Locale.GERMANY)
|
||||
expectedCalendar.timeInMillis = startOfYesterday
|
||||
val startOfTodayCalendar = DateUtils.getStartOfTodayCalendar()
|
||||
assertThat(expectedCalendar, equalTo(startOfTodayCalendar))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testGetStartOfTodayCalendarWithOffset_afterOffset() {
|
||||
val hourOffset = 3
|
||||
setStartDayOffset(hourOffset, 0)
|
||||
val afterOffset = unixTime(2017, Calendar.JANUARY, 1, hourOffset + 1, 0)
|
||||
setFixedLocalTime(afterOffset)
|
||||
setFixedLocale(Locale.GERMANY)
|
||||
val startOfToday = unixTime(2017, Calendar.JANUARY, 1, 0, 0)
|
||||
val expectedCalendar = GregorianCalendar(TimeZone.getTimeZone("GMT"), Locale.GERMANY)
|
||||
expectedCalendar.timeInMillis = startOfToday
|
||||
val startOfTodayCalendar = DateUtils.getStartOfTodayCalendar()
|
||||
assertThat(expectedCalendar, equalTo(startOfTodayCalendar))
|
||||
}
|
||||
|
||||
@Test
|
||||
@Throws(Exception::class)
|
||||
fun testGetTodayWithOffset() {
|
||||
|
||||
Reference in New Issue
Block a user