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