Closed ABCOM2000 closed 10 years ago
The following test returns sunrise offset by 30 minutes.
Location location = new Location("19.01441", "72.84794"); SunriseSunsetCalculator calculator = new SunriseSunsetCalculator(location, "Asia/Kolkata"); Calendar calendar = Calendar.getInstance(); calendar.setTimeZone(TimeZone.getTimeZone("Asia/Kolkata")); String sunrise = calculator.getCivilSunriseForDate(calendar);
I solved this problem by making a few corrections in the getUTCOffSet method (SolarEventCalculator.java). The modified function is given below:
private BigDecimal getUTCOffSet(Calendar date) { float offSetInMillis = date.get(Calendar.ZONE_OFFSET); BigDecimal offSet = new BigDecimal(offSetInMillis / 3600000); return offSet.setScale(1, RoundingMode.HALF_EVEN); }
The data type of offSetInMillis is changed from int to float and setScale is set to 1. This strikes another point in my head. If the timezone offset is 05:45 (Kathmandu, Nepal), we may need to set the scale to 2. Check out!
The following test returns sunrise offset by 30 minutes.
Location location = new Location("19.01441", "72.84794"); SunriseSunsetCalculator calculator = new SunriseSunsetCalculator(location, "Asia/Kolkata"); Calendar calendar = Calendar.getInstance(); calendar.setTimeZone(TimeZone.getTimeZone("Asia/Kolkata")); String sunrise = calculator.getCivilSunriseForDate(calendar);
I solved this problem by making a few corrections in the getUTCOffSet method (SolarEventCalculator.java). The modified function is given below:
private BigDecimal getUTCOffSet(Calendar date) { float offSetInMillis = date.get(Calendar.ZONE_OFFSET); BigDecimal offSet = new BigDecimal(offSetInMillis / 3600000); return offSet.setScale(1, RoundingMode.HALF_EVEN); }
The data type of offSetInMillis is changed from int to float and setScale is set to 1. This strikes another point in my head. If the timezone offset is 05:45 (Kathmandu, Nepal), we may need to set the scale to 2. Check out!