MCPcopy Create free account
hub / github.com/MenoData/Time4J / at

Method at

base/src/main/java/net/time4j/calendar/HebrewTime.java:470–525  ·  view source on GitHub ↗
(SolarTime geoLocation)

Source from the content-addressed store, hash-verified

468 * @see #on(HebrewCalendar, SolarTime)
469 */
470 public static ChronoFunction<Moment, Optional<HebrewTime>> at(SolarTime geoLocation) {
471
472 return (moment) -> {
473 ZonalOffset offset = ZonalOffset.atLongitude(new BigDecimal(geoLocation.getLongitude()));
474 PlainTimestamp tsp = moment.toZonalTimestamp(offset); // local mean time
475 Optional<Moment> sunset = tsp.toDate().get(geoLocation.sunset());
476
477 if (sunset.isPresent()) {
478 Optional<Moment> sunrise;
479 ClockCycle cycle = null;
480 Moment t1 = null;
481 Moment t2 = null;
482 if (moment.isBefore(sunset.get())) {
483 sunrise = tsp.toDate().get(geoLocation.sunrise());
484 if (sunrise.isPresent()) {
485 if (moment.isBefore(sunrise.get())) {
486 sunset = tsp.toDate().minus(1, CalendarUnit.DAYS).get(geoLocation.sunset());
487 if (sunset.isPresent()) {
488 cycle = ClockCycle.NIGHT;
489 t1 = sunset.get();
490 t2 = sunrise.get();
491 }
492 } else {
493 cycle = ClockCycle.DAY;
494 t1 = sunrise.get();
495 t2 = sunset.get();
496 }
497 }
498 } else {
499 sunrise = tsp.toDate().plus(1, CalendarUnit.DAYS).get(geoLocation.sunrise());
500 if (sunrise.isPresent()) {
501 cycle = ClockCycle.NIGHT;
502 t1 = sunset.get();
503 t2 = sunrise.get();
504 }
505 }
506 if (cycle != null && t1 != null && t2 != null) {
507 long halfDay =
508 t1.until(t2, TimeUnit.SECONDS) * 1_000_000_000L
509 + t2.getNanosecond()
510 - t1.getNanosecond();
511 long delta =
512 t1.until(moment, TimeUnit.SECONDS) * 1_000_000_000L
513 + moment.getNanosecond()
514 - t1.getNanosecond();
515 double halakim = (12.0 * PARTS_IN_HOUR * delta) / halfDay;
516 int hourOfCycle = (int) Math.floor(halakim / PARTS_IN_HOUR);
517 int partOfHour = (int) Math.floor(halakim - hourOfCycle * PARTS_IN_HOUR);
518 return Optional.of(new HebrewTime(cycle, ((hourOfCycle == 0) ? 12 : hourOfCycle), partOfHour));
519 }
520 }
521
522 return Optional.empty();
523 };
524
525 }
526
527 /**

Callers 4

atJerusalemMethod · 0.95
atTimezoneMethod · 0.95
nowMethod · 0.95
createFromMethod · 0.95

Calls 15

atLongitudeMethod · 0.95
toDateMethod · 0.95
untilMethod · 0.95
getNanosecondMethod · 0.95
getHourMethod · 0.95
toZonalTimestampMethod · 0.80
floorMethod · 0.80
subtractMethod · 0.80
getLongitudeMethod · 0.65
getMethod · 0.65
sunsetMethod · 0.65
isBeforeMethod · 0.65

Tested by 2

atJerusalemMethod · 0.76
atTimezoneMethod · 0.76