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.kodi.internal.model;
15 import java.time.Duration;
16 import java.util.concurrent.TimeUnit;
18 import org.eclipse.jdt.annotation.NonNullByDefault;
21 * Class representing a Kodi duration (https://kodi.wiki/view/JSON-RPC_API/v9#Global.Time)
23 * @author Christoph Weitkamp - Initial contribution
26 public class KodiDuration {
28 * The hours of the duration
32 * The minutes of the duration
36 * The seconds of the duration
40 * The milliseconds of the duration
42 private long milliseconds;
44 public long getHours() {
48 public void setHours(long hours) {
52 public long getMinutes() {
56 public void setMinutes(long minutes) {
57 this.minutes = minutes;
60 public long getSeconds() {
64 public void setSeconds(long seconds) {
65 this.seconds = seconds;
68 public long getMilliseconds() {
72 public void setMilliseconds(long milliseconds) {
73 this.milliseconds = milliseconds;
77 * Converts this KodiDuration to the total length in seconds.
79 * @return the total length of the duration in seconds
81 public long toSeconds() {
82 return TimeUnit.MILLISECONDS.toSeconds(toMillis());
86 * Converts this KodiDuration to the total length in milliseconds.
88 * @return the total length of the duration in milliseconds
90 public long toMillis() {
91 return Duration.ofHours(hours).plusMinutes(minutes).plusSeconds(seconds).plusMillis(milliseconds).toMillis();