|
20 | 20 | import java.time.Duration; |
21 | 21 | import java.time.Instant; |
22 | 22 | import java.time.LocalDate; |
23 | | -import java.time.ZoneOffset; |
| 23 | +import java.time.ZoneId; |
24 | 24 | import java.time.ZonedDateTime; |
25 | | -import java.time.temporal.ChronoUnit; |
26 | 25 | import java.util.Calendar; |
27 | 26 |
|
28 | 27 | /** |
@@ -1234,38 +1233,34 @@ public boolean isTishaBav() { |
1234 | 1233 | public Instant getMoladAsInstant() { |
1235 | 1234 | JewishDate molad = getMolad(); |
1236 | 1235 |
|
1237 | | - // Har Habayis coordinates |
1238 | | - //double latitude = 31.778; |
1239 | | - double longitude = 35.2354; |
1240 | | - |
1241 | 1236 | // Standard time offset for Jerusalem: GMT+2 |
1242 | | - ZoneOffset jerusalemStandardOffset = ZoneOffset.ofHours(2); |
| 1237 | + // The raw molad Date (point in time) must be generated using standard time. Using "Asia/Jerusalem" timezone will |
| 1238 | + // result in the time being incorrectly off by an hour in the summer due to DST. Proper adjustment for the actual |
| 1239 | + // time in DST will be done by the date formatter class used to display the Date. |
| 1240 | + ZoneId jerusalemStandardOffset = ZoneId.of("GMT+2"); |
1243 | 1241 |
|
1244 | | - // Compute molad seconds from chalakim |
1245 | | - double moladSeconds = molad.getMoladChalakim() * 10.0 / 3.0; |
| 1242 | + double moladSeconds = molad.getMoladChalakim() * 10.0 / 3.0; // Compute molad seconds from chalakim |
1246 | 1243 | int seconds = (int) moladSeconds; |
1247 | | - int millis = (int) ((moladSeconds - seconds) * 1000); |
| 1244 | + int nanos = (int) ((moladSeconds - seconds) * 1_000_000_000); // convert remainder to nanos |
1248 | 1245 |
|
1249 | | - // Construct ZonedDateTime in standard time (GMT+2) |
1250 | 1246 | ZonedDateTime moladZdt = ZonedDateTime.of( |
1251 | 1247 | molad.getGregorianYear(), |
1252 | 1248 | molad.getGregorianMonth() +1, // 1-based FIXME |
1253 | 1249 | molad.getGregorianDayOfMonth(), |
1254 | 1250 | molad.getMoladHours(), |
1255 | 1251 | molad.getMoladMinutes(), |
1256 | 1252 | seconds, |
1257 | | - millis * 1_000_000, // nanos |
| 1253 | + nanos, |
1258 | 1254 | jerusalemStandardOffset |
1259 | 1255 | ); |
1260 | 1256 |
|
1261 | | - // Compute local mean time offset in milliseconds (example: 20.94 minutes = 1256400 ms) |
1262 | | - long localMeanOffsetMillis = (long) ((longitude - 35.0) * 4 * 60 * 1000); |
1263 | | - |
1264 | | - // Apply offset using ChronoUnit.MILLIS |
1265 | | - moladZdt = moladZdt.minus(localMeanOffsetMillis, ChronoUnit.MILLIS); |
| 1257 | + // Har Habayis at a longitude of 35.2354 offset vs longitude 35 in standard time, so we subtract the time difference |
| 1258 | + // of 20.94 minutes (20 minutes and 56 seconds and 496 millis) to get to Standard time from local mean time |
| 1259 | + Duration jerusalemStandardTimeOffset = Duration.ofMinutes(20) |
| 1260 | + .plusSeconds(56) |
| 1261 | + .plusMillis(496); |
1266 | 1262 |
|
1267 | | - // Return precise Instant |
1268 | | - return moladZdt.toInstant(); |
| 1263 | + return moladZdt.toInstant().minus(jerusalemStandardTimeOffset); |
1269 | 1264 | } |
1270 | 1265 |
|
1271 | 1266 | /** |
|
0 commit comments