|
|
@ -5,452 +5,372 @@
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
package com.todoroo.andlib.utility
|
|
|
|
package com.todoroo.andlib.utility
|
|
|
|
|
|
|
|
|
|
|
|
import androidx.test.core.app.ApplicationProvider
|
|
|
|
|
|
|
|
import androidx.test.ext.junit.runners.AndroidJUnit4
|
|
|
|
import androidx.test.ext.junit.runners.AndroidJUnit4
|
|
|
|
|
|
|
|
import androidx.test.platform.app.InstrumentationRegistry
|
|
|
|
|
|
|
|
import kotlinx.coroutines.runBlocking
|
|
|
|
import org.junit.After
|
|
|
|
import org.junit.After
|
|
|
|
import org.junit.Assert.assertEquals
|
|
|
|
import org.junit.Assert.assertEquals
|
|
|
|
import org.junit.Assert.assertTrue
|
|
|
|
import org.junit.Assert.assertTrue
|
|
|
|
import org.junit.Ignore
|
|
|
|
import org.junit.Ignore
|
|
|
|
import org.junit.Test
|
|
|
|
import org.junit.Test
|
|
|
|
import org.junit.runner.RunWith
|
|
|
|
import org.junit.runner.RunWith
|
|
|
|
import org.tasks.Freeze.Companion.freezeAt
|
|
|
|
import org.tasks.SuspendFreeze
|
|
|
|
|
|
|
|
import org.tasks.SuspendFreeze.Companion.freezeAt
|
|
|
|
|
|
|
|
import org.tasks.TestUtilities.withLocale
|
|
|
|
import org.tasks.date.DateTimeUtils
|
|
|
|
import org.tasks.date.DateTimeUtils
|
|
|
|
|
|
|
|
import org.tasks.extensions.Context.is24HourFormat
|
|
|
|
|
|
|
|
import org.tasks.extensions.Context.is24HourOverride
|
|
|
|
|
|
|
|
import org.tasks.kmp.formatDayOfWeek
|
|
|
|
|
|
|
|
import org.tasks.kmp.org.tasks.time.DateStyle
|
|
|
|
|
|
|
|
import org.tasks.kmp.org.tasks.time.TextStyle
|
|
|
|
|
|
|
|
import org.tasks.kmp.org.tasks.time.getRelativeDateTime
|
|
|
|
|
|
|
|
import org.tasks.kmp.org.tasks.time.getRelativeDay
|
|
|
|
|
|
|
|
import org.tasks.kmp.org.tasks.time.getTimeString
|
|
|
|
import org.tasks.time.DateTime
|
|
|
|
import org.tasks.time.DateTime
|
|
|
|
import java.time.format.FormatStyle
|
|
|
|
|
|
|
|
import java.util.Locale
|
|
|
|
import java.util.Locale
|
|
|
|
|
|
|
|
|
|
|
|
@RunWith(AndroidJUnit4::class)
|
|
|
|
@RunWith(AndroidJUnit4::class)
|
|
|
|
class DateUtilitiesTest {
|
|
|
|
class DateUtilitiesTest {
|
|
|
|
@After
|
|
|
|
@After
|
|
|
|
fun after() {
|
|
|
|
fun after() {
|
|
|
|
DateUtilities.is24HourOverride = null
|
|
|
|
is24HourOverride = null
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
fun testGet24HourTime() {
|
|
|
|
fun testGet24HourTime() {
|
|
|
|
DateUtilities.is24HourOverride = true
|
|
|
|
is24HourOverride = true
|
|
|
|
assertEquals("09:05", DateUtilities.getTimeString(ApplicationProvider.getApplicationContext(), DateTime(2014, 1, 4, 9, 5, 36)))
|
|
|
|
assertEquals("09:05", getTimeString(DateTime(2014, 1, 4, 9, 5, 36).millis, is24HourFormat))
|
|
|
|
assertEquals("13:00", DateUtilities.getTimeString(ApplicationProvider.getApplicationContext(), DateTime(2014, 1, 4, 13, 0, 1)))
|
|
|
|
assertEquals("13:00", getTimeString(DateTime(2014, 1, 4, 13, 0, 1).millis, is24HourFormat))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
fun testGetTime() {
|
|
|
|
fun testGetTime() {
|
|
|
|
DateUtilities.is24HourOverride = false
|
|
|
|
is24HourOverride = false
|
|
|
|
assertEquals("9:05 AM", DateUtilities.getTimeString(ApplicationProvider.getApplicationContext(), DateTime(2014, 1, 4, 9, 5, 36)))
|
|
|
|
assertEquals("9:05 AM", getTimeString(DateTime(2014, 1, 4, 9, 5, 36).millis, is24HourFormat))
|
|
|
|
assertEquals("1:05 PM", DateUtilities.getTimeString(ApplicationProvider.getApplicationContext(), DateTime(2014, 1, 4, 13, 5, 36)))
|
|
|
|
assertEquals("1:05 PM", getTimeString(DateTime(2014, 1, 4, 13, 5, 36).millis, is24HourFormat))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
fun testGetTimeWithNoMinutes() {
|
|
|
|
fun testGetTimeWithNoMinutes() {
|
|
|
|
DateUtilities.is24HourOverride = false
|
|
|
|
is24HourOverride = false
|
|
|
|
assertEquals("1 PM", DateUtilities.getTimeString(ApplicationProvider.getApplicationContext(), DateTime(2014, 1, 4, 13, 0, 59))) // derp?
|
|
|
|
assertEquals("1 PM", getTimeString(DateTime(2014, 1, 4, 13, 0, 59).millis, is24HourFormat)) // derp?
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
fun testGetDateStringWithYear() {
|
|
|
|
fun testGetDateStringWithYear() = runBlocking {
|
|
|
|
assertEquals("Jan 4, 2014", DateUtilities.getDateString(ApplicationProvider.getApplicationContext(), DateTime(2014, 1, 4, 0, 0, 0)))
|
|
|
|
assertEquals("Jan 4, 2014", getRelativeDay(DateTime(2014, 1, 4, 0, 0, 0).millis))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
fun testGetDateStringHidingYear() {
|
|
|
|
fun testGetDateStringHidingYear() = runBlocking {
|
|
|
|
freezeAt(DateTimeUtils.newDate(2014, 2, 1)) {
|
|
|
|
freezeAt(DateTimeUtils.newDate(2014, 2, 1)) {
|
|
|
|
assertEquals("Jan 1", DateUtilities.getDateString(ApplicationProvider.getApplicationContext(), DateTime(2014, 1, 1)))
|
|
|
|
assertEquals("Jan 1", getRelativeDay(DateTime(2014, 1, 1).millis))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
fun testGetDateStringWithDifferentYear() {
|
|
|
|
fun testGetDateStringWithDifferentYear() = runBlocking {
|
|
|
|
freezeAt(DateTimeUtils.newDate(2013, 12, 1)) {
|
|
|
|
freezeAt(DateTimeUtils.newDate(2013, 12, 1)) {
|
|
|
|
assertEquals("Jan 1, 2014", DateUtilities.getDateString(ApplicationProvider.getApplicationContext(), DateTime(2014, 1, 1, 0, 0, 0)))
|
|
|
|
assertEquals("Jan 1, 2014", getRelativeDay(DateTime(2014, 1, 1, 0, 0, 0).millis))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
fun testGetWeekdayLongString() {
|
|
|
|
fun testGetWeekdayLongString() = withLocale(Locale.US) {
|
|
|
|
assertEquals("Sunday", DateUtilities.getWeekday(DateTimeUtils.newDate(2013, 12, 29), Locale.US))
|
|
|
|
assertEquals("Sunday", formatDayOfWeek(DateTimeUtils.newDate(2013, 12, 29).millis, TextStyle.FULL))
|
|
|
|
assertEquals("Monday", DateUtilities.getWeekday(DateTimeUtils.newDate(2013, 12, 30), Locale.US))
|
|
|
|
assertEquals("Monday", formatDayOfWeek(DateTimeUtils.newDate(2013, 12, 30).millis, TextStyle.FULL))
|
|
|
|
assertEquals("Tuesday", DateUtilities.getWeekday(DateTimeUtils.newDate(2013, 12, 31), Locale.US))
|
|
|
|
assertEquals("Tuesday", formatDayOfWeek(DateTimeUtils.newDate(2013, 12, 31).millis, TextStyle.FULL))
|
|
|
|
assertEquals("Wednesday", DateUtilities.getWeekday(DateTimeUtils.newDate(2014, 1, 1), Locale.US))
|
|
|
|
assertEquals("Wednesday", formatDayOfWeek(DateTimeUtils.newDate(2014, 1, 1).millis, TextStyle.FULL))
|
|
|
|
assertEquals("Thursday", DateUtilities.getWeekday(DateTimeUtils.newDate(2014, 1, 2), Locale.US))
|
|
|
|
assertEquals("Thursday", formatDayOfWeek(DateTimeUtils.newDate(2014, 1, 2).millis, TextStyle.FULL))
|
|
|
|
assertEquals("Friday", DateUtilities.getWeekday(DateTimeUtils.newDate(2014, 1, 3), Locale.US))
|
|
|
|
assertEquals("Friday", formatDayOfWeek(DateTimeUtils.newDate(2014, 1, 3).millis, TextStyle.FULL))
|
|
|
|
assertEquals("Saturday", DateUtilities.getWeekday(DateTimeUtils.newDate(2014, 1, 4), Locale.US))
|
|
|
|
assertEquals("Saturday", formatDayOfWeek(DateTimeUtils.newDate(2014, 1, 4).millis, TextStyle.FULL))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
fun testGetWeekdayShortString() {
|
|
|
|
fun testGetWeekdayShortString() = withLocale(Locale.US) {
|
|
|
|
assertEquals("Sun", DateUtilities.getWeekdayShort(DateTimeUtils.newDate(2013, 12, 29), Locale.US))
|
|
|
|
assertEquals("Sun", formatDayOfWeek(DateTimeUtils.newDate(2013, 12, 29).millis, TextStyle.SHORT))
|
|
|
|
assertEquals("Mon", DateUtilities.getWeekdayShort(DateTimeUtils.newDate(2013, 12, 30), Locale.US))
|
|
|
|
assertEquals("Mon", formatDayOfWeek(DateTimeUtils.newDate(2013, 12, 30).millis, TextStyle.SHORT))
|
|
|
|
assertEquals("Tue", DateUtilities.getWeekdayShort(DateTimeUtils.newDate(2013, 12, 31), Locale.US))
|
|
|
|
assertEquals("Tue", formatDayOfWeek(DateTimeUtils.newDate(2013, 12, 31).millis, TextStyle.SHORT))
|
|
|
|
assertEquals("Wed", DateUtilities.getWeekdayShort(DateTimeUtils.newDate(2014, 1, 1), Locale.US))
|
|
|
|
assertEquals("Wed", formatDayOfWeek(DateTimeUtils.newDate(2014, 1, 1).millis, TextStyle.SHORT))
|
|
|
|
assertEquals("Thu", DateUtilities.getWeekdayShort(DateTimeUtils.newDate(2014, 1, 2), Locale.US))
|
|
|
|
assertEquals("Thu", formatDayOfWeek(DateTimeUtils.newDate(2014, 1, 2).millis, TextStyle.SHORT))
|
|
|
|
assertEquals("Fri", DateUtilities.getWeekdayShort(DateTimeUtils.newDate(2014, 1, 3), Locale.US))
|
|
|
|
assertEquals("Fri", formatDayOfWeek(DateTimeUtils.newDate(2014, 1, 3).millis, TextStyle.SHORT))
|
|
|
|
assertEquals("Sat", DateUtilities.getWeekdayShort(DateTimeUtils.newDate(2014, 1, 4), Locale.US))
|
|
|
|
assertEquals("Sat", formatDayOfWeek(DateTimeUtils.newDate(2014, 1, 4).millis, TextStyle.SHORT))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
fun getRelativeFullDate() {
|
|
|
|
fun getRelativeFullDate() = withLocale(Locale.US) {
|
|
|
|
freezeAt(DateTime(2018, 1, 1)) {
|
|
|
|
freezeAt(DateTime(2018, 1, 1)) {
|
|
|
|
assertEquals(
|
|
|
|
assertEquals(
|
|
|
|
"Sunday, January 14",
|
|
|
|
"Sunday, January 14",
|
|
|
|
DateUtilities.getRelativeDateTime(
|
|
|
|
getRelativeDateTime(DateTime(2018, 1, 14).millis, is24HourFormat, DateStyle.FULL)
|
|
|
|
ApplicationProvider.getApplicationContext(),
|
|
|
|
)
|
|
|
|
DateTime(2018, 1, 14).millis,
|
|
|
|
|
|
|
|
Locale.US,
|
|
|
|
|
|
|
|
FormatStyle.FULL))
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
fun getRelativeFullDateWithYear() {
|
|
|
|
fun getRelativeFullDateWithYear() = withLocale(Locale.US) {
|
|
|
|
freezeAt(DateTime(2017, 12, 12)) {
|
|
|
|
freezeAt(DateTime(2017, 12, 12)) {
|
|
|
|
assertEquals(
|
|
|
|
assertEquals(
|
|
|
|
"Sunday, January 14, 2018",
|
|
|
|
"Sunday, January 14, 2018",
|
|
|
|
DateUtilities.getRelativeDateTime(
|
|
|
|
getRelativeDateTime(DateTime(2018, 1, 14).millis, is24HourFormat, DateStyle.FULL)
|
|
|
|
ApplicationProvider.getApplicationContext(),
|
|
|
|
)
|
|
|
|
DateTime(2018, 1, 14).millis,
|
|
|
|
|
|
|
|
Locale.US,
|
|
|
|
|
|
|
|
FormatStyle.FULL))
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
fun getRelativeFullDateTime() {
|
|
|
|
fun getRelativeFullDateTime() = withLocale(Locale.US) {
|
|
|
|
freezeAt(DateTime(2018, 1, 1)) {
|
|
|
|
freezeAt(DateTime(2018, 1, 1)) {
|
|
|
|
assertMatches(
|
|
|
|
assertMatches(
|
|
|
|
"Sunday, January 14( at)? 1:43 PM",
|
|
|
|
"Sunday, January 14( at)? 1:43 PM",
|
|
|
|
DateUtilities.getRelativeDateTime(
|
|
|
|
getRelativeDateTime(DateTime(2018, 1, 14, 13, 43, 1).millis, is24HourFormat, DateStyle.FULL)
|
|
|
|
ApplicationProvider.getApplicationContext(),
|
|
|
|
)
|
|
|
|
DateTime(2018, 1, 14, 13, 43, 1).millis,
|
|
|
|
|
|
|
|
Locale.US,
|
|
|
|
|
|
|
|
FormatStyle.FULL))
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
@Ignore("Fails on CI - need to investigate")
|
|
|
|
@Ignore("Fails on CI - need to investigate")
|
|
|
|
fun getRelativeDateTimeWithAlwaysDisplayFullDateOption() {
|
|
|
|
fun getRelativeDateTimeWithAlwaysDisplayFullDateOption() = withLocale(Locale.US) {
|
|
|
|
freezeAt(DateTime(2020, 1, 1)) {
|
|
|
|
freezeAt(DateTime(2020, 1, 1)) {
|
|
|
|
assertMatches(
|
|
|
|
assertMatches(
|
|
|
|
"Thursday, January 2 at 11:50 AM",
|
|
|
|
"Thursday, January 2 at 11:50 AM",
|
|
|
|
DateUtilities.getRelativeDateTime(
|
|
|
|
getRelativeDateTime(DateTime(2020, 1, 2, 11, 50, 1).millis, is24HourFormat, DateStyle.FULL, true, false)
|
|
|
|
ApplicationProvider.getApplicationContext(),
|
|
|
|
)
|
|
|
|
DateTime(2020, 1, 2, 11, 50, 1).millis,
|
|
|
|
|
|
|
|
Locale.US,
|
|
|
|
|
|
|
|
FormatStyle.FULL,
|
|
|
|
|
|
|
|
true,
|
|
|
|
|
|
|
|
false
|
|
|
|
|
|
|
|
))
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
fun getRelativeFullDateTimeWithYear() {
|
|
|
|
fun getRelativeFullDateTimeWithYear() = withLocale(Locale.US) {
|
|
|
|
freezeAt(DateTime(2017, 12, 12)) {
|
|
|
|
freezeAt(DateTime(2017, 12, 12)) {
|
|
|
|
assertMatches(
|
|
|
|
assertMatches(
|
|
|
|
"Sunday, January 14, 2018( at)? 11:50 AM",
|
|
|
|
"Sunday, January 14, 2018( at)? 11:50 AM",
|
|
|
|
DateUtilities.getRelativeDateTime(
|
|
|
|
getRelativeDateTime(DateTime(2018, 1, 14, 11, 50, 1).millis, is24HourFormat, DateStyle.FULL)
|
|
|
|
ApplicationProvider.getApplicationContext(),
|
|
|
|
)
|
|
|
|
DateTime(2018, 1, 14, 11, 50, 1).millis,
|
|
|
|
|
|
|
|
Locale.US,
|
|
|
|
|
|
|
|
FormatStyle.FULL))
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
fun getRelativeDayWithAlwaysDisplayFullDateOption() {
|
|
|
|
fun getRelativeDayWithAlwaysDisplayFullDateOption() = withLocale(Locale.US) {
|
|
|
|
freezeAt(DateTime(2020, 1, 1)) {
|
|
|
|
freezeAt(DateTime(2020, 1, 1)) {
|
|
|
|
assertEquals(
|
|
|
|
assertEquals(
|
|
|
|
"Thursday, January 2",
|
|
|
|
"Thursday, January 2",
|
|
|
|
DateUtilities.getRelativeDay(
|
|
|
|
getRelativeDay(DateTime(2020, 1, 2, 11, 50, 1).millis, DateStyle.FULL, alwaysDisplayFullDate = true, lowercase = true)
|
|
|
|
ApplicationProvider.getApplicationContext(),
|
|
|
|
|
|
|
|
DateTime(2020, 1, 2, 11, 50, 1).millis,
|
|
|
|
|
|
|
|
Locale.US,
|
|
|
|
|
|
|
|
FormatStyle.FULL,
|
|
|
|
|
|
|
|
true,
|
|
|
|
|
|
|
|
true
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
fun getRelativeDayWithoutAlwaysDisplayFullDateOption() {
|
|
|
|
fun getRelativeDayWithoutAlwaysDisplayFullDateOption() = withLocale(Locale.US) {
|
|
|
|
freezeAt(DateTime(2020, 1, 1)) {
|
|
|
|
freezeAt(DateTime(2020, 1, 1)) {
|
|
|
|
assertEquals(
|
|
|
|
assertEquals(
|
|
|
|
"tomorrow",
|
|
|
|
"tomorrow",
|
|
|
|
DateUtilities.getRelativeDay(
|
|
|
|
getRelativeDay(DateTime(2020, 1, 2, 11, 50, 1).millis, DateStyle.FULL, lowercase = true)
|
|
|
|
ApplicationProvider.getApplicationContext(),
|
|
|
|
|
|
|
|
DateTime(2020, 1, 2, 11, 50, 1).millis,
|
|
|
|
|
|
|
|
Locale.US,
|
|
|
|
|
|
|
|
FormatStyle.FULL,
|
|
|
|
|
|
|
|
false,
|
|
|
|
|
|
|
|
true
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
fun germanDateNoYear() {
|
|
|
|
fun germanDateNoYear() = withLocale(Locale.GERMAN) {
|
|
|
|
freezeAt(DateTime(2018, 1, 1)) {
|
|
|
|
freezeAt(DateTime(2018, 1, 1)) {
|
|
|
|
assertEquals(
|
|
|
|
assertEquals(
|
|
|
|
"Sonntag, 14. Januar",
|
|
|
|
"Sonntag, 14. Januar",
|
|
|
|
DateUtilities.getRelativeDateTime(
|
|
|
|
getRelativeDateTime(DateTime(2018, 1, 14).millis, is24HourFormat, DateStyle.FULL)
|
|
|
|
ApplicationProvider.getApplicationContext(),
|
|
|
|
)
|
|
|
|
DateTime(2018, 1, 14).millis,
|
|
|
|
|
|
|
|
Locale.GERMAN,
|
|
|
|
|
|
|
|
FormatStyle.FULL))
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
fun germanDateWithYear() {
|
|
|
|
fun germanDateWithYear() = withLocale(Locale.GERMAN) {
|
|
|
|
freezeAt(DateTime(2017, 12, 12)) {
|
|
|
|
freezeAt(DateTime(2017, 12, 12)) {
|
|
|
|
assertEquals(
|
|
|
|
assertEquals(
|
|
|
|
"Sonntag, 14. Januar 2018",
|
|
|
|
"Sonntag, 14. Januar 2018",
|
|
|
|
DateUtilities.getRelativeDateTime(
|
|
|
|
getRelativeDateTime(DateTime(2018, 1, 14).millis, is24HourFormat, DateStyle.FULL)
|
|
|
|
ApplicationProvider.getApplicationContext(),
|
|
|
|
)
|
|
|
|
DateTime(2018, 1, 14).millis,
|
|
|
|
|
|
|
|
Locale.GERMAN,
|
|
|
|
|
|
|
|
FormatStyle.FULL))
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
fun koreanDateNoYear() {
|
|
|
|
fun koreanDateNoYear() = withLocale(Locale.KOREAN) {
|
|
|
|
freezeAt(DateTime(2018, 1, 1)) {
|
|
|
|
freezeAt(DateTime(2018, 1, 1)) {
|
|
|
|
assertEquals(
|
|
|
|
assertEquals(
|
|
|
|
"1월 14일 일요일",
|
|
|
|
"1월 14일 일요일",
|
|
|
|
DateUtilities.getRelativeDateTime(
|
|
|
|
getRelativeDateTime(DateTime(2018, 1, 14).millis, is24HourFormat, DateStyle.FULL)
|
|
|
|
ApplicationProvider.getApplicationContext(),
|
|
|
|
)
|
|
|
|
DateTime(2018, 1, 14).millis,
|
|
|
|
|
|
|
|
Locale.KOREAN,
|
|
|
|
|
|
|
|
FormatStyle.FULL))
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
fun koreanDateWithYear() {
|
|
|
|
fun koreanDateWithYear() = withLocale(Locale.KOREAN) {
|
|
|
|
freezeAt(DateTime(2017, 12, 12)) {
|
|
|
|
freezeAt(DateTime(2017, 12, 12)) {
|
|
|
|
assertEquals(
|
|
|
|
assertEquals(
|
|
|
|
"2018년 1월 14일 일요일",
|
|
|
|
"2018년 1월 14일 일요일",
|
|
|
|
DateUtilities.getRelativeDateTime(
|
|
|
|
getRelativeDateTime(DateTime(2018, 1, 14).millis, is24HourFormat, DateStyle.FULL)
|
|
|
|
ApplicationProvider.getApplicationContext(),
|
|
|
|
)
|
|
|
|
DateTime(2018, 1, 14).millis,
|
|
|
|
|
|
|
|
Locale.KOREAN,
|
|
|
|
|
|
|
|
FormatStyle.FULL))
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
fun japaneseDateNoYear() {
|
|
|
|
fun japaneseDateNoYear() = withLocale(Locale.JAPANESE) {
|
|
|
|
freezeAt(DateTime(2018, 1, 1)) {
|
|
|
|
freezeAt(DateTime(2018, 1, 1)) {
|
|
|
|
assertEquals(
|
|
|
|
assertEquals(
|
|
|
|
"1月14日日曜日",
|
|
|
|
"1月14日日曜日",
|
|
|
|
DateUtilities.getRelativeDateTime(
|
|
|
|
getRelativeDateTime(DateTime(2018, 1, 14).millis, is24HourFormat, DateStyle.FULL)
|
|
|
|
ApplicationProvider.getApplicationContext(),
|
|
|
|
)
|
|
|
|
DateTime(2018, 1, 14).millis,
|
|
|
|
|
|
|
|
Locale.JAPANESE,
|
|
|
|
|
|
|
|
FormatStyle.FULL))
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
fun japaneseDateWithYear() {
|
|
|
|
fun japaneseDateWithYear() = withLocale(Locale.JAPANESE) {
|
|
|
|
freezeAt(DateTime(2017, 12, 12)) {
|
|
|
|
freezeAt(DateTime(2017, 12, 12)) {
|
|
|
|
assertEquals(
|
|
|
|
assertEquals(
|
|
|
|
"2018年1月14日日曜日",
|
|
|
|
"2018年1月14日日曜日",
|
|
|
|
DateUtilities.getRelativeDateTime(
|
|
|
|
getRelativeDateTime(DateTime(2018, 1, 14).millis, is24HourFormat, DateStyle.FULL)
|
|
|
|
ApplicationProvider.getApplicationContext(),
|
|
|
|
)
|
|
|
|
DateTime(2018, 1, 14).millis,
|
|
|
|
|
|
|
|
Locale.JAPANESE,
|
|
|
|
|
|
|
|
FormatStyle.FULL))
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
fun chineseDateNoYear() {
|
|
|
|
fun chineseDateNoYear() = withLocale(Locale.CHINESE) {
|
|
|
|
freezeAt(DateTime(2018, 1, 1)) {
|
|
|
|
freezeAt(DateTime(2018, 1, 1)) {
|
|
|
|
assertEquals(
|
|
|
|
assertEquals(
|
|
|
|
"1月14日星期日",
|
|
|
|
"1月14日星期日",
|
|
|
|
DateUtilities.getRelativeDateTime(
|
|
|
|
getRelativeDateTime(DateTime(2018, 1, 14).millis, is24HourFormat, DateStyle.FULL)
|
|
|
|
ApplicationProvider.getApplicationContext(),
|
|
|
|
)
|
|
|
|
DateTime(2018, 1, 14).millis,
|
|
|
|
|
|
|
|
Locale.CHINESE,
|
|
|
|
|
|
|
|
FormatStyle.FULL))
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
fun chineseDateWithYear() {
|
|
|
|
fun chineseDateWithYear() = withLocale(Locale.CHINESE) {
|
|
|
|
freezeAt(DateTime(2017, 12, 12)) {
|
|
|
|
SuspendFreeze.freezeAt(DateTime(2017, 12, 12)) {
|
|
|
|
assertEquals(
|
|
|
|
assertEquals(
|
|
|
|
"2018年1月14日星期日",
|
|
|
|
"2018年1月14日星期日",
|
|
|
|
DateUtilities.getRelativeDateTime(
|
|
|
|
getRelativeDateTime(DateTime(2018, 1, 14).millis, is24HourFormat, DateStyle.FULL)
|
|
|
|
ApplicationProvider.getApplicationContext(),
|
|
|
|
)
|
|
|
|
DateTime(2018, 1, 14).millis,
|
|
|
|
|
|
|
|
Locale.CHINESE,
|
|
|
|
|
|
|
|
FormatStyle.FULL))
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
fun chineseDateTimeNoYear() {
|
|
|
|
fun chineseDateTimeNoYear() = withLocale(Locale.CHINESE) {
|
|
|
|
freezeAt(DateTime(2018, 1, 1)) {
|
|
|
|
freezeAt(DateTime(2018, 1, 1)) {
|
|
|
|
assertEquals(
|
|
|
|
assertEquals(
|
|
|
|
"1月14日星期日 上午11:53",
|
|
|
|
"1月14日星期日 上午11:53",
|
|
|
|
DateUtilities.getRelativeDateTime(
|
|
|
|
getRelativeDateTime(DateTime(2018, 1, 14, 11, 53, 1).millis, is24HourFormat, DateStyle.FULL)
|
|
|
|
ApplicationProvider.getApplicationContext(),
|
|
|
|
)
|
|
|
|
DateTime(2018, 1, 14, 11, 53, 1).millis,
|
|
|
|
|
|
|
|
Locale.CHINESE,
|
|
|
|
|
|
|
|
FormatStyle.FULL))
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
fun chineseDateTimeWithYear() {
|
|
|
|
fun chineseDateTimeWithYear() = withLocale(Locale.CHINESE) {
|
|
|
|
freezeAt(DateTime(2017, 12, 12)) {
|
|
|
|
freezeAt(DateTime(2017, 12, 12)) {
|
|
|
|
assertEquals(
|
|
|
|
assertEquals(
|
|
|
|
"2018年1月14日星期日 下午1:45",
|
|
|
|
"2018年1月14日星期日 下午1:45",
|
|
|
|
DateUtilities.getRelativeDateTime(
|
|
|
|
getRelativeDateTime(DateTime(2018, 1, 14, 13, 45, 1).millis, is24HourFormat, DateStyle.FULL)
|
|
|
|
ApplicationProvider.getApplicationContext(),
|
|
|
|
)
|
|
|
|
DateTime(2018, 1, 14, 13, 45, 1).millis,
|
|
|
|
|
|
|
|
Locale.CHINESE,
|
|
|
|
|
|
|
|
FormatStyle.FULL))
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
fun frenchDateTimeWithYear() {
|
|
|
|
fun frenchDateTimeWithYear() = withLocale(Locale.FRENCH) {
|
|
|
|
freezeAt(DateTime(2017, 12, 12)) {
|
|
|
|
freezeAt(DateTime(2017, 12, 12)) {
|
|
|
|
assertMatches(
|
|
|
|
assertMatches(
|
|
|
|
"dimanche 14 janvier 2018( à)? 13:45",
|
|
|
|
"dimanche 14 janvier 2018( à)? 13:45",
|
|
|
|
DateUtilities.getRelativeDateTime(
|
|
|
|
getRelativeDateTime(DateTime(2018, 1, 14, 13, 45, 1).millis, is24HourFormat, DateStyle.FULL)
|
|
|
|
ApplicationProvider.getApplicationContext(),
|
|
|
|
)
|
|
|
|
DateTime(2018, 1, 14, 13, 45, 1).millis,
|
|
|
|
|
|
|
|
Locale.FRENCH,
|
|
|
|
|
|
|
|
FormatStyle.FULL))
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
fun indiaDateTimeWithYear() {
|
|
|
|
fun indiaDateTimeWithYear() = withLocale(Locale.forLanguageTag("hi-IN")) {
|
|
|
|
freezeAt(DateTime(2017, 12, 12)) {
|
|
|
|
freezeAt(DateTime(2017, 12, 12)) {
|
|
|
|
assertMatches(
|
|
|
|
assertMatches(
|
|
|
|
"रविवार, 14 जनवरी 2018( को)? 1:45 pm",
|
|
|
|
"रविवार, 14 जनवरी 2018( को)? 1:45 pm",
|
|
|
|
DateUtilities.getRelativeDateTime(
|
|
|
|
getRelativeDateTime(DateTime(2018, 1, 14, 13, 45, 1).millis, is24HourFormat, DateStyle.FULL)
|
|
|
|
ApplicationProvider.getApplicationContext(),
|
|
|
|
)
|
|
|
|
DateTime(2018, 1, 14, 13, 45, 1).millis,
|
|
|
|
|
|
|
|
Locale.forLanguageTag("hi-IN"),
|
|
|
|
|
|
|
|
FormatStyle.FULL))
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
fun russiaDateTimeNoYear() {
|
|
|
|
fun russiaDateTimeNoYear() = withLocale(Locale.forLanguageTag("ru")) {
|
|
|
|
freezeAt(DateTime(2018, 12, 12)) {
|
|
|
|
freezeAt(DateTime(2018, 12, 12)) {
|
|
|
|
assertMatches(
|
|
|
|
assertMatches(
|
|
|
|
"воскресенье, 14 января,? 13:45",
|
|
|
|
"воскресенье, 14 января,? 13:45",
|
|
|
|
DateUtilities.getRelativeDateTime(
|
|
|
|
getRelativeDateTime(DateTime(2018, 1, 14, 13, 45, 1).millis, is24HourFormat, DateStyle.FULL)
|
|
|
|
ApplicationProvider.getApplicationContext(),
|
|
|
|
)
|
|
|
|
DateTime(2018, 1, 14, 13, 45, 1).millis,
|
|
|
|
|
|
|
|
Locale.forLanguageTag("ru"),
|
|
|
|
|
|
|
|
FormatStyle.FULL))
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
fun russiaDateTimeWithYear() {
|
|
|
|
fun russiaDateTimeWithYear() = withLocale(Locale.forLanguageTag("ru")) {
|
|
|
|
freezeAt(DateTime(2017, 12, 12)) {
|
|
|
|
freezeAt(DateTime(2017, 12, 12)) {
|
|
|
|
assertMatches(
|
|
|
|
assertMatches(
|
|
|
|
"воскресенье, 14 января 2018 г.,? 13:45",
|
|
|
|
"воскресенье, 14 января 2018 г.,? 13:45",
|
|
|
|
DateUtilities.getRelativeDateTime(
|
|
|
|
getRelativeDateTime(DateTime(2018, 1, 14, 13, 45, 1).millis, is24HourFormat, DateStyle.FULL)
|
|
|
|
ApplicationProvider.getApplicationContext(),
|
|
|
|
)
|
|
|
|
DateTime(2018, 1, 14, 13, 45, 1).millis,
|
|
|
|
|
|
|
|
Locale.forLanguageTag("ru"),
|
|
|
|
|
|
|
|
FormatStyle.FULL))
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
fun brazilDateTimeNoYear() {
|
|
|
|
fun brazilDateTimeNoYear() = withLocale(Locale.forLanguageTag("pt-br")) {
|
|
|
|
freezeAt(DateTime(2018, 12, 12)) {
|
|
|
|
freezeAt(DateTime(2018, 12, 12)) {
|
|
|
|
assertEquals(
|
|
|
|
assertEquals(
|
|
|
|
"domingo, 14 de janeiro 13:45",
|
|
|
|
"domingo, 14 de janeiro 13:45",
|
|
|
|
DateUtilities.getRelativeDateTime(
|
|
|
|
getRelativeDateTime(DateTime(2018, 1, 14, 13, 45, 1).millis, is24HourFormat, DateStyle.FULL)
|
|
|
|
ApplicationProvider.getApplicationContext(),
|
|
|
|
)
|
|
|
|
DateTime(2018, 1, 14, 13, 45, 1).millis,
|
|
|
|
|
|
|
|
Locale.forLanguageTag("pt-br"),
|
|
|
|
|
|
|
|
FormatStyle.FULL))
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
fun brazilDateTimeWithYear() {
|
|
|
|
fun brazilDateTimeWithYear() = withLocale(Locale.forLanguageTag("pt-br")) {
|
|
|
|
freezeAt(DateTime(2017, 12, 12)) {
|
|
|
|
freezeAt(DateTime(2017, 12, 12)) {
|
|
|
|
assertEquals(
|
|
|
|
assertEquals(
|
|
|
|
"domingo, 14 de janeiro de 2018 13:45",
|
|
|
|
"domingo, 14 de janeiro de 2018 13:45",
|
|
|
|
DateUtilities.getRelativeDateTime(
|
|
|
|
getRelativeDateTime(DateTime(2018, 1, 14, 13, 45, 1).millis, is24HourFormat, DateStyle.FULL)
|
|
|
|
ApplicationProvider.getApplicationContext(),
|
|
|
|
)
|
|
|
|
DateTime(2018, 1, 14, 13, 45, 1).millis,
|
|
|
|
|
|
|
|
Locale.forLanguageTag("pt-br"),
|
|
|
|
|
|
|
|
FormatStyle.FULL))
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
fun spainDateTimeNoYear() {
|
|
|
|
fun spainDateTimeNoYear() = withLocale(Locale.forLanguageTag("es")) {
|
|
|
|
freezeAt(DateTime(2018, 12, 12)) {
|
|
|
|
freezeAt(DateTime(2018, 12, 12)) {
|
|
|
|
assertMatches(
|
|
|
|
assertMatches(
|
|
|
|
"domingo, 14 de enero,? 13:45",
|
|
|
|
"domingo, 14 de enero,? 13:45",
|
|
|
|
DateUtilities.getRelativeDateTime(
|
|
|
|
getRelativeDateTime(DateTime(2018, 1, 14, 13, 45, 1).millis, is24HourFormat, DateStyle.FULL)
|
|
|
|
ApplicationProvider.getApplicationContext(),
|
|
|
|
)
|
|
|
|
DateTime(2018, 1, 14, 13, 45, 1).millis,
|
|
|
|
|
|
|
|
Locale.forLanguageTag("es"),
|
|
|
|
|
|
|
|
FormatStyle.FULL))
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
fun spainDateTimeWithYear() {
|
|
|
|
fun spainDateTimeWithYear() = withLocale(Locale.forLanguageTag("es")) {
|
|
|
|
freezeAt(DateTime(2017, 12, 12)) {
|
|
|
|
freezeAt(DateTime(2017, 12, 12)) {
|
|
|
|
assertMatches(
|
|
|
|
assertMatches(
|
|
|
|
"domingo, 14 de enero de 2018,? 13:45",
|
|
|
|
"domingo, 14 de enero de 2018,? 13:45",
|
|
|
|
DateUtilities.getRelativeDateTime(
|
|
|
|
getRelativeDateTime(DateTime(2018, 1, 14, 13, 45, 1).millis, is24HourFormat, DateStyle.FULL)
|
|
|
|
ApplicationProvider.getApplicationContext(),
|
|
|
|
)
|
|
|
|
DateTime(2018, 1, 14, 13, 45, 1).millis,
|
|
|
|
|
|
|
|
Locale.forLanguageTag("es"),
|
|
|
|
|
|
|
|
FormatStyle.FULL))
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
fun hebrewDateTimeNoYear() {
|
|
|
|
fun hebrewDateTimeNoYear() = withLocale(Locale.forLanguageTag("iw")) {
|
|
|
|
freezeAt(DateTime(2018, 12, 12)) {
|
|
|
|
freezeAt(DateTime(2018, 12, 12)) {
|
|
|
|
assertMatches(
|
|
|
|
assertMatches(
|
|
|
|
"יום ראשון, 14 בינואר( בשעה)? 13:45",
|
|
|
|
"יום ראשון, 14 בינואר( בשעה)? 13:45",
|
|
|
|
DateUtilities.getRelativeDateTime(
|
|
|
|
getRelativeDateTime(DateTime(2018, 1, 14, 13, 45, 1).millis, is24HourFormat, DateStyle.FULL)
|
|
|
|
ApplicationProvider.getApplicationContext(),
|
|
|
|
)
|
|
|
|
DateTime(2018, 1, 14, 13, 45, 1).millis,
|
|
|
|
|
|
|
|
Locale.forLanguageTag("iw"),
|
|
|
|
|
|
|
|
FormatStyle.FULL))
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
fun hebrewDateTimeWithYear() {
|
|
|
|
fun hebrewDateTimeWithYear() = withLocale(Locale.forLanguageTag("iw")) {
|
|
|
|
freezeAt(DateTime(2017, 12, 12)) {
|
|
|
|
freezeAt(DateTime(2017, 12, 12)) {
|
|
|
|
|
|
|
|
|
|
|
|
assertMatches(
|
|
|
|
assertMatches(
|
|
|
|
"יום ראשון, 14 בינואר 2018( בשעה)? 13:45",
|
|
|
|
"יום ראשון, 14 בינואר 2018( בשעה)? 13:45",
|
|
|
|
DateUtilities.getRelativeDateTime(
|
|
|
|
getRelativeDateTime(DateTime(2018, 1, 14, 13, 45, 1).millis, is24HourFormat, DateStyle.FULL)
|
|
|
|
ApplicationProvider.getApplicationContext(),
|
|
|
|
)
|
|
|
|
DateTime(2018, 1, 14, 13, 45, 1).millis,
|
|
|
|
|
|
|
|
Locale.forLanguageTag("iw"),
|
|
|
|
|
|
|
|
FormatStyle.FULL))
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private fun assertMatches(regex: String, actual: String) =
|
|
|
|
private fun assertMatches(regex: String, actual: String) =
|
|
|
|
assertTrue("expected=$regex\nactual=$actual", actual.matches(Regex(regex)))
|
|
|
|
assertTrue("expected=$regex\nactual=$actual", actual.matches(Regex(regex)))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private val is24HourFormat: Boolean
|
|
|
|
|
|
|
|
get() = InstrumentationRegistry.getInstrumentation().targetContext.is24HourFormat
|
|
|
|
}
|
|
|
|
}
|