Class DayPeriod
Represents a period or part of a day usually in minute precision
as formattable extension to PlainTime.
The i18n-module is necessary to exploit the full functionality otherwise this class will just fall back to AM/PM only. Most non-English speaking countries completely ignore the notation of AM/PM but know day periods with finer granularity such as "in the morning", "evening" etc. Users can get extensive format support for day periods via the CLDR-pattern symbols b or B. The combination of half-day-hours with a day period is especially useful. Example of usage:
ChronoFormatter<PlainTime> f =
ChronoFormatter.ofTimePattern("h:mm BBBB", PatternType.CLDR, Locale.ENGLISH);
System.out.println(f.format(PlainTime.of(17, 15))); // output => 5:15 in the afternoon
- Since:
- 3.13/4.10
- Author:
- Meno Hochschild
-
Method Summary
Modifier and TypeMethodDescriptionEquivalent toapproximate(TextWidth.WIDE, OutputContext.FORMAT).approximate(TextWidth width, OutputContext outputContext)Represents a flexible day period (in the afternoon, at night etc).booleanfixed()Equivalent tofixed(TextWidth.WIDE, OutputContext.FORMAT).fixed(TextWidth width, OutputContext outputContext)Represents a fixed day period (am / pm / midnight / noon).Determines the end of the day period which covers given clock time.Determines the start of the day period which covers given clock time.inthashCode()static DayPeriodCreates an instance based on locale-specific predefined data.static DayPeriodCreates an instance based on user-defined data.toString()For debugging purposes.
-
Method Details
-
of
Creates an instance based on locale-specific predefined data.
If given locale does not point to any predefined data then Time4J will fall back to AM/PM.
- Parameters:
locale- contains the language setting- Returns:
- locale-specific instance
- Since:
- 3.13/4.10
-
of
Creates an instance based on user-defined data.
- Parameters:
timeToLabels- map containing the day-periods where the keys represent starting points and the values represent the associated labels intended for representation- Returns:
- user-specific instance
- Throws:
IllegalArgumentException- if given map is empty or contains empty values- Since:
- 3.13/4.10
-
fixed
Equivalent to
fixed(TextWidth.WIDE, OutputContext.FORMAT).- Returns:
- fixed textual representation of day period as function applicable on
PlainTimeetc. - Since:
- 3.13/4.10
- See Also:
fixed(TextWidth, OutputContext)
-
fixed
Represents a fixed day period (am / pm / midnight / noon).
The function returned can be applied on either
PlainTimeorPlainTimestamp. Otherwise it throws aChronoExceptionif an instance ofPlainTimecannot be found. If this day period was not created for a locale then the function will just return one of the literals "am", "pm", "midnight" or "noon".- Parameters:
width- determines the text widthoutputContext- determines in which context to format- Returns:
- fixed textual representation of day period as function applicable on
PlainTimeetc. - Since:
- 3.13/4.10
-
approximate
Equivalent to
approximate(TextWidth.WIDE, OutputContext.FORMAT).- Returns:
- approximate textual representation of day period as function applicable on
PlainTimeetc. - Since:
- 3.13/4.10
- See Also:
approximate(TextWidth, OutputContext)
-
approximate
public ChronoFunction<ChronoDisplay,String> approximate(TextWidth width, OutputContext outputContext)Represents a flexible day period (in the afternoon, at night etc).
The function returned can be applied on either
PlainTimeorPlainTimestamp. Otherwise it throws aChronoExceptionif an instance ofPlainTimecannot be found. If no suitable text can be determined then the function falls back to AM/PM.- Parameters:
width- determines the text widthoutputContext- determines in which context to format- Returns:
- approximate textual representation of day period as function applicable on
PlainTimeetc. - Since:
- 3.13/4.10
-
getStart
Determines the start of the day period which covers given clock time.
- Parameters:
context- the clock time a day period is searched for- Returns:
- start of day period around given clock time, inclusive
- Since:
- 3.13/4.10
- See Also:
getEnd(PlainTime)
-
getEnd
Determines the end of the day period which covers given clock time.
- Parameters:
context- the clock time a day period is searched for- Returns:
- end of day period around given clock time, exclusive
- Since:
- 3.13/4.10
- See Also:
getStart(PlainTime)
-
equals
-
hashCode
public int hashCode() -
toString
For debugging purposes.
-