]> git.basschouten.com Git - openhab-addons.git/blob
54edea13784671b99e64b990da3d606286eaa675
[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.astro.internal.model;
14
15 import java.util.Calendar;
16
17 /**
18  * Extends the zodiac with a date range.
19  *
20  * @author Gerhard Riegler - Initial contribution
21  */
22 public class SunZodiac extends Zodiac {
23     private Range range;
24
25     /**
26      * Creates a Zodiac with a sign and a range.
27      */
28     public SunZodiac(ZodiacSign sign, Range range) {
29         super(sign);
30         this.range = range;
31     }
32
33     /**
34      * Returns she start of the zodiac.
35      */
36     public Calendar getStart() {
37         return range == null ? null : range.getStart();
38     }
39
40     /**
41      * Returns the end of the zodiac.
42      */
43     public Calendar getEnd() {
44         return range == null ? null : range.getEnd();
45     }
46
47     /**
48      * Returns true, if the zodiac is valid on the specified calendar object.
49      */
50     public boolean isValid(Calendar calendar) {
51         if (range == null || range.getStart() == null || range.getEnd() == null) {
52             return false;
53         }
54
55         return range.getStart().getTimeInMillis() <= calendar.getTimeInMillis()
56                 && range.getEnd().getTimeInMillis() >= calendar.getTimeInMillis();
57     }
58 }