Package net.time4j.engine
Class StartOfDay
java.lang.Object
net.time4j.engine.StartOfDay
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 Summary
Modifier and TypeFieldDescriptionstatic StartOfDay
Start of calendar day at 18:00 on previous day.static StartOfDay
Default start of calendar day at midnight.static StartOfDay
Start of calendar day at 06:00 in the morning. -
Method Summary
Modifier and TypeMethodDescriptionstatic <T extends UnixTime>
StartOfDaydefinedBy(ChronoFunction<CalendarDate,Optional<T>> event)
Obtains the start of a calendar day as determined by given date function.abstract int
getDeviation(CalendarDate calendarDay, TZID tzid)
Yields the start of given calendar day relative to midnight in seconds.static StartOfDay
ofFixedDeviation(int deviation)
Obtains the start of a calendar day relative to midnight in fixed seconds.
-
Field Details
-
MIDNIGHT
Default start of calendar day at midnight. -
EVENING
Start of calendar day at 18:00 on previous day. Used inHebrewCalendar
andHijriCalendar
as rough approximation for sunset. However, most users should apply an astronomical definition.- See Also:
definedBy(ChronoFunction)
-
MORNING
Start of calendar day at 06:00 in the morning.- See Also:
EthiopianCalendar
-
-
Method Details
-
ofFixedDeviation
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
Yields the start of given calendar day relative to midnight in seconds.
- Parameters:
calendarDay
- calendar daytzid
- 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
-