@CalendarType(value="iso8601") public final class PlainDate extends Calendrical<IsoDateUnit,PlainDate> implements GregorianDate, Normalizer<CalendarUnit>, ThreetenAdapter, LocalizedPatternSupport
Represents a plain calendar date in conformance to ISO-8601-standard using the gregorian calendar rules for all times.
The value range also contains negative years down to -999999999.
These years cannot be directly interpreted in a historic way, as in general no past
year, too. Instead such related dates can and must rather be interpreted
as a different way of counting days - like epoch days. The rules of
gregorian calendar are applied in a proleptic way that is backwards into
the past even before the earliest introduction of gregorian calendar in
Rome (a non-historic mathematical abstraction).
However, this class enables full historization via a historic extension mechanism
(i18n-module). When formatting or parsing based on the expert engine of Time4J, it is sufficient to
specify a historic era (pattern symbol G) using the history of calendar reforms in a locale, and Time4J
will automatically apply different rules of calendar history. It is also possible to explicitly model
a suitable history by creating an instance of net.time4j.history.ChronoHistory and to feed the
format engine with this information. Furthermore, this history object yields specialized elements for
querying and manipulating an ISO-8601 calendar date in a historic context.
Following elements which are declared as constants are registered by this class:
COMPONENTDAY_OF_MONTHDAY_OF_QUARTERDAY_OF_WEEKDAY_OF_YEARMONTH_AS_NUMBERMONTH_OF_YEARQUARTER_OF_YEARWEEKDAY_IN_MONTHYEARYEAR_OF_WEEKDATEFurthermore, all elements of classes Weekmodel, EpochDays and
ChronoHistory are supported.
| Modifier and Type | Field and Description |
|---|---|
static CalendarDateElement |
COMPONENT
Element with the calendar date in the value range
[-999999999-01-01] until [+999999999-12-31]. |
static ProportionalElement<Integer,PlainDate> |
DAY_OF_MONTH
Element with the day of month in the value range
1-28/29/30/31. |
static ProportionalElement<Integer,PlainDate> |
DAY_OF_QUARTER
Element with the day within a quarter of year in the value range
1-90/91/92. |
static NavigableElement<Weekday> |
DAY_OF_WEEK
Element with the day of week in the value range
MONDAY-SUNDAY. |
static ProportionalElement<Integer,PlainDate> |
DAY_OF_YEAR
Element with the day of year in the value range
1-365/366). |
static ProportionalElement<Integer,PlainDate> |
MONTH_AS_NUMBER
Element with the calendar month in numerical form and the value range
1-12. |
static NavigableElement<Month> |
MONTH_OF_YEAR
Element with the calendar month as enum in the value range
JANUARY-DECEMBER). |
static NavigableElement<Quarter> |
QUARTER_OF_YEAR
Element with the quarter of year in the value range
Q1-Q4. |
static OrdinalWeekdayElement |
WEEKDAY_IN_MONTH
Element with the ordinal day-of-week within given calendar month
in the value range
1-5. |
static AdjustableElement<Integer,PlainDate> |
YEAR
Element with the proleptic iso-year without any era reference and
the value range
-999999999 until 999999999. |
static AdjustableElement<Integer,PlainDate> |
YEAR_OF_WEEKDATE
Defines an element for the week-based year in an
ISO-8601-weekdate.
|
| Modifier and Type | Method and Description |
|---|---|
PlainTimestamp |
at(PlainTime time)
Creates a new local timestamp with this date and given wall time.
|
Moment |
atFirstMoment(String tzid)
Creates a new moment which corresponds to this date at earliest valid time
at the begin of associated day in given timezone.
|
Moment |
atFirstMoment(TZID tzid)
Creates a new moment which corresponds to this date at earliest valid time
at the begin of associated day in given timezone.
|
PlainTimestamp |
atStartOfDay()
Creates a new local timestamp with this date at midnight at the
begin of associated day.
|
PlainTimestamp |
atStartOfDay(String tzid)
Creates a new local timestamp with this date at earliest valid time
at the begin of associated day in given timezone.
|
PlainTimestamp |
atStartOfDay(TZID tzid)
Creates a new local timestamp with this date at earliest valid time
at the begin of associated day in given timezone.
|
PlainTimestamp |
atTime(int hour,
int minute)
Is equivalent to
at(PlainTime.of(hour, minute)). |
PlainTimestamp |
atTime(int hour,
int minute,
int second)
Is equivalent to
at(PlainTime.of(hour, minute, second)). |
static TimeAxis<IsoDateUnit,PlainDate> |
axis()
Provides a static access to the associated chronology on base of
epoch days which contains the chronological rules.
|
static <S> Chronology<S> |
axis(Converter<S,PlainDate> converter)
Provides a static access to the associated time axis using the foreign type S.
|
static TemporalFormatter<PlainDate> |
formatter(DisplayMode mode,
Locale locale)
Creates a new formatter which uses the given display mode and locale
for formatting and parsing plain dates.
|
static <P extends ChronoPattern<P>> |
formatter(String formatPattern,
P patternType,
Locale locale)
Creates a new formatter which uses the given pattern and locale
for formatting and parsing plain dates.
|
static PlainDate |
from(GregorianDate date)
Common conversion method for proleptic gregorian dates.
|
static PlainDate |
from(LocalDate date)
Short cut for
TemporalType.LOCAL_DATE.translate(date). |
int |
getDayOfMonth()
Yields the day of month.
|
Weekday |
getDayOfWeek()
Determines the day of week.
|
int |
getDayOfYear()
Yields the day of year.
|
int |
getMonth()
Yields the gregorian month as integer.
|
int |
getYear()
Yields the proleptic year according to ISO-8601.
|
boolean |
isLeapYear()
Is the year of this date a leap year?
|
static boolean |
isValid(int year,
int month,
int dayOfMonth)
Queries if given parameter values form a well defined calendar date.
|
boolean |
isWeekend(Locale country)
Does this date fall on a week-end in given country?
|
int |
lengthOfMonth()
Calculates the length of associated month in days.
|
int |
lengthOfYear()
Calculates the length of associated year in days.
|
static TemporalFormatter<PlainDate> |
localFormatter(DisplayMode mode)
Creates a new formatter which uses the given display mode in the
default locale for formatting and parsing plain dates.
|
static <P extends ChronoPattern<P>> |
localFormatter(String formatPattern,
P patternType)
Creates a new formatter which uses the given pattern in the
default locale for formatting and parsing plain dates.
|
PlainDate |
minus(long amount,
CalendarUnit unit)
Subtracts given amount in units from this date and yields the result of subtraction.
|
Duration<CalendarUnit> |
normalize(TimeSpan<? extends CalendarUnit> timespan)
Normalized given timespan using years, months and days.
|
static PlainDate |
nowInSystemTime()
Obtains the current date in system time.
|
static PlainDate |
of(int year,
int dayOfYear)
Creates a new ordinal date conforming to ISO-8601.
|
static PlainDate |
of(int year,
int month,
int dayOfMonth)
Creates a new calendar date conforming to ISO-8601.
|
static PlainDate |
of(int yearOfWeekdate,
int weekOfYear,
Weekday dayOfWeek)
Creates a new week-date conforming to ISO-8601.
|
static PlainDate |
of(int year,
Month month,
int dayOfMonth)
Creates a new calendar date conforming to ISO-8601.
|
static PlainDate |
of(long amount,
EpochDays epoch)
Creates a new date based on count of days since given epoch.
|
PlainDate |
plus(long amount,
CalendarUnit unit)
Adds given amount in units to this date and yields the result of addition.
|
String |
toString()
Creates a canonical representation of the form
"YYYY-MM-DD" as documented in ISO-8601.
|
LocalDate |
toTemporalAccessor()
Converts this object to a
TemporalAccessor. |
compareTo, equals, getDaysSinceEpochUTC, hashCode, isAfter, isBefore, isSimultaneous, minus, plusmax, min, minus, minus, plus, plus, until, untilcontains, get, get, getInt, getMaximum, getMinimum, getRegisteredElements, getTimezone, hasTimezone, isValid, isValid, isValid, matches, with, with, with, withget, getLong, isSupported, query, rangetransform, transform, transform, transform, transform, transformisAfterAll, isBeforeAllpublic static final CalendarDateElement COMPONENT
Element with the calendar date in the value range
[-999999999-01-01] until [+999999999-12-31].
Example of usage:
PlainTimestamp tsp = PlainTimestamp.of(2014, 8, 21, 14, 30); tsp = tsp.with(PlainDate.COMPONENT, PlainDate.of(2015, 1, 1)); System.out.println(tsp); // output: 2015-01-01T14:30
@FormattableElement(format="u") public static final AdjustableElement<Integer,PlainDate> YEAR
Element with the proleptic iso-year without any era reference and
the value range -999999999 until 999999999.
Examples:
import static net.time4j.PlainDate.YEAR; PlainDate date = PlainDate.of(2012, 2, 29); System.out.println(date.get(YEAR)); // output: 2012 date = date.with(YEAR, 2014); System.out.println(date); // output: 2014-02-28 date = date.with(YEAR.incremented()); // nächstes Jahr System.out.println(date); // output: 2015-02-28 date = date.with(YEAR.atCeiling()); // letzter Tag des Jahres System.out.println(date); // output: 2015-12-31 date = date.with(YEAR.atFloor()); // erster Tag des Jahres System.out.println(date); // output: 2015-01-01
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.
@FormattableElement(format="Y") public static final AdjustableElement<Integer,PlainDate> 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:
Note: This element has a special basic unit which can be used such that the day of the week will be conserved instead of the day of month after adding one week-based year:
PlainDate date = PlainDate.of(2014, JANUARY, 2); // Thursday IsoDateUnit unit = CalendarUnit.weekBasedYears(); System.out.println(date.plus(1, unit)); // output: 2015-01-01
CalendarUnit.weekBasedYears(),
Weekmodel.ISO@FormattableElement(format="Q", standalone="q") public static final NavigableElement<Quarter> QUARTER_OF_YEAR
Element with the quarter of year in the value range
Q1-Q4.
@FormattableElement(format="M", standalone="L") public static final NavigableElement<Month> MONTH_OF_YEAR
Element with the calendar month as enum in the value range
JANUARY-DECEMBER).
Examples:
import static net.time4j.PlainDate.MONTH_OF_YEAR; import static net.time4j.Month.*; PlainDate date = PlainDate.of(2012, 2, 29); System.out.println(date.get(MONTH_OF_YEAR)); // output: February date = date.with(MONTH_OF_YEAR, APRIL); System.out.println(date); // output: 2012-04-29 date = date.with(MONTH_OF_YEAR.incremented()); // next month System.out.println(date); // output: 2012-05-29 date = date.with(MONTH_OF_YEAR.maximized()); // last month of year System.out.println(date); // output: 2012-12-29 date = date.with(MONTH_OF_YEAR.atCeiling()); // last day of month System.out.println(date); // output: 2012-12-31 date = date.with(MONTH_OF_YEAR.atFloor()); // first day of month System.out.println(date); // output: 2012-12-01 date = date.with(MONTH_OF_YEAR.setToNext(JULY)); // move to July System.out.println(date); // output: 2013-07-01
@FormattableElement(format="M") public static final ProportionalElement<Integer,PlainDate> MONTH_AS_NUMBER
Element with the calendar month in numerical form and the value range
1-12.
Normally the enum-variant is recommended due to clarity and type-safety. The enum-form can also be formatted as text. However, if users want to set any month number in a lenient way with possible carry-over then they can do it like in following example:
import static net.time4j.PlainDate.MONTH_AS_NUMBER; PlainDate date = PlainDate.of(2012, 2, 29); date = date.with(MONTH_AS_NUMBER.setLenient(13); System.out.println(date); // output: 2013-01-29
MONTH_OF_YEAR@FormattableElement(format="d") public static final ProportionalElement<Integer,PlainDate> DAY_OF_MONTH
Element with the day of month in the value range
1-28/29/30/31.
@FormattableElement(format="E") public static final NavigableElement<Weekday> DAY_OF_WEEK
Element with the day of week in the value range MONDAY-SUNDAY.
A localized form is available by Weekmodel.localDayOfWeek().
In US sunday is considered as first day of week, different from
definition used here (monday as start of calendar week according to
ISO-8601). Therefore, if users need localized weekday-numbers, users
can use the expression Weekmodel.of(Locale.US).localDayOfWeek()
in a country like US.
@FormattableElement(format="D") public static final ProportionalElement<Integer,PlainDate> DAY_OF_YEAR
Element with the day of year in the value range 1-365/366).
public static final ProportionalElement<Integer,PlainDate> DAY_OF_QUARTER
Element with the day within a quarter of year in the value range
1-90/91/92.
@FormattableElement(format="F") public static final OrdinalWeekdayElement WEEKDAY_IN_MONTH
Element with the ordinal day-of-week within given calendar month
in the value range 1-5.
Example:
import static net.time4j.PlainDate.WEEKDAY_IN_MONTH; import static net.time4j.Weekday.*; PlainDate date = PlainDate.of(2013, 3, 1); // first of march 2013 System.out.println(date.with(WEEKDAY_IN_MONTH.setToThird(WEDNESDAY))); // output: 2013-03-20 (third Wednesday in march)
public static PlainDate of(int year, int month, int dayOfMonth)
Creates a new calendar date conforming to ISO-8601.
year - proleptic iso year [(-999,999,999)-999,999,999]month - gregorian month in range (1-12)dayOfMonth - day of month in range (1-31)IllegalArgumentException - if any argument is out of rangeof(int, Month, int),
of(int, int),
of(int, int, Weekday)public static PlainDate of(int year, Month month, int dayOfMonth)
Creates a new calendar date conforming to ISO-8601.
year - proleptic iso year [(-999,999,999)-999,999,999]month - gregorian month in range (January-December)dayOfMonth - day of month in range (1-31)IllegalArgumentException - if any argument is out of rangeof(int, int, int)public static PlainDate of(int year, int dayOfYear)
Creates a new ordinal date conforming to ISO-8601.
year - proleptic iso year [(-999,999,999)-999,999,999]dayOfYear - day of year in the range (1-366)IllegalArgumentException - if any argument is out of rangepublic static PlainDate of(int yearOfWeekdate, int weekOfYear, Weekday dayOfWeek)
Creates a new week-date conforming to ISO-8601.
yearOfWeekdate - week-based-year according to ISO-definitionweekOfYear - week of year in the range (1-52/53)dayOfWeek - day of week in the range (MONDAY-SUNDAY)IllegalArgumentException - if any argument is out of rangepublic static PlainDate of(long amount, EpochDays epoch)
Creates a new date based on count of days since given epoch.
amount - count of daysepoch - reference date scaleIllegalArgumentException - if first argument is out of rangepublic static PlainDate nowInSystemTime()
Obtains the current date in system time.
Convenient short-cut for: SystemClock.inLocalView().today().
SystemClock.inLocalView(),
ZonalClock.today()public static PlainDate from(GregorianDate date)
Common conversion method for proleptic gregorian dates.
date - ISO-datepublic static PlainDate from(LocalDate date)
Short cut for TemporalType.LOCAL_DATE.translate(date).
date - Threeten-equivalent of this instanceTemporalType.LOCAL_DATEpublic PlainTimestamp atStartOfDay()
Creates a new local timestamp with this date at midnight at the begin of associated day.
at(PlainTime)public PlainTimestamp atStartOfDay(TZID tzid)
Creates a new local timestamp with this date at earliest valid time at the begin of associated day in given timezone.
tzid - timezone idIllegalArgumentException - if given timezone cannot be loadedUnsupportedOperationException - if the underlying timezone
repository does not expose any public transition historyatStartOfDay(),
atFirstMoment(TZID)public PlainTimestamp atStartOfDay(String tzid)
Creates a new local timestamp with this date at earliest valid time at the begin of associated day in given timezone.
tzid - timezone idIllegalArgumentException - if given timezone cannot be loadedUnsupportedOperationException - if the underlying timezone
repository does not expose any public transition historyatStartOfDay(),
atFirstMoment(String)public Moment atFirstMoment(TZID tzid)
Creates a new moment which corresponds to this date at earliest valid time at the begin of associated day in given timezone.
tzid - timezone idIllegalArgumentException - if given timezone cannot be loadedUnsupportedOperationException - if the underlying timezone
repository does not expose any public transition historyatStartOfDay(TZID)public Moment atFirstMoment(String tzid)
Creates a new moment which corresponds to this date at earliest valid time at the begin of associated day in given timezone.
tzid - timezone idIllegalArgumentException - if given timezone cannot be loadedUnsupportedOperationException - if the underlying timezone
repository does not expose any public transition historyatStartOfDay(String)public PlainTimestamp at(PlainTime time)
Creates a new local timestamp with this date and given wall time.
If the time T24:00 is used
then the resulting timestamp will automatically be normalized such
that the timestamp will contain the following day instead.
time - wall timepublic PlainTimestamp atTime(int hour, int minute)
Is equivalent to at(PlainTime.of(hour, minute)).
hour - hour of day in range (0-24)minute - minute of hour in range (0-59)IllegalArgumentException - if any argument is out of rangepublic PlainTimestamp atTime(int hour, int minute, int second)
Is equivalent to at(PlainTime.of(hour, minute, second)).
hour - hour of day in range (0-24)minute - minute of hour in range (0-59)second - second of hour in range (0-59)IllegalArgumentException - if any argument is out of rangepublic int getYear()
GregorianDateYields the proleptic year according to ISO-8601.
The term proleptic means that the gregorian calendar rules are applied backwards even before the introduction of this calendar. Second: The year numbering is just the mathematical one as defined in ISO-8601 such that there is a year zero and even negative years: -2 = BC 3, -1 = BC 2, 0 = BC 1, 1 = AD 1, 2 = AD 2, ...
getYear in interface GregorianDateGregorianMath.MIN_YEAR - GregorianMath.MAX_YEARpublic int getMonth()
GregorianDateYields the gregorian month as integer.
getMonth in interface GregorianDatepublic int getDayOfMonth()
GregorianDateYields the day of month.
getDayOfMonth in interface GregorianDate1 <= dayOfMonth <= 31public Weekday getDayOfWeek()
Determines the day of week.
public int getDayOfYear()
Yields the day of year.
public int lengthOfMonth()
Calculates the length of associated month in days.
28-31public int lengthOfYear()
Calculates the length of associated year in days.
365 or 366 if associated year is a leap yearpublic boolean isLeapYear()
Is the year of this date a leap year?
public boolean isWeekend(Locale country)
Does this date fall on a week-end in given country?
country - country setting with two-letter ISO-3166-codetrue if in given country this date is on weekend
else falseWeekmodel.weekend()public static boolean isValid(int year,
int month,
int dayOfMonth)
Queries if given parameter values form a well defined calendar date.
This method only checks the range limits, not if the date is historically correct.
year - the proleptic year to be checkedmonth - the month to be checkeddayOfMonth - the day of month to be checkedtrue if valid else falseof(int, int, int)public PlainDate plus(long amount, CalendarUnit unit)
Adds given amount in units to this date and yields the result of addition.
Covers the most important units and is overloaded for performance reasons.
amount - the amount of units to be added to this date (maybe negative)unit - the unit to be used in additionArithmeticException - in case of numerical overflowplus(long, IsoDateUnit)public PlainDate minus(long amount, CalendarUnit unit)
Subtracts given amount in units from this date and yields the result of subtraction.
Covers the most important units and is overloaded for performance reasons.
amount - the amount of units to be subtracted from this date (maybe negative)unit - the unit to be used in subtractionArithmeticException - in case of numerical overflowminus(long, IsoDateUnit)public static <P extends ChronoPattern<P>> TemporalFormatter<PlainDate> localFormatter(String formatPattern, P patternType)
Creates a new formatter which uses the given pattern in the default locale for formatting and parsing plain dates.
P - generic pattern typeformatPattern - format definition as patternpatternType - pattern dialectPlainDate-objects
using system localeIllegalArgumentException - if resolving of pattern failspublic static TemporalFormatter<PlainDate> localFormatter(DisplayMode mode)
Creates a new formatter which uses the given display mode in the default locale for formatting and parsing plain dates.
mode - formatting stylePlainDate-objects
using system localeIllegalStateException - if format pattern cannot be retrievedpublic static <P extends ChronoPattern<P>> TemporalFormatter<PlainDate> formatter(String formatPattern, P patternType, Locale locale)
Creates a new formatter which uses the given pattern and locale for formatting and parsing plain dates.
P - generic pattern typeformatPattern - format definition as patternpatternType - pattern dialectlocale - locale settingPlainDate-objects
using given localeIllegalArgumentException - if resolving of pattern failslocalFormatter(String,ChronoPattern)public static TemporalFormatter<PlainDate> formatter(DisplayMode mode, Locale locale)
Creates a new formatter which uses the given display mode and locale for formatting and parsing plain dates.
mode - formatting stylelocale - locale settingPlainDate-objects
using given localeIllegalStateException - if format pattern cannot be retrievedlocalFormatter(DisplayMode)public String toString()
Creates a canonical representation of the form "YYYY-MM-DD" as documented in ISO-8601.
toString in interface GregorianDatetoString in class TimePoint<IsoDateUnit,PlainDate>public Duration<CalendarUnit> normalize(TimeSpan<? extends CalendarUnit> timespan)
Normalized given timespan using years, months and days.
This normalizer can also convert from days to months. Example:
Duration<CalendarUnit> dur = Duration.of(30, CalendarUnit.DAYS);
Duration<CalendarUnit> result =
PlainDate.of(2012, 2, 28).normalize(dur);
System.out.println(result); // output: P1M1D (leap year!)
normalize in interface Normalizer<CalendarUnit>timespan - to be normalizedDuration.with(Normalizer)public LocalDate toTemporalAccessor()
ThreetenAdapterConverts this object to a TemporalAccessor.
Any implementation is required to return a new object with a different concrete type, not this instance.
toTemporalAccessor in interface ThreetenAdapterpublic static TimeAxis<IsoDateUnit,PlainDate> axis()
Provides a static access to the associated chronology on base of epoch days which contains the chronological rules.
null)public static <S> Chronology<S> axis(Converter<S,PlainDate> converter)
Provides a static access to the associated time axis using the foreign type S.
S - foreign temporal typeconverter - type converterTemporalType.LOCAL_DATECopyright © 2014–2017. All rights reserved.