1 |
/*
|
2 |
* Copyright 2008-2009 Mike Reedell / LuckyCatLabs.
|
3 |
*
|
4 |
* Licensed under the Apache License, Version 2.0 (the "License");
|
5 |
* you may not use this file except in compliance with the License.
|
6 |
* You may obtain a copy of the License at
|
7 |
*
|
8 |
* http://www.apache.org/licenses/LICENSE-2.0
|
9 |
*
|
10 |
* Unless required by applicable law or agreed to in writing, software
|
11 |
* distributed under the License is distributed on an "AS IS" BASIS,
|
12 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13 |
* See the License for the specific language governing permissions and
|
14 |
* limitations under the License.
|
15 |
*/
|
16 |
|
17 |
package com.luckycatlabs.sunrisesunset;
|
18 |
|
19 |
import java.util.Calendar;
|
20 |
|
21 |
import com.luckycatlabs.sunrisesunset.calculator.SolarEventCalculator;
|
22 |
import com.luckycatlabs.sunrisesunset.dto.Location2;
|
23 |
|
24 |
|
25 |
/**
|
26 |
* Public interface for getting the various types of sunrise/sunset.
|
27 |
*/
|
28 |
public class SunriseSunsetCalculator
|
29 |
{
|
30 |
|
31 |
private Location2 location;
|
32 |
|
33 |
private SolarEventCalculator calculator;
|
34 |
|
35 |
/**
|
36 |
* Constructs a new <code>SunriseSunsetCalculator</code> with the given <code>Location</code>
|
37 |
*
|
38 |
* @param location
|
39 |
* <code>Location</code> object containing the Latitude/Longitude of the location to compute
|
40 |
* the sunrise/sunset for.
|
41 |
* @param timeZoneIdentifier
|
42 |
* String identifier for the timezone to compute the sunrise/sunset times in. In the form
|
43 |
* "America/New_York". Please see the zi directory under the JDK installation for supported
|
44 |
* time zones.
|
45 |
*/
|
46 |
public SunriseSunsetCalculator(Location2 location, String timeZoneIdentifier)
|
47 |
{
|
48 |
this.calculator = new SolarEventCalculator(location, timeZoneIdentifier);
|
49 |
}
|
50 |
|
51 |
/**
|
52 |
* Returns the astronomical (108deg) sunrise for the given date.
|
53 |
*
|
54 |
* @param date
|
55 |
* <code>Calendar</code> object containing the date to compute the astronomical sunrise for.
|
56 |
* @return the astronomical sunrise time in HH:MM (24-hour clock) form.
|
57 |
*/
|
58 |
public String getAstronomicalSunriseForDate(Calendar date)
|
59 |
{
|
60 |
return calculator.computeSunriseTime(Zenith.ASTRONOMICAL, date);
|
61 |
}
|
62 |
|
63 |
public SolarEventCalculator.moonCoor_ret computeMoon(Calendar date)
|
64 |
{
|
65 |
return (calculator.computeMoonStats(date));
|
66 |
}
|
67 |
|
68 |
/**
|
69 |
* Returns the astronomical (108deg) sunset for the given date.
|
70 |
*
|
71 |
* @param date
|
72 |
* <code>Calendar</code> object containing the date to compute the astronomical sunset for.
|
73 |
* @return the astronomical sunset time in HH:MM (24-hour clock) form.
|
74 |
*/
|
75 |
public String getAstronomicalSunsetForDate(Calendar date)
|
76 |
{
|
77 |
return calculator.computeSunsetTime(Zenith.ASTRONOMICAL, date);
|
78 |
}
|
79 |
|
80 |
/**
|
81 |
* Returns the nautical (102deg) sunrise for the given date.
|
82 |
*
|
83 |
* @param date
|
84 |
* <code>Calendar</code> object containing the date to compute the nautical sunrise for.
|
85 |
* @return the nautical sunrise time in HH:MM (24-hour clock) form.
|
86 |
*/
|
87 |
public String getNauticalSunriseForDate(Calendar date)
|
88 |
{
|
89 |
return calculator.computeSunriseTime(Zenith.NAUTICAL, date);
|
90 |
}
|
91 |
|
92 |
/**
|
93 |
* Returns the nautical (102deg) sunset for the given date.
|
94 |
*
|
95 |
* @param date
|
96 |
* <code>Calendar</code> object containing the date to compute the nautical sunset for.
|
97 |
* @return the nautical sunset time in HH:MM (24-hour clock) form.
|
98 |
*/
|
99 |
public String getNauticalSunsetForDate(Calendar date)
|
100 |
{
|
101 |
return calculator.computeSunsetTime(Zenith.NAUTICAL, date);
|
102 |
}
|
103 |
|
104 |
/**
|
105 |
* Returns the civil sunrise (twilight, 96deg) for the given date.
|
106 |
*
|
107 |
* @param date
|
108 |
* <code>Calendar</code> object containing the date to compute the civil sunrise for.
|
109 |
* @return the civil sunrise time in HH:MM (24-hour clock) form.
|
110 |
*/
|
111 |
public String getCivilSunriseForDate(Calendar date)
|
112 |
{
|
113 |
return calculator.computeSunriseTime(Zenith.CIVIL, date);
|
114 |
}
|
115 |
|
116 |
/**
|
117 |
* Returns the civil sunset (twilight, 96deg) for the given date.
|
118 |
*
|
119 |
* @param date
|
120 |
* <code>Calendar</code> object containing the date to compute the civil sunset for.
|
121 |
* @return the civil sunset time in HH:MM (24-hour clock) form.
|
122 |
*/
|
123 |
public String getCivilSunsetForDate(Calendar date)
|
124 |
{
|
125 |
return calculator.computeSunsetTime(Zenith.CIVIL, date);
|
126 |
}
|
127 |
|
128 |
/**
|
129 |
* Returns the official sunrise (90deg 50', 90.8333deg) for the given date.
|
130 |
*
|
131 |
* @param date
|
132 |
* <code>Calendar</code> object containing the date to compute the official sunrise for.
|
133 |
* @return the official sunrise time in HH:MM (24-hour clock) form.
|
134 |
*/
|
135 |
public String getOfficialSunriseForDate(Calendar date)
|
136 |
{
|
137 |
return calculator.computeSunriseTime(Zenith.OFFICIAL, date);
|
138 |
}
|
139 |
|
140 |
/**
|
141 |
* Returns the official sunrise (90deg 50', 90.8333deg) for the given date.
|
142 |
*
|
143 |
* @param date
|
144 |
* <code>Calendar</code> object containing the date to compute the official sunset for.
|
145 |
* @return the official sunset time in HH:MM (24-hour clock) form.
|
146 |
*/
|
147 |
public String getOfficialSunsetForDate(Calendar date)
|
148 |
{
|
149 |
return calculator.computeSunsetTime(Zenith.OFFICIAL, date);
|
150 |
}
|
151 |
|
152 |
/**
|
153 |
* Returns the location where the sunrise/sunset is calculated for.
|
154 |
*
|
155 |
* @return <code>Location</code> object representing the location of the computed sunrise/sunset.
|
156 |
*/
|
157 |
public Location2 getLocation()
|
158 |
{
|
159 |
return location;
|
160 |
}
|
161 |
}
|