2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.awattar.internal;
15 import java.time.Instant;
16 import java.time.ZoneId;
17 import java.time.ZonedDateTime;
19 import org.eclipse.jdt.annotation.NonNullByDefault;
22 * Class to store hourly price data.
24 * @author Wolfgang Klimt - initial contribution
27 public class AwattarPrice implements Comparable<AwattarPrice> {
28 private final Double price;
29 private final long endTimestamp;
30 private final long startTimestamp;
32 private final int hour;
34 public AwattarPrice(double price, long startTimestamp, long endTimestamp, ZoneId zoneId) {
36 this.endTimestamp = endTimestamp;
37 this.startTimestamp = startTimestamp;
38 this.hour = ZonedDateTime.ofInstant(Instant.ofEpochMilli(startTimestamp), zoneId).getHour();
41 public long getStartTimestamp() {
42 return startTimestamp;
45 public long getEndTimestamp() {
49 public double getPrice() {
54 public String toString() {
55 return String.format("(%1$tF %1$tR - %2$tR: %3$.3f)", startTimestamp, endTimestamp, getPrice());
58 public int getHour() {
63 public int compareTo(AwattarPrice o) {
64 return price.compareTo(o.price);
67 public boolean isBetween(long start, long end) {
68 return startTimestamp >= start && endTimestamp <= end;
71 public boolean contains(long timestamp) {
72 return startTimestamp <= timestamp && endTimestamp > timestamp;