1 package net.pterodactylus.rhynodge.webpages.weather
3 import com.fasterxml.jackson.annotation.JsonGetter
4 import com.fasterxml.jackson.annotation.JsonProperty
5 import net.pterodactylus.rhynodge.states.AbstractState
6 import java.time.Instant
7 import java.time.ZoneId
8 import java.time.ZonedDateTime
11 * Contains a weather state.
13 * @author [David ‘Bombe’ Roden](mailto:bombe@pterodactylus.net)
15 class WeatherState(val service: String, val dateTime: ZonedDateTime) : AbstractState(true), Iterable<HourState> {
17 constructor(@JsonProperty("service") service: String, @JsonProperty("dateTime") time: Long) :
18 this(service, Instant.ofEpochMilli(time).atZone(ZoneId.of("Europe/Berlin")))
20 @JsonProperty("hours")
21 val hours: List<HourState> = mutableListOf()
24 @JsonGetter("dateTime")
25 get() = dateTime.toInstant().toEpochMilli()
27 operator fun plusAssign(hourState: HourState) {
28 (hours as MutableList<HourState>).add(hourState)
31 override fun iterator(): Iterator<HourState> {
32 return hours.iterator()
35 override fun equals(other: Any?): Boolean {
36 other as? WeatherState ?: return false
37 return (dateTime == other.dateTime) and (hours == other.hours)