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()
23 @get:JsonGetter("dateTime")
24 val timeMillis = dateTime.toInstant().toEpochMilli()
26 operator fun plusAssign(hourState: HourState) {
27 (hours as MutableList<HourState>).add(hourState)
30 override fun iterator(): Iterator<HourState> {
31 return hours.iterator()
34 override fun equals(other: Any?): Boolean {
35 other as? WeatherState ?: return false
36 return (dateTime == other.dateTime) and (hours == other.hours)