@CalendarType(value="iso8601") public final class CalendarWeek extends FixedCalendarInterval<CalendarWeek>
Represents the calendar week starting on Monday according to ISO-8601-paper.
The elements registered by this class are:
This class does not offer localized formatting. However, a combination of numerical formatting and fixed literals is possible using the root locale. Example for using the German abbreviation KW for a calendar week:
ChronoFormatter<CalendarWeek> f =
ChronoFormatter.setUp(CalendarWeek.chronology(), Locale.ROOT)
.addPattern("w. 'KW'", PatternType.CLDR).build();
System.out.println(f.format(CalendarWeek.of(2016, 4)); // 4. KW
Note: The current calendar week can be determined by an expression like:
nowInSystemTime() or in a more general way
CalendarWeek current = SystemClock.inLocalView().now(CalendarWeek.chronology()).
| Modifier and Type | Field and Description |
|---|---|
static ChronoElement<Integer> |
WEEK_OF_YEAR
Element with the week of year in the value range
1-52/53. |
static ChronoElement<Integer> |
YEAR_OF_WEEKDATE
Defines an element for the week-based year in an
ISO-8601-weekdate.
|
| Modifier and Type | Method and Description |
|---|---|
PlainDate |
at(Weekday dayOfWeek)
Combines this calendar week with given day of week to a calendar date.
|
static Chronology<CalendarWeek> |
chronology()
Yields the associated chronology.
|
int |
compareTo(CalendarWeek other) |
boolean |
contains(PlainDate temporal)
Queries if given time point belongs to this interval.
|
boolean |
equals(Object obj) |
static CalendarWeek |
from(GregorianDate date)
Converts given gregorian date to a calendar week.
|
Boundary<PlainDate> |
getEnd()
Yields the upper bound of this interval.
|
Boundary<PlainDate> |
getStart()
Yields the lower bound of this interval.
|
int |
getWeek()
Yields the number of calendar week.
|
int |
getYear()
Yields the year number.
|
int |
hashCode() |
boolean |
isAfter(PlainDate temporal)
Is this interval after the given time point?
|
boolean |
isBefore(PlainDate temporal)
Is this interval before the given time point?
|
static boolean |
isValid(int yearOfWeekdate,
int weekOfYear)
Validates given year-of-weekdate and week-of-year.
|
Iterator<PlainDate> |
iterator()
Iterates over all seven days from Monday to Sunday.
|
int |
length()
Calendar week always consist of seven days.
|
CalendarWeek |
minus(Weeks weeks)
Subtracts given weeks from this calendar week.
|
CalendarWeek |
minus(Years<Weekcycle> years)
Subtracts given years from this calendar week.
|
static CalendarWeek |
nowInSystemTime()
Obtains the current calendar week in system time.
|
static CalendarWeek |
of(int yearOfWeekdate,
int weekOfYear)
Creates a new instance based on given week-based year and week-of-year
according to ISO-8601.
|
static CalendarWeek |
parseISO(String text)
Interpretes given ISO-conforming text as calendar week.
|
CalendarWeek |
plus(Weeks weeks)
Adds given weeks to this calendar week.
|
CalendarWeek |
plus(Years<Weekcycle> years)
Adds given years to this calendar week.
|
String |
toString()
Outputs this instance as a String in CLDR-format "YYYY-'W'ww" (like "2016-W01").
|
CalendarWeek |
withLastWeekOfYear()
Yields the last calendar week of the year of this instance.
|
abuts, contains, isBefore, isEmpty, isFinite, isSimultaneous, streamDaily, toFlexInterval, withValuecontains, get, get, getInt, getMaximum, getMinimum, getRegisteredElements, getTimezone, hasTimezone, isValid, isValid, isValid, matches, with, with, with, withintersects, isAfterforEach, spliterator@FormattableElement(format="Y") public static final ChronoElement<Integer> YEAR_OF_WEEKDATE
Defines an element for the week-based year in an ISO-8601-weekdate.
The week-based year is usually the same as the calendar year. However, at the begin or end of a calendar year the situation is different because the first week of the weekdate can start after New Year and the last week of the weekdate can end before the last day of the calendar year. Examples:
@FormattableElement(format="w") public static final ChronoElement<Integer> WEEK_OF_YEAR
Element with the week of year in the value range 1-52/53.
The calendar week always starts on Monday. The first week which has at least four days within current calendar year is considered as the first week of year.
Weekmodel.ISO,
Weekmodel.weekOfYear()public static CalendarWeek of(int yearOfWeekdate, int weekOfYear)
Creates a new instance based on given week-based year and week-of-year according to ISO-8601.
In order to create the last calendar week of given year, it is recommended to use following expression:
CalendarWeek first = CalendarWeek.of(2016, 1);
CalendarWeek last = first.withLastWeekOfYear();
yearOfWeekdate - week-based year within range -999,999,999 / +999,999,999weekOfYear - week of year based on ISO-8601 in range 1-52/53IllegalArgumentException - if any argument is out of rangeisValid(int, int),
withLastWeekOfYear()public static CalendarWeek nowInSystemTime()
Obtains the current calendar week in system time.
Convenient short-cut for: SystemClock.inLocalView().now(CalendarWeek.chronology()).
SystemClock.inLocalView(),
ZonalClock.now(net.time4j.engine.Chronology)public PlainDate at(Weekday dayOfWeek)
Combines this calendar week with given day of week to a calendar date.
dayOfWeek - day of week in range MONDAY - SUNDAYpublic int getYear()
Yields the year number.
YEAR_OF_WEEKDATEpublic int getWeek()
Yields the number of calendar week.
Note: The last week of year can be obtained by the expression getMaximum(WEEK_OF_YEAR).
WEEK_OF_YEAR,
ChronoEntity.getMaximum(ChronoElement),
withLastWeekOfYear()public Boundary<PlainDate> getStart()
ChronoIntervalYields the lower bound of this interval.
public Boundary<PlainDate> getEnd()
ChronoIntervalYields the upper bound of this interval.
public boolean contains(PlainDate temporal)
ChronoIntervalQueries if given time point belongs to this interval.
temporal - time point to be queriedtrue if given time point belongs to this interval else falsepublic boolean isAfter(PlainDate temporal)
ChronoIntervalIs this interval after the given time point?
temporal - reference time pointtrue if this interval is after given time point else falsepublic boolean isBefore(PlainDate temporal)
ChronoIntervalIs this interval before the given time point?
temporal - reference time pointtrue if this interval is before given time point else falsepublic static boolean isValid(int yearOfWeekdate,
int weekOfYear)
Validates given year-of-weekdate and week-of-year.
yearOfWeekdate - the year of weekdate (can be different from calendar year near New Year)weekOfYear - the week of weekbased yeartrue if valid else falseof(int, int)public int length()
Calendar week always consist of seven days.
7public static CalendarWeek from(GregorianDate date)
Converts given gregorian date to a calendar week.
date - gregorian calendar date (for example PlainDateIllegalArgumentException - if given date is invalidpublic CalendarWeek withLastWeekOfYear()
Yields the last calendar week of the year of this instance.
52 or 53public CalendarWeek plus(Years<Weekcycle> years)
Adds given years to this calendar week.
years - the count of week-based years to be addedpublic CalendarWeek plus(Weeks weeks)
Adds given weeks to this calendar week.
weeks - the count of weeks to be addedpublic CalendarWeek minus(Years<Weekcycle> years)
Subtracts given years from this calendar week.
years - the count of week-based years to be subtractedpublic CalendarWeek minus(Weeks weeks)
Subtracts given weeks from this calendar week.
weeks - the count of weeks to be subtractedpublic int compareTo(CalendarWeek other)
public Iterator<PlainDate> iterator()
Iterates over all seven days from Monday to Sunday.
public String toString()
Outputs this instance as a String in CLDR-format "YYYY-'W'ww" (like "2016-W01").
toString in class ObjectparseISO(String)public static CalendarWeek parseISO(String text) throws ParseException
Interpretes given ISO-conforming text as calendar week.
The underlying parser uses the CLDR-pattern "YYYY[-]'W'ww".
text - text to be parsedIndexOutOfBoundsException - if given text is emptyParseException - if the text is not parseabletoString()public static Chronology<CalendarWeek> chronology()
Yields the associated chronology.
Copyright © 2014–2018. All rights reserved.