Skip to content

Commit 160edde

Browse files
bwbeckercquiroz
authored andcommitted
Add three tests for DateTimeFormatter.ofPattern. All pass in the JVM. For Locale.US, two pass in ScalaJS and one fails. For Locale.CANADA, one passes in ScalaJS and two fail.
Run `testOnly org.threeten.bp.format.TestDateTimeTextPrinting`
1 parent 268777e commit 160edde

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

tests/shared/src/test/scala/org/threeten/bp/format/TestDateTimeTextPrinting.scala

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,4 +172,25 @@ class TestDateTimeTextPrinting extends AnyFunSuite with AssertionsHelper {
172172
val dt: LocalDateTime = LocalDateTime.of(2010, 2, 1, 0, 0)
173173
assertEquals(f.format(dt), "2")
174174
}
175+
176+
177+
test("formatFullDate") {
178+
Locale.setDefault(Locale.CANADA) // Passes for both US and CANADA
179+
val formatFullDate = DateTimeFormatter.ofPattern("MMMM dd, yyyy")
180+
val dt = LocalDateTime.of(2018, 1, 30, 11, 2, 45, 750000)
181+
assertResult("January 30, 2018") {dt.format(formatFullDate)}
182+
}
183+
test("formatDayOfWeek") {
184+
Locale.setDefault(Locale.CANADA) // Passes for US
185+
val formatDayOfWeek = DateTimeFormatter.ofPattern("cccc MMM d") // Thursday Jan. 25
186+
val dt = LocalDateTime.of(2018, 1, 30, 11, 2, 45, 750000)
187+
assertResult("Tuesday Jan 30") {dt.format(formatDayOfWeek)}
188+
}
189+
test("formatTime_AM_PM") {
190+
Locale.setDefault(Locale.CANADA) // Fails for both US and CANADA
191+
val formatTime_AM_PM = DateTimeFormatter.ofPattern("h:mm a") // 10:15 PM
192+
val dt = LocalDateTime.of(2018, 1, 30, 11, 2, 45, 750000)
193+
assertResult("11:02 AM") {dt.format(formatTime_AM_PM)}
194+
}
195+
175196
}

0 commit comments

Comments
 (0)