Gilberto Diaz
03/25/2020, 5:31 PMclass DateUtils {
fun LocalDateTime.setTimeZone(targetTimeZone: String): LocalDateTime {
return ZonedDateTime.of(
this,
ZoneId.of(targetTimeZone)
).toLocalDateTime()
}
}
@Test
fun `It should set time zone`() {
val msgDateStr = "2020-03-07T11:55:00"
val format = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss")
al currDate = LocalDateTime.parse(msgDateStr, format)
assertEquals("2020-03-07T11:55-05:00[America/New_York]", DateUtils.setTimeZone(currDate, "America/NewYork"))
}
DateUtils.setTimeZome(...) // I get a Unresolved reference: setTimeZone
Daniel
03/25/2020, 6:10 PMGilberto Diaz
03/25/2020, 6:12 PMaandreyev
03/25/2020, 6:13 PMwith(DateUtils()){
assertEquals("2020-03-07T11:55-05:00[America/New_York]", currDate.setTimeZone( "America/NewYork"))
}
aandreyev
03/25/2020, 6:14 PMGilberto Diaz
03/25/2020, 6:15 PMcurrDate.setTimeZone(...) // Unresolved reference: setTimeZone
Gilberto Diaz
03/25/2020, 6:15 PMGilberto Diaz
03/25/2020, 6:16 PMDateTimeFormatter.ofPattern(…) // Unresolved reference: ofPattern
aandreyev
03/25/2020, 6:19 PMaandreyev
03/25/2020, 6:19 PMGilberto Diaz
03/25/2020, 6:32 PMDaniel
03/25/2020, 8:23 PMfun LocalDateTime.setTimeZone(targetTimeZone: String): LocalDateTime {
return ZonedDateTime.of(
this,
ZoneId.of(targetTimeZone)
).toLocalDateTime()
}
In LocalDateTimeExt.kt
file for exampleGilberto Diaz
03/25/2020, 8:24 PMDaniel
03/25/2020, 8:24 PMtestImplementation
ect. No idea how it is handled in maven thoughGilberto Diaz
03/25/2020, 8:33 PM