Changed SunriseSunset constructor interface

Changed the SunriseSunset construtor to take the TimeZone as
parameter, leaving the offset calculations to its implementation.

Changed the SunriseSunset instantiation at DayNightHelper
accordingly.
This commit is contained in:
Goedson Teixeira Paixao 2011-10-18 17:05:38 -02:00
parent 3738a9990e
commit 91b5662a6f
2 changed files with 11 additions and 6 deletions

View file

@ -260,16 +260,21 @@ public class SunriseSunset
double dfLatIn, // latitude
double dfLonIn, // longitude
Date dateInputIn, // date
int dfTimeZoneIn // time zone
)
TimeZone tzIn // time zone
)
{
// Calculate internal representation of timezone offset as fraction of hours from GMT
// Our calculations consider offsets to the West as positive, so we must invert
// the signal of the values provided by the standard library
double dfTimeZoneIn = -1.0 * tzIn.getOffset(dateInputIn) / 3600000;
// Copy values supplied as agruments to local variables.
dfLat = dfLatIn;
dfLon = dfLonIn;
dateInput = dateInputIn;
dfTimeZone = 1.0 * dfTimeZoneIn / 60;
origTimeZone = 1.0 * dfTimeZoneIn / 60;
dfTimeZone = dfTimeZoneIn;
origTimeZone= dfTimeZoneIn;
// Call the method to do the calculations.
doCalculations();

View file

@ -88,7 +88,7 @@ public class DayNightHelper implements SensorEventListener {
Date actualTime = new Date();
SunriseSunset daynightSwitch = new SunriseSunset(lastKnownLocation.getLatitude(),
longitude < 0 ? 360 - longitude : longitude, actualTime,
-TimeZone.getDefault().getOffset(actualTime.getTime()) / 60000);
TimeZone.getDefault());
boolean daytime = daynightSwitch.isDaytime();
log.debug("Sunrise/sunset setting to day: " + daytime); //$NON-NLS-1$
lastAutoValue = Boolean.valueOf(daytime);