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 |
* Public interface for getting the various types of sunrise/sunset.
|
26 |
*/
|
27 |
public class SunriseSunsetCalculator
|
28 |
{
|
29 |
|
30 |
private Location2 location;
|
31 |
|
32 |
private SolarEventCalculator calculator;
|
33 |
|
34 |
/**
|
35 |
* Constructs a new <code>SunriseSunsetCalculator</code> with the given <code>Location</code>
|
36 |
*
|
37 |
* @param location
|
38 |
* <code>Location</code> object containing the Latitude/Longitude of the location to compute
|
39 |
* the sunrise/sunset for.
|
40 |
* @param timeZoneIdentifier
|
41 |
* String identifier for the timezone to compute the sunrise/sunset times in. In the form
|
42 |
* "America/New_York". Please see the zi directory under the JDK installation for supported
|
43 |
* time zones.
|
44 |
*/
|
45 |
public SunriseSunsetCalculator(Location2 location, String timeZoneIdentifier)
|
46 |
{
|
47 |
this.calculator = new SolarEventCalculator(location, timeZoneIdentifier);
|
48 |
}
|
49 |
|
50 |
/**
|
51 |
* Returns the astronomical (108deg) sunrise for the given date.
|
52 |
*
|
53 |
* @param date
|
54 |
* <code>Calendar</code> object containing the date to compute the astronomical sunrise for.
|
55 |
* @return the astronomical sunrise time in HH:MM (24-hour clock) form.
|
56 |
*/
|
57 |
public String getAstronomicalSunriseForDate(Calendar date)
|
58 |
{
|
59 |
return calculator.computeSunriseTime(Zenith.ASTRONOMICAL, date);
|
60 |
}
|
61 |
|
62 |
public SolarEventCalculator.moonCoor_ret computeMoon(Calendar date)
|
63 |
{
|
64 |
return (calculator.computeMoonStats(date));
|
65 |
}
|
66 |
|
67 |
/**
|
68 |
* Returns the astronomical (108deg) sunset for the given date.
|
69 |
*
|
70 |
* @param date
|
71 |
* <code>Calendar</code> object containing the date to compute the astronomical sunset for.
|
72 |
* @return the astronomical sunset time in HH:MM (24-hour clock) form.
|
73 |
*/
|
74 |
public String getAstronomicalSunsetForDate(Calendar date)
|
75 |
{
|
76 |
return calculator.computeSunsetTime(Zenith.ASTRONOMICAL, date);
|
77 |
}
|
78 |
|
79 |
/**
|
80 |
* Returns the nautical (102deg) sunrise for the given date.
|
81 |
*
|
82 |
* @param date
|
83 |
* <code>Calendar</code> object containing the date to compute the nautical sunrise for.
|
84 |
* @return the nautical sunrise time in HH:MM (24-hour clock) form.
|
85 |
*/
|
86 |
public String getNauticalSunriseForDate(Calendar date)
|
87 |
{
|
88 |
return calculator.computeSunriseTime(Zenith.NAUTICAL, date);
|
89 |
}
|
90 |
|
91 |
/**
|
92 |
* Returns the nautical (102deg) sunset for the given date.
|
93 |
*
|
94 |
* @param date
|
95 |
* <code>Calendar</code> object containing the date to compute the nautical sunset for.
|
96 |
* @return the nautical sunset time in HH:MM (24-hour clock) form.
|
97 |
*/
|
98 |
public String getNauticalSunsetForDate(Calendar date)
|
99 |
{
|
100 |
return calculator.computeSunsetTime(Zenith.NAUTICAL, date);
|
101 |
}
|
102 |
|
103 |
/**
|
104 |
* Returns the civil sunrise (twilight, 96deg) for the given date.
|
105 |
*
|
106 |
* @param date
|
107 |
* <code>Calendar</code> object containing the date to compute the civil sunrise for.
|
108 |
* @return the civil sunrise time in HH:MM (24-hour clock) form.
|
109 |
*/
|
110 |
public String getCivilSunriseForDate(Calendar date)
|
111 |
{
|
112 |
return calculator.computeSunriseTime(Zenith.CIVIL, date);
|
113 |
}
|
114 |
|
115 |
/**
|
116 |
* Returns the civil sunset (twilight, 96deg) for the given date.
|
117 |
*
|
118 |
* @param date
|
119 |
* <code>Calendar</code> object containing the date to compute the civil sunset for.
|
120 |
* @return the civil sunset time in HH:MM (24-hour clock) form.
|
121 |
*/
|
122 |
public String getCivilSunsetForDate(Calendar date)
|
123 |
{
|
124 |
return calculator.computeSunsetTime(Zenith.CIVIL, date);
|
125 |
}
|
126 |
|
127 |
/**
|
128 |
* Returns the official sunrise (90deg 50', 90.8333deg) for the given date.
|
129 |
*
|
130 |
* @param date
|
131 |
* <code>Calendar</code> object containing the date to compute the official sunrise for.
|
132 |
* @return the official sunrise time in HH:MM (24-hour clock) form.
|
133 |
*/
|
134 |
public String getOfficialSunriseForDate(Calendar date)
|
135 |
{
|
136 |
return calculator.computeSunriseTime(Zenith.OFFICIAL, date);
|
137 |
}
|
138 |
|
139 |
/**
|
140 |
* Returns the official sunrise (90deg 50', 90.8333deg) for the given date.
|
141 |
*
|
142 |
* @param date
|
143 |
* <code>Calendar</code> object containing the date to compute the official sunset for.
|
144 |
* @return the official sunset time in HH:MM (24-hour clock) form.
|
145 |
*/
|
146 |
public String getOfficialSunsetForDate(Calendar date)
|
147 |
{
|
148 |
return calculator.computeSunsetTime(Zenith.OFFICIAL, date);
|
149 |
}
|
150 |
|
151 |
/**
|
152 |
* Returns the location where the sunrise/sunset is calculated for.
|
153 |
*
|
154 |
* @return <code>Location</code> object representing the location of the computed sunrise/sunset.
|
155 |
*/
|
156 |
public Location2 getLocation()
|
157 |
{
|
158 |
return location;
|
159 |
}
|
160 |
}
|