]> git.basschouten.com Git - openhab-addons.git/blob
34506cc1e188ce9593b2cc7fc225284b3774d534
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.kodi.internal.model;
14
15 import java.time.Duration;
16 import java.util.concurrent.TimeUnit;
17
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19
20 /**
21  * Class representing a Kodi duration (https://kodi.wiki/view/JSON-RPC_API/v9#Global.Time)
22  *
23  * @author Christoph Weitkamp - Initial contribution
24  */
25 @NonNullByDefault
26 public class KodiDuration {
27     /**
28      * The hours of the duration
29      */
30     private long hours;
31     /**
32      * The minutes of the duration
33      */
34     private long minutes;
35     /**
36      * The seconds of the duration
37      */
38     private long seconds;
39     /**
40      * The milliseconds of the duration
41      */
42     private long milliseconds;
43
44     public long getHours() {
45         return hours;
46     }
47
48     public void setHours(long hours) {
49         this.hours = hours;
50     }
51
52     public long getMinutes() {
53         return minutes;
54     }
55
56     public void setMinutes(long minutes) {
57         this.minutes = minutes;
58     }
59
60     public long getSeconds() {
61         return seconds;
62     }
63
64     public void setSeconds(long seconds) {
65         this.seconds = seconds;
66     }
67
68     public long getMilliseconds() {
69         return milliseconds;
70     }
71
72     public void setMilliseconds(long milliseconds) {
73         this.milliseconds = milliseconds;
74     }
75
76     /**
77      * Converts this KodiDuration to the total length in seconds.
78      *
79      * @return the total length of the duration in seconds
80      */
81     public long toSeconds() {
82         return TimeUnit.MILLISECONDS.toSeconds(toMillis());
83     }
84
85     /**
86      * Converts this KodiDuration to the total length in milliseconds.
87      *
88      * @return the total length of the duration in milliseconds
89      */
90     public long toMillis() {
91         return Duration.ofHours(hours).plusMinutes(minutes).plusSeconds(seconds).plusMillis(milliseconds).toMillis();
92     }
93 }