Class StartOfDay

java.lang.Object
net.time4j.engine.StartOfDay

public abstract class StartOfDay extends Object

Defines the start of a given calendar day relative to midnight in seconds.

Note: All subclasses must be immutable.

Since:
3.5/4.3
Author:
Meno Hochschild
  • Field Details

    • MIDNIGHT

      public static final StartOfDay MIDNIGHT
      Default start of calendar day at midnight.
    • EVENING

      public static final StartOfDay EVENING
      Start of calendar day at 18:00 on previous day. Used in HebrewCalendar and HijriCalendar as rough approximation for sunset. However, most users should apply an astronomical definition.
      See Also:
      definedBy(ChronoFunction)
    • MORNING

      public static final StartOfDay MORNING
      Start of calendar day at 06:00 in the morning.
      See Also:
      EthiopianCalendar
  • Method Details

    • ofFixedDeviation

      public static StartOfDay ofFixedDeviation(int deviation)

      Obtains the start of a calendar day relative to midnight in fixed seconds.

      A negative deviation is explicitly allowed and refers to the previous calendar day.

      Parameters:
      deviation - the deviation of start of day relative to midnight in seconds on the local timeline
      Returns:
      start of day
      Throws:
      IllegalArgumentException - if the argument is out of range -43200 < deviation <= 43200
      Since:
      3.5/4.3
    • definedBy

      public static <T extends UnixTime> StartOfDay definedBy(ChronoFunction<CalendarDate,​Optional<T>> event)

      Obtains the start of a calendar day as determined by given date function.

      If the given function cannot determine a moment for a calendar day then an exception will be thrown. This method is most suitable for calendars whose days start on astronomical events like sunset. Example:

           HijriCalendar hijri = HijriCalendar.ofUmalqura(1436, 10, 2);
           SolarTime mekkaTime = SolarTime.ofLocation(21.4225, 39.826111);
           ZonalOffset saudiArabia = ZonalOffset.ofHours(OffsetSign.AHEAD_OF_UTC, 3);
           StartOfDay startOfDay = StartOfDay.definedBy(mekkaTime.sunset());
      
           // short after sunset (2015-07-17T19:05:40)
           System.out.println(
               hijri.atTime(19, 6).at(saudiArabia, startOfDay)); // 2015-07-17T19:06+03:00
      
           // short before sunset (2015-07-17T19:05:40)
           System.out.println(
               hijri.minus(CalendarDays.ONE).atTime(19, 5).at(saudiArabia, startOfDay)); // 2015-07-17T19:05+03:00
       
      Type Parameters:
      T - generic type parameter indicating the time of the event
      Parameters:
      event - function which yields the relevant moment for a given calendar day
      Returns:
      start of day
      Since:
      3.34/4.29
    • getDeviation

      public abstract int getDeviation(CalendarDate calendarDay, TZID tzid)

      Yields the start of given calendar day relative to midnight in seconds.

      Parameters:
      calendarDay - calendar day
      tzid - timezone identifier, helps to resolve an UTC-event like sunset to a local time
      Returns:
      nominal deviation of start of day relative to midnight in seconds on the local timeline
      Since:
      5.0