public final class DayPeriod extends Object
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
| Modifier and Type | Method and Description |
|---|---|
ChronoFunction<ChronoDisplay,String> |
approximate()
Equivalent to
approximate(TextWidth.WIDE, OutputContext.FORMAT). |
ChronoFunction<ChronoDisplay,String> |
approximate(TextWidth width,
OutputContext outputContext)
Represents a flexible day period (in the afternoon, at night etc).
|
boolean |
equals(Object obj) |
ChronoFunction<ChronoDisplay,String> |
fixed()
Equivalent to
fixed(TextWidth.WIDE, OutputContext.FORMAT). |
ChronoFunction<ChronoDisplay,String> |
fixed(TextWidth width,
OutputContext outputContext)
Represents a fixed day period (am / pm / midnight / noon).
|
PlainTime |
getEnd(PlainTime context)
Determines the end of the day period which covers given clock time.
|
PlainTime |
getStart(PlainTime context)
Determines the start of the day period which covers given clock time.
|
int |
hashCode() |
static DayPeriod |
of(Locale locale)
Creates an instance based on locale-specific predefined data.
|
static DayPeriod |
of(Map<PlainTime,String> timeToLabels)
Creates an instance based on user-defined data.
|
String |
toString()
For debugging purposes.
|
public static DayPeriod of(Locale locale)
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.
locale - contains the language settingpublic static DayPeriod of(Map<PlainTime,String> timeToLabels)
Creates an instance based on user-defined data.
timeToLabels - map containing the day-periods where the keys represent starting points
and the values represent the associated labels intended for representationIllegalArgumentException - if given map is empty or contains empty valuespublic ChronoFunction<ChronoDisplay,String> fixed()
Equivalent to fixed(TextWidth.WIDE, OutputContext.FORMAT).
PlainTime etc.fixed(TextWidth, OutputContext)public ChronoFunction<ChronoDisplay,String> fixed(TextWidth width, OutputContext outputContext)
Represents a fixed day period (am / pm / midnight / noon).
The function returned can be applied on either PlainTime or PlainTimestamp.
Otherwise it throws a ChronoException if an instance of PlainTime cannot 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".
width - determines the text widthoutputContext - determines in which context to formatPlainTime etc.public ChronoFunction<ChronoDisplay,String> approximate()
Equivalent to approximate(TextWidth.WIDE, OutputContext.FORMAT).
PlainTime etc.approximate(TextWidth, OutputContext)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 PlainTime or PlainTimestamp.
Otherwise it throws a ChronoException if an instance of PlainTime cannot be found.
If no suitable text can be determined then the function falls back to AM/PM.
width - determines the text widthoutputContext - determines in which context to formatPlainTime etc.public PlainTime getStart(PlainTime context)
Determines the start of the day period which covers given clock time.
context - the clock time a day period is searched forgetEnd(PlainTime)public PlainTime getEnd(PlainTime context)
Determines the end of the day period which covers given clock time.
context - the clock time a day period is searched forgetStart(PlainTime)Copyright © 2014–2017. All rights reserved.