-
-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #851 from forrestguice/build
remove jitpack.io from build
- Loading branch information
Showing
41 changed files
with
3,554 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
665 changes: 665 additions & 0 deletions
665
app/src/main/java/ca/rmen/sunrisesunset/SunriseSunset.java
Large diffs are not rendered by default.
Oops, something went wrong.
290 changes: 290 additions & 0 deletions
290
app/src/main/java/com/luckycatlabs/sunrisesunset/SunriseSunsetCalculator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,290 @@ | ||
/* | ||
* Copyright 2008-2009 Mike Reedell / LuckyCatLabs. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.luckycatlabs.sunrisesunset; | ||
|
||
import java.util.Calendar; | ||
import java.util.TimeZone; | ||
|
||
import com.luckycatlabs.sunrisesunset.calculator.SolarEventCalculator; | ||
import com.luckycatlabs.sunrisesunset.dto.Location; | ||
|
||
/** | ||
* Public interface for getting the various types of sunrise/sunset. | ||
*/ | ||
public class SunriseSunsetCalculator { | ||
|
||
private Location location; | ||
|
||
private SolarEventCalculator calculator; | ||
|
||
/** | ||
* Constructs a new <code>SunriseSunsetCalculator</code> with the given <code>Location</code> | ||
* | ||
* @param location | ||
* <code>Location</code> object containing the Latitude/Longitude of the location to compute | ||
* the sunrise/sunset for. | ||
* @param timeZoneIdentifier | ||
* String identifier for the timezone to compute the sunrise/sunset times in. In the form | ||
* "America/New_York". Please see the zi directory under the JDK installation for supported | ||
* time zones. | ||
*/ | ||
public SunriseSunsetCalculator(Location location, String timeZoneIdentifier) { | ||
this.location = location; | ||
this.calculator = new SolarEventCalculator(location, timeZoneIdentifier); | ||
} | ||
|
||
/** | ||
* Constructs a new <code>SunriseSunsetCalculator</code> with the given <code>Location</code> | ||
* | ||
* @param location | ||
* <code>Location</code> object containing the Latitude/Longitude of the location to compute | ||
* the sunrise/sunset for. | ||
* @param timeZone | ||
* timezone to compute the sunrise/sunset times in. | ||
*/ | ||
public SunriseSunsetCalculator(Location location, TimeZone timeZone) { | ||
this.location = location; | ||
this.calculator = new SolarEventCalculator(location, timeZone); | ||
} | ||
|
||
/** | ||
* Returns the astronomical (108deg) sunrise for the given date. | ||
* | ||
* @param date | ||
* <code>Calendar</code> object containing the date to compute the astronomical sunrise for. | ||
* @return the astronomical sunrise time in HH:MM (24-hour clock) form. | ||
*/ | ||
public String getAstronomicalSunriseForDate(Calendar date) { | ||
return calculator.computeSunriseTime(Zenith.ASTRONOMICAL, date); | ||
} | ||
|
||
/** | ||
* Returns the astronomical (108deg) sunrise for the given date. | ||
* | ||
* @param date | ||
* <code>Calendar</code> object containing the date to compute the astronomical sunrise for. | ||
* @return the astronomical sunrise time as a Calendar | ||
*/ | ||
public Calendar getAstronomicalSunriseCalendarForDate(Calendar date) { | ||
return calculator.computeSunriseCalendar(Zenith.ASTRONOMICAL, date); | ||
} | ||
|
||
/** | ||
* Returns the astronomical (108deg) sunset for the given date. | ||
* | ||
* @param date | ||
* <code>Calendar</code> object containing the date to compute the astronomical sunset for. | ||
* @return the astronomical sunset time in HH:MM (24-hour clock) form. | ||
*/ | ||
public String getAstronomicalSunsetForDate(Calendar date) { | ||
return calculator.computeSunsetTime(Zenith.ASTRONOMICAL, date); | ||
} | ||
|
||
/** | ||
* Returns the astronomical (108deg) sunset for the given date. | ||
* | ||
* @param date | ||
* <code>Calendar</code> object containing the date to compute the astronomical sunset for. | ||
* @return the astronomical sunset time as a Calendar | ||
*/ | ||
public Calendar getAstronomicalSunsetCalendarForDate(Calendar date) { | ||
return calculator.computeSunsetCalendar(Zenith.ASTRONOMICAL, date); | ||
} | ||
|
||
/** | ||
* Returns the nautical (102deg) sunrise for the given date. | ||
* | ||
* @param date | ||
* <code>Calendar</code> object containing the date to compute the nautical sunrise for. | ||
* @return the nautical sunrise time in HH:MM (24-hour clock) form. | ||
*/ | ||
public String getNauticalSunriseForDate(Calendar date) { | ||
return calculator.computeSunriseTime(Zenith.NAUTICAL, date); | ||
} | ||
|
||
/** | ||
* Returns the nautical (102deg) sunrise for the given date. | ||
* | ||
* @param date | ||
* <code>Calendar</code> object containing the date to compute the nautical sunrise for. | ||
* @return the nautical sunrise time as a Calendar | ||
*/ | ||
public Calendar getNauticalSunriseCalendarForDate(Calendar date) { | ||
return calculator.computeSunriseCalendar(Zenith.NAUTICAL, date); | ||
} | ||
|
||
/** | ||
* Returns the nautical (102deg) sunset for the given date. | ||
* | ||
* @param date | ||
* <code>Calendar</code> object containing the date to compute the nautical sunset for. | ||
* @return the nautical sunset time in HH:MM (24-hour clock) form. | ||
*/ | ||
public String getNauticalSunsetForDate(Calendar date) { | ||
return calculator.computeSunsetTime(Zenith.NAUTICAL, date); | ||
} | ||
|
||
/** | ||
* Returns the nautical (102deg) sunset for the given date. | ||
* | ||
* @param date | ||
* <code>Calendar</code> object containing the date to compute the nautical sunset for. | ||
* @return the nautical sunset time as a Calendar | ||
*/ | ||
public Calendar getNauticalSunsetCalendarForDate(Calendar date) { | ||
return calculator.computeSunsetCalendar(Zenith.NAUTICAL, date); | ||
} | ||
|
||
/** | ||
* Returns the civil sunrise (twilight, 96deg) for the given date. | ||
* | ||
* @param date | ||
* <code>Calendar</code> object containing the date to compute the civil sunrise for. | ||
* @return the civil sunrise time in HH:MM (24-hour clock) form. | ||
*/ | ||
public String getCivilSunriseForDate(Calendar date) { | ||
return calculator.computeSunriseTime(Zenith.CIVIL, date); | ||
} | ||
|
||
/** | ||
* Returns the civil sunrise (twilight, 96deg) for the given date. | ||
* | ||
* @param date | ||
* <code>Calendar</code> object containing the date to compute the civil sunrise for. | ||
* @return the civil sunrise time as a Calendar | ||
*/ | ||
public Calendar getCivilSunriseCalendarForDate(Calendar date) { | ||
return calculator.computeSunriseCalendar(Zenith.CIVIL, date); | ||
} | ||
|
||
/** | ||
* Returns the civil sunset (twilight, 96deg) for the given date. | ||
* | ||
* @param date | ||
* <code>Calendar</code> object containing the date to compute the civil sunset for. | ||
* @return the civil sunset time in HH:MM (24-hour clock) form. | ||
*/ | ||
public String getCivilSunsetForDate(Calendar date) { | ||
return calculator.computeSunsetTime(Zenith.CIVIL, date); | ||
} | ||
|
||
/** | ||
* Returns the civil sunset (twilight, 96deg) for the given date. | ||
* | ||
* @param date | ||
* <code>Calendar</code> object containing the date to compute the civil sunset for. | ||
* @return the civil sunset time as a Calendar | ||
*/ | ||
public Calendar getCivilSunsetCalendarForDate(Calendar date) { | ||
return calculator.computeSunsetCalendar(Zenith.CIVIL, date); | ||
} | ||
|
||
/** | ||
* Returns the official sunrise (90deg 50', 90.8333deg) for the given date. | ||
* | ||
* @param date | ||
* <code>Calendar</code> object containing the date to compute the official sunrise for. | ||
* @return the official sunrise time in HH:MM (24-hour clock) form. | ||
*/ | ||
public String getOfficialSunriseForDate(Calendar date) { | ||
return calculator.computeSunriseTime(Zenith.OFFICIAL, date); | ||
} | ||
|
||
/** | ||
* Returns the official sunrise (90deg 50', 90.8333deg) for the given date. | ||
* | ||
* @param date | ||
* <code>Calendar</code> object containing the date to compute the official sunrise for. | ||
* @return the official sunrise time as a Calendar | ||
*/ | ||
public Calendar getOfficialSunriseCalendarForDate(Calendar date) { | ||
return calculator.computeSunriseCalendar(Zenith.OFFICIAL, date); | ||
} | ||
|
||
/** | ||
* Returns the official sunrise (90deg 50', 90.8333deg) for the given date. | ||
* | ||
* @param date | ||
* <code>Calendar</code> object containing the date to compute the official sunset for. | ||
* @return the official sunset time in HH:MM (24-hour clock) form. | ||
*/ | ||
public String getOfficialSunsetForDate(Calendar date) { | ||
return calculator.computeSunsetTime(Zenith.OFFICIAL, date); | ||
} | ||
|
||
/** | ||
* Returns the official sunrise (90deg 50', 90.8333deg) for the given date. | ||
* | ||
* @param date | ||
* <code>Calendar</code> object containing the date to compute the official sunset for. | ||
* @return the official sunset time as a Calendar | ||
*/ | ||
public Calendar getOfficialSunsetCalendarForDate(Calendar date) { | ||
return calculator.computeSunsetCalendar(Zenith.OFFICIAL, date); | ||
} | ||
|
||
/** | ||
* Computes the sunrise for an arbitrary declination. | ||
* | ||
* @param latitude | ||
* @param longitude | ||
* Coordinates for the location to compute the sunrise/sunset for. | ||
* @param timeZone | ||
* timezone to compute the sunrise/sunset times in. | ||
* @param date | ||
* <code>Calendar</code> object containing the date to compute the official sunset for. | ||
* @param degrees | ||
* Angle under the horizon for which to compute sunrise. For example, "civil sunrise" | ||
* corresponds to 6 degrees. | ||
* @return the requested sunset time as a <code>Calendar</code> object. | ||
*/ | ||
|
||
public static Calendar getSunrise(double latitude, double longitude, TimeZone timeZone, Calendar date, double degrees) { | ||
SolarEventCalculator solarEventCalculator = new SolarEventCalculator(new Location(latitude, longitude), timeZone); | ||
return solarEventCalculator.computeSunriseCalendar(new Zenith(90 - degrees), date); | ||
} | ||
|
||
/** | ||
* Computes the sunset for an arbitrary declination. | ||
* | ||
* @param latitude | ||
* @param longitude | ||
* Coordinates for the location to compute the sunrise/sunset for. | ||
* @param timeZone | ||
* timezone to compute the sunrise/sunset times in. | ||
* @param date | ||
* <code>Calendar</code> object containing the date to compute the official sunset for. | ||
* @param degrees | ||
* Angle under the horizon for which to compute sunrise. For example, "civil sunset" | ||
* corresponds to 6 degrees. | ||
* @return the requested sunset time as a <code>Calendar</code> object. | ||
*/ | ||
|
||
public static Calendar getSunset(double latitude, double longitude, TimeZone timeZone, Calendar date, double degrees) { | ||
SolarEventCalculator solarEventCalculator = new SolarEventCalculator(new Location(latitude, longitude), timeZone); | ||
return solarEventCalculator.computeSunsetCalendar(new Zenith(90 - degrees), date); | ||
} | ||
|
||
/** | ||
* Returns the location where the sunrise/sunset is calculated for. | ||
* | ||
* @return <code>Location</code> object representing the location of the computed sunrise/sunset. | ||
*/ | ||
public Location getLocation() { | ||
return location; | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
app/src/main/java/com/luckycatlabs/sunrisesunset/Zenith.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Copyright 2008-2009 Mike Reedell / LuckyCatLabs. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.luckycatlabs.sunrisesunset; | ||
|
||
import java.math.BigDecimal; | ||
|
||
/** | ||
* Defines the solar declination used in computing the sunrise/sunset. | ||
*/ | ||
public class Zenith { | ||
/** Astronomical sunrise/set is when the sun is 18 degrees below the horizon. */ | ||
public static final Zenith ASTRONOMICAL = new Zenith(108); | ||
|
||
/** Nautical sunrise/set is when the sun is 12 degrees below the horizon. */ | ||
public static final Zenith NAUTICAL = new Zenith(102); | ||
|
||
/** Civil sunrise/set (dawn/dusk) is when the sun is 6 degrees below the horizon. */ | ||
public static final Zenith CIVIL = new Zenith(96); | ||
|
||
/** Official sunrise/set is when the sun is 50' below the horizon. */ | ||
public static final Zenith OFFICIAL = new Zenith(90.8333); | ||
|
||
private final BigDecimal degrees; | ||
|
||
public Zenith(double degrees) { | ||
this.degrees = BigDecimal.valueOf(degrees); | ||
} | ||
|
||
public BigDecimal degrees() { | ||
return degrees; | ||
} | ||
} |
Oops, something went wrong.