import org.jsoup.nodes.Document
import org.jsoup.nodes.Element
import java.time.LocalDateTime
+import java.time.ZoneId.of
+import java.time.ZonedDateTime
import java.time.format.DateTimeFormatter
/**
return wetterComState
}
- private fun parseDateTime(document: Document): LocalDateTime? {
+ private fun parseDateTime(document: Document): ZonedDateTime? {
val dateElement = document.select("#furtherDetails .portable-mb h3")
.single()?.text()?.split(",")?.get(1)?.trim() ?: return null
val timeElement = document.select(".weather-strip--detail .delta.palm-hide")
.first()?.text()?.split(" ")?.first() ?: return null
- return LocalDateTime.from(dateTimeFormatter.parse("%s %s".format(dateElement, timeElement)))
+ return LocalDateTime.from(dateTimeFormatter.parse("%s %s".format(dateElement, timeElement))).atZone(of("Europe/Berlin"))
}
private fun parseHourStates(document: Document): List<HourState> {
package net.pterodactylus.rhynodge.webpages.weather.wettercom
import net.pterodactylus.rhynodge.states.AbstractState
-import java.time.LocalDateTime
+import java.time.ZonedDateTime
/**
* Contains the state parsed from [wetter.com](https://www.wetter.com/).
*
* @author [David ‘Bombe’ Roden](mailto:bombe@pterodactylus.net)
*/
-class WetterComState(val dateTime: LocalDateTime) : AbstractState(true) {
+class WetterComState(val dateTime: ZonedDateTime) : AbstractState(true) {
val hours: List<HourState> = mutableListOf()
import org.mockito.Mockito.mock
import java.time.LocalDateTime
import java.time.Month
+import java.time.ZoneId
/**
* Unit test for [WetterComFilter].
val document = loadDocument(javaClass, "wetter.com.html", url)
val htmlState = HtmlState(url, document)
val newState = filter.filter(htmlState) as WetterComState
- assertThat(newState.dateTime, `is`(LocalDateTime.of(2016, Month.MAY, 23, 5, 0)))
+ assertThat(newState.dateTime, `is`(LocalDateTime.of(2016, Month.MAY, 23, 5, 0).atZone(ZoneId.of("Europe/Berlin"))))
assertThat(newState.hours, contains(
HourState(0, 15.0, 0.65, 0.8, WindDirection.NORTH, 5.0, "leichter Regen-schauer", "http://ls1.wettercomassets.com/wcomv5/images/icons/small/d_80_S.png?201605201518"),
HourState(1, 15.0, 0.7, 0.9, WindDirection.NONE, 5.0, "leichter Regen-schauer", "http://ls1.wettercomassets.com/wcomv5/images/icons/small/d_80_S.png?201605201518"),
import org.hamcrest.Matchers.`is`
import org.junit.Test
import java.time.Instant
-import java.time.LocalDateTime
import java.time.ZoneId
+import java.time.ZonedDateTime
/**
* Unit test for [WetterComState].
fun statesWithoutHoursEqualOneAnother() {
val now = Instant.now().atZone(ZoneId.of("UTC"))
println("%s %s".format(now, now.javaClass))
- val firstState = WetterComState(LocalDateTime.from(now))
- val secondState = WetterComState(LocalDateTime.from(now))
+ val firstState = WetterComState(ZonedDateTime.from(now))
+ val secondState = WetterComState(ZonedDateTime.from(now))
assertThat(firstState, `is`(secondState))
}
fun statesWithTheSameHoursAreEqual() {
val now = Instant.now().atZone(ZoneId.of("UTC"))
println("%s %s".format(now, now.javaClass))
- val firstState = WetterComState(LocalDateTime.from(now))
+ val firstState = WetterComState(ZonedDateTime.from(now))
firstState.addHour(HourState(0, 10.0, 0.05, 0.0, WindDirection.NORTH, 5.0, "Fine", "http://1"))
firstState.addHour(HourState(1, 12.0, 0.1, 2.0, WindDirection.WEST, 8.0, "Superb", "http://2"))
- val secondState = WetterComState(LocalDateTime.from(now))
+ val secondState = WetterComState(ZonedDateTime.from(now))
secondState.addHour(HourState(0, 10.0, 0.05, 0.0, WindDirection.NORTH, 5.0, "Fine", "http://1"))
secondState.addHour(HourState(1, 12.0, 0.1, 2.0, WindDirection.WEST, 8.0, "Superb", "http://2"))
assertThat(firstState, `is`(secondState))