Package com.ethlo.time
Class DateTime
- java.lang.Object
-
- com.ethlo.time.DateTime
-
- All Implemented Interfaces:
java.time.temporal.TemporalAccessor
public class DateTime extends java.lang.Object implements java.time.temporal.TemporalAccessorContainer class for parsed date/date-time data. ThegetMostGranularField()contains the highest granularity field found, like MONTH, MINUTE, SECOND.
-
-
Field Summary
Fields Modifier and Type Field Description private intcharLengthprivate intdayprivate Fieldfieldprivate intfractionDigitsprivate inthourprivate static LeapSecondHandlerleapSecondHandlerprivate intminuteprivate intmonthprivate intnanoprivate TimezoneOffsetoffsetprivate intsecondprivate intyear
-
Constructor Summary
Constructors Constructor Description DateTime(Field field, int year, int month, int day, int hour, int minute, int second, int nano, TimezoneOffset offset, int fractionDigits)DateTime(Field field, int year, int month, int day, int hour, int minute, int second, int nano, TimezoneOffset offset, int fractionDigits, int charLength)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidassertMinGranularity(Field field)booleanequals(java.lang.Object o)intgetDayOfMonth()intgetFractionDigits()Return the number of significant fraction digits in the second.intgetHour()longgetLong(java.time.temporal.TemporalField temporalField)intgetMinute()intgetMonth()FieldgetMostGranularField()Returns the most granular field found during parsingintgetNano()java.util.Optional<TimezoneOffset>getOffset()Returns the time offset, if availableintgetParseLength()intgetSecond()intgetYear()inthashCode()booleanincludesGranularity(Field field)Returns if the specified field is part of this date/date-timebooleanisSupported(java.time.temporal.TemporalField field)private static voidleapSecondCheck(int year, int month, int day, int hour, int minute, int second, int nanos, TimezoneOffset offset)static DateTimeof(int year, int month, int day, int hour, int minute, int second, int nanos, TimezoneOffset offset, int fractionDigits)Create a new instance with nanosecond granularity from the input parametersstatic DateTimeof(int year, int month, int day, int hour, int minute, int second, TimezoneOffset offset)Create a new instance with second granularity from the input parametersstatic DateTimeof(int year, int month, int day, int hour, int minute, TimezoneOffset offset)Create a new instance with minute granularity from the input parametersstatic DateTimeof(java.time.OffsetDateTime dateTime)Create a new instance with data from the specified date-time.static DateTimeofDate(int year, int month, int day)Create a new instance with day granularity from the input parametersstatic DateTimeofYear(int year)Create a new instance with year granularity from the input parametersstatic DateTimeofYearMonth(int year, int month)Create a new instance with year-month granularity from the input parametersprivate longtoEpochSeconds()java.time.InstanttoInstant()This method will attempt to create an Instant from whatever granularity is available in the parsed year/date/date-time.java.time.LocalDatetoLocalDate()Creates aLocalDate, discarding any higher granularity fieldsjava.time.LocalDateTimetoLocalDatetime()Creates aLocalDateTimediscarding any timezone informationjava.time.LocalTimetoLocalTime()java.time.OffsetDateTimetoOffsetDatetime()Creates anOffsetDateTimejava.lang.StringtoString()Formats this date-time as a date/date-time with the same fields as was parsedjava.lang.StringtoString(int fractionDigits)Formats this date-time as an RFC-3339 compatible string with the specified number of fractions in the second.private java.lang.StringtoString(DateTime date, Field lastIncluded, int fractionDigits)java.lang.StringtoString(Field lastIncluded)Formats this date-time as an ISO formatted string with the last included field as specified.java.time.YeartoYear()Creates aYeardiscarding any higher granularity fieldsjava.time.YearMonthtoYearMonth()Creates aYearMonthdiscarding any higher granularity fieldsprivate voidvalidated()
-
-
-
Field Detail
-
leapSecondHandler
private static final LeapSecondHandler leapSecondHandler
-
field
private final Field field
-
year
private final int year
-
month
private final int month
-
day
private final int day
-
hour
private final int hour
-
minute
private final int minute
-
second
private final int second
-
nano
private final int nano
-
offset
private final TimezoneOffset offset
-
fractionDigits
private final int fractionDigits
-
charLength
private final int charLength
-
-
Constructor Detail
-
DateTime
public DateTime(Field field, int year, int month, int day, int hour, int minute, int second, int nano, TimezoneOffset offset, int fractionDigits)
-
DateTime
public DateTime(Field field, int year, int month, int day, int hour, int minute, int second, int nano, TimezoneOffset offset, int fractionDigits, int charLength)
-
-
Method Detail
-
of
public static DateTime of(int year, int month, int day, int hour, int minute, int second, TimezoneOffset offset)
Create a new instance with second granularity from the input parameters- Parameters:
year- yearmonth- monthday- dayhour- hourminute- minutesecond- secondoffset- timezone offset- Returns:
- A DateTime with second granularity
-
of
public static DateTime of(int year, int month, int day, int hour, int minute, int second, int nanos, TimezoneOffset offset, int fractionDigits)
Create a new instance with nanosecond granularity from the input parameters- Parameters:
year- yearmonth- monthday- dayhour- hourminute- minutesecond- secondnanos- nanosoffset- timezone offsetfractionDigits- The granularity of the fractional seconds field- Returns:
- A DateTime with nanosecond granularity
-
ofYear
public static DateTime ofYear(int year)
Create a new instance with year granularity from the input parameters- Parameters:
year- The year- Returns:
- a new instance with year granularity from the input parameters
-
ofYearMonth
public static DateTime ofYearMonth(int year, int month)
Create a new instance with year-month granularity from the input parameters- Parameters:
year- The yearmonth- The month- Returns:
- a new instance with year-month granularity from the input parameters
-
ofDate
public static DateTime ofDate(int year, int month, int day)
Create a new instance with day granularity from the input parameters- Parameters:
year- The yearmonth- The monthday- The day- Returns:
- a new instance with day granularity from the input parameters
-
of
public static DateTime of(int year, int month, int day, int hour, int minute, TimezoneOffset offset)
Create a new instance with minute granularity from the input parameters- Parameters:
year- The yearmonth- The monthday- The dayhour- The hourminute- The minuteoffset- The timezone offset- Returns:
- a new instance with minute granularity from the input parameters
-
of
public static DateTime of(java.time.OffsetDateTime dateTime)
Create a new instance with data from the specified date-time.- Parameters:
dateTime- The date-time to copy data from- Returns:
- A new instance
-
leapSecondCheck
private static void leapSecondCheck(int year, int month, int day, int hour, int minute, int second, int nanos, TimezoneOffset offset)
-
includesGranularity
public boolean includesGranularity(Field field)
Returns if the specified field is part of this date/date-time- Parameters:
field- The field to check for- Returns:
- True if included, otherwise false
-
getYear
public int getYear()
-
getMonth
public int getMonth()
-
getDayOfMonth
public int getDayOfMonth()
-
getHour
public int getHour()
-
getMinute
public int getMinute()
-
getSecond
public int getSecond()
-
getNano
public int getNano()
-
getOffset
public java.util.Optional<TimezoneOffset> getOffset()
Returns the time offset, if available- Returns:
- the time offset, if available
-
toYear
public java.time.Year toYear()
Creates aYeardiscarding any higher granularity fields- Returns:
- the
Year
-
toYearMonth
public java.time.YearMonth toYearMonth()
Creates aYearMonthdiscarding any higher granularity fields- Returns:
- the
YearMonth
-
toLocalDatetime
public java.time.LocalDateTime toLocalDatetime()
Creates aLocalDateTimediscarding any timezone information- Returns:
- the
LocalDateTime
-
toOffsetDatetime
public java.time.OffsetDateTime toOffsetDatetime()
Creates anOffsetDateTime- Returns:
- the
OffsetDateTime
-
toLocalDate
public java.time.LocalDate toLocalDate()
Creates aLocalDate, discarding any higher granularity fields- Returns:
- the
LocalDate
-
getMostGranularField
public Field getMostGranularField()
Returns the most granular field found during parsing- Returns:
- The field found
-
assertMinGranularity
private void assertMinGranularity(Field field)
-
toString
public java.lang.String toString(Field lastIncluded)
Formats this date-time as an ISO formatted string with the last included field as specified.- Parameters:
lastIncluded- The last specified field to include- Returns:
- The formatted date/date-time string
-
toString
public java.lang.String toString(int fractionDigits)
Formats this date-time as an RFC-3339 compatible string with the specified number of fractions in the second.- Parameters:
fractionDigits- The number of fractions to include- Returns:
- The formatted date/date-time string
-
getFractionDigits
public int getFractionDigits()
Return the number of significant fraction digits in the second.- Returns:
- The number of significant fraction digits
-
toString
public java.lang.String toString()
Formats this date-time as a date/date-time with the same fields as was parsed- Overrides:
toStringin classjava.lang.Object- Returns:
- The formatted date/date-time string
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
isSupported
public boolean isSupported(java.time.temporal.TemporalField field)
- Specified by:
isSupportedin interfacejava.time.temporal.TemporalAccessor
-
getLong
public long getLong(java.time.temporal.TemporalField temporalField)
- Specified by:
getLongin interfacejava.time.temporal.TemporalAccessor
-
toInstant
public java.time.Instant toInstant()
This method will attempt to create an Instant from whatever granularity is available in the parsed year/date/date-time.
Missing fields will be replaced by their lowest allowed value: 1 for month and day, 0 for any missing time component.
NOTE: If there is no time-zone defined, UTC will be assumed
- Returns:
- An instant representing the point in time.
-
toEpochSeconds
private long toEpochSeconds()
-
validated
private void validated()
-
getParseLength
public int getParseLength()
-
toLocalTime
public java.time.LocalTime toLocalTime()
-
-