Class CalendarMonth
- All Implemented Interfaces:
Serializable
,Comparable<CalendarMonth>
,Iterable<PlainDate>
,TemporalAccessor
,ChronoDisplay
,ThreetenAdapter
,LocalizedPatternSupport
,ChronoInterval<PlainDate>
Represents the month of a gregorian calendar year as interval (like from 1st of January until end of January).
The elements registered by this class are:
Formatting example for localized styles:
ChronoFormatter<CalendarMonth> usStyle = ChronoFormatter.ofStyle(DisplayMode.SHORT, Locale.US, CalendarMonth.chronology()); ChronoFormatter<CalendarMonth> germanStyle = ChronoFormatter.ofStyle(DisplayMode.SHORT, Locale.GERMANY, CalendarMonth.chronology()); System.out.println("US-format: " + usStyle.format(CalendarMonth.of(2016, 5))); // US-format: 5/2016 System.out.println("German: " + germanStyle.format(CalendarMonth.of(2016, 5))); // German: 5.2016
Note: The current month of calendar year can be determined by an expression like:
nowInSystemTime()
or in a more general way
CalendarMonth current = SystemClock.inLocalView().now(CalendarMonth.chronology())
.
- Since:
- 3.21/4.17
- Author:
- Meno Hochschild
- See Also:
- Serialized Form
-
Field Summary
Modifier and TypeFieldDescriptionstatic ChronoElement<Integer>
Element with the month as number in the value range1 - 12
.static ChronoElement<Month>
Element with the month of year in the value rangeJanuary - December
.static ChronoElement<Integer>
Element with the proleptic iso-year without any era reference and the value range-999999999
until999999999
. -
Method Summary
Modifier and TypeMethodDescriptionatDayOfMonth(int dayOfMonth)
Combines this year and month with given day of month to a calendar date.Yields the date of the end of this calendar month.static Chronology<CalendarMonth>
Yields the associated chronology.int
compareTo(CalendarMonth other)
boolean
Queries if given time point belongs to this interval.boolean
static CalendarMonth
Converts given JSR-310-type to a calendar month.static CalendarMonth
from(GregorianDate date)
Converts given gregorian date to a calendar month.getEnd()
Yields the upper bound of this interval.getMonth()
Yields the month as enum.getStart()
Yields the lower bound of this interval.int
getYear()
Yields the year number.int
hashCode()
boolean
Is this interval after the given time point?boolean
Is this interval before the given time point?iterator()
Iterates over all days of this calendar month.int
length()
Determines the count of days belonging to this month.Subtracts given months from this calendar month.minus(Years<CalendarUnit> years)
Subtracts given years from this calendar month.static CalendarMonth
Obtains the current calendar month in system time.static CalendarMonth
of(int year, int month)
Creates a new instance based on given gregorian calendar year and month.static CalendarMonth
Creates a new instance based on given gregorian calendar year and month.static CalendarMonth
Interpretes given ISO-conforming text as calendar month.Adds given months to this calendar month.plus(Years<CalendarUnit> years)
Adds given years to this calendar month.static Chronology<YearMonth>
threeten()
Obtains a bridge chronology for the typejava.time.YearMonth
.static TimeLine<CalendarMonth>
timeline()
Obtains a timeline for this type.toString()
Outputs this instance as a String in CLDR-format "uuuu-MM" (like "2016-10").Converts this object to aTemporalAccessor
.Methods inherited from class net.time4j.range.FixedCalendarInterval
abuts, contains, isBefore, isEmpty, isFinite, isSimultaneous, streamDaily, toFlexInterval, withValue
Methods inherited from class net.time4j.engine.ChronoEntity
contains, get, get, getInt, getMaximum, getMinimum, getRegisteredElements, getTimezone, hasTimezone, isValid, isValid, isValid, matches, with, with, with, with
Methods inherited from interface net.time4j.range.ChronoInterval
intersects, isAfter
Methods inherited from interface java.lang.Iterable
forEach, spliterator
Methods inherited from interface net.time4j.format.LocalizedPatternSupport
getFormatPattern, getFormatPattern, useDynamicFormatPattern
Methods inherited from interface net.time4j.engine.ThreetenAdapter
get, getLong, isSupported, query, range
-
Field Details
-
YEAR
Element with the proleptic iso-year without any era reference and the value range
-999999999
until999999999
.The term "proleptic" means that the rules of the gregorian calendar and the associated way of year counting is applied backward even before the introduction of gregorian calendar. The year
0
is permitted - and negative years, too. For historic year numbers, this mathematical extrapolation is not recommended and usually wrong. -
MONTH_OF_YEAR
Element with the month of year in the value range
January - December
. -
MONTH_AS_NUMBER
Element with the month as number in the value range
1 - 12
.
-
-
Method Details
-
of
Creates a new instance based on given gregorian calendar year and month.
- Parameters:
year
- gregorian year within range-999,999,999 / +999,999,999
month
- gregorian month in range 1-12- Returns:
- new instance
- Throws:
IllegalArgumentException
- if any argument is out of range
-
of
Creates a new instance based on given gregorian calendar year and month.
- Parameters:
year
- gregorian year within range-999,999,999 / +999,999,999
month
- gregorian month- Returns:
- new instance
- Throws:
IllegalArgumentException
- if given year is out of range
-
nowInSystemTime
Obtains the current calendar month in system time.
Convenient short-cut for:
SystemClock.inLocalView().now(CalendarMonth.chronology())
.- Returns:
- current calendar month in system time zone using the system clock
- Since:
- 3.24/4.20
- See Also:
SystemClock.inLocalView()
,ZonalClock.now(net.time4j.engine.Chronology)
-
atDayOfMonth
Combines this year and month with given day of month to a calendar date.
- Parameters:
dayOfMonth
- day of month in range 1-28/29/30/31- Returns:
- calendar date
- Throws:
IllegalArgumentException
- if the day-of-month is out of range
-
atEndOfMonth
Yields the date of the end of this calendar month.
- Returns:
- PlainDate
-
getYear
public int getYear()Yields the year number.
- Returns:
- int
-
getMonth
Yields the month as enum.
User who wish to get the month as integer can use the expression
getMonth().getValue()
.- Returns:
- Month
-
getStart
Description copied from interface:ChronoInterval
Yields the lower bound of this interval.
- Specified by:
getStart
in interfaceChronoInterval<PlainDate>
- Returns:
- start interval boundary
-
getEnd
Description copied from interface:ChronoInterval
Yields the upper bound of this interval.
- Specified by:
getEnd
in interfaceChronoInterval<PlainDate>
- Returns:
- end interval boundary
-
contains
Description copied from interface:ChronoInterval
Queries if given time point belongs to this interval.
- Specified by:
contains
in interfaceChronoInterval<PlainDate>
- Parameters:
temporal
- time point to be queried- Returns:
true
if given time point belongs to this interval elsefalse
-
isAfter
Description copied from interface:ChronoInterval
Is this interval after the given time point?
- Specified by:
isAfter
in interfaceChronoInterval<PlainDate>
- Parameters:
temporal
- reference time point- Returns:
true
if this interval is after given time point elsefalse
-
isBefore
Description copied from interface:ChronoInterval
Is this interval before the given time point?
- Specified by:
isBefore
in interfaceChronoInterval<PlainDate>
- Parameters:
temporal
- reference time point- Returns:
true
if this interval is before given time point elsefalse
-
length
public int length()Determines the count of days belonging to this month.
- Returns:
- int
-
from
Converts given gregorian date to a calendar month.
- Parameters:
date
- gregorian calendar date (for examplePlainDate
- Returns:
- CalendarMonth
- Throws:
IllegalArgumentException
- if given date is invalid- Since:
- 3.28/4.24
-
from
Converts given JSR-310-type to a calendar month.
- Parameters:
yearMonth
- Threeten-equivalent of this instance- Returns:
- CalendarMonth
- See Also:
toTemporalAccessor()
-
plus
Adds given years to this calendar month.
- Parameters:
years
- the count of years to be added- Returns:
- result of addition
-
plus
Adds given months to this calendar month.
- Parameters:
months
- the count of months to be added- Returns:
- result of addition
-
minus
Subtracts given years from this calendar month.
- Parameters:
years
- the count of years to be subtracted- Returns:
- result of subtraction
-
minus
Subtracts given months from this calendar month.
- Parameters:
months
- the count of months to be subtracted- Returns:
- result of subtraction
-
compareTo
- Specified by:
compareTo
in interfaceComparable<CalendarMonth>
-
iterator
Iterates over all days of this calendar month.
-
equals
-
hashCode
public int hashCode() -
toString
Outputs this instance as a String in CLDR-format "uuuu-MM" (like "2016-10").
- Overrides:
toString
in classObject
- Returns:
- String
- See Also:
parseISO(String)
-
parseISO
Interpretes given ISO-conforming text as calendar month.
The underlying parser uses the CLDR-pattern "uuuu-MM|uuuuMM".
- Parameters:
text
- text to be parsed- Returns:
- parsed calendar month
- Throws:
IndexOutOfBoundsException
- if given text is emptyParseException
- if the text is not parseable- See Also:
toString()
-
toTemporalAccessor
Description copied from interface:ThreetenAdapter
Converts this object to a
TemporalAccessor
.Any implementation is required to return a new object with a different concrete type, not this instance.
- Specified by:
toTemporalAccessor
in interfaceThreetenAdapter
- Returns:
- converted Threeten-object (always as new object)
-
chronology
Yields the associated chronology.
- Returns:
- the underlying rule engine
-
threeten
Obtains a bridge chronology for the type
java.time.YearMonth
.- Returns:
- rule engine adapted for the type
java.time.YearMonth
- See Also:
chronology()
-
timeline
Obtains a timeline for this type.
- Returns:
- singleton timeline
- Since:
- 5.0
-