Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Nextcloud - Android Client
*
* SPDX-FileCopyrightText: 2026 <Ruba Mogalli> <rubamogalli@gmail.com>
* SPDX-License-Identifier: AGPL-3.0-or-later OR GPL-2.0-only
*/
package com.nextcloud.utils.date

import org.junit.Assert.assertEquals
import org.junit.Test
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
import java.util.Locale

class DateFormatPatternTest {

// Fixed date, so the result never depends on today's date or timezone
private val date = LocalDateTime.of(2024, 8, 3, 14, 38)

private fun format(pattern: DateFormatPattern): String =
DateTimeFormatter.ofPattern(pattern.pattern, Locale.ENGLISH).format(date)

@Test
fun fullDateWithHours_formatsDateAndTime() {
assertEquals("03.08.2024 - 14:38", format(DateFormatPattern.FullDateWithHours))
}

@Test
fun monthWithDate_formatsShortMonthAndDay() {
assertEquals("Aug 3", format(DateFormatPattern.MonthWithDate))
}

@Test
fun fullMonthWithYear_formatsFullMonthAndYearAndTime() {
assertEquals("August 03, 2024 14:38", format(DateFormatPattern.MonthDayYearTime))
}

@Test
fun monthWithYear_formatsShortMonthAndYear() {
assertEquals("Aug 2024", format(DateFormatPattern.MonthWithYear))
}

@Test
fun fullMonthWithYear_formatsFullMonthAndYear() {
assertEquals("August 2024", format(DateFormatPattern.FullMonthWithYear))
}

@Test
fun fullMonth_formatsFullMonthName() {
assertEquals("August", format(DateFormatPattern.FullMonth))
}

@Test
fun year_formatsFourDigitYear() {
assertEquals("2024", format(DateFormatPattern.Year))
}
}