@Override public final int get( TemporalField field ) { int accessor; try { accessor = temporal().get( field ); } catch ( UnsupportedTemporalTypeException e ) { throw new UnsupportedTemporalUnitException( e.getMessage(), e ); } return accessor; }
int fromNanos = from.isSupported( NANO_OF_SECOND ) ? from.get( NANO_OF_SECOND ) : 0; int toNanos = to.isSupported( NANO_OF_SECOND ) ? to.get( NANO_OF_SECOND ) : 0; nanos = toNanos - fromNanos; && from.isSupported( SECOND_OF_MINUTE ) && to.isSupported( SECOND_OF_MINUTE ) && from.get( SECOND_OF_MINUTE ) != to.get( SECOND_OF_MINUTE );
@SuppressWarnings( "unchecked" ) @Override public <R extends Temporal> R adjustInto( R temporal, long newValue ) { int newVal = range.checkValidIntValue( newValue, this ); int oldYear = temporal.get( ChronoField.YEAR ); return (R) temporal.with( ChronoField.YEAR, (oldYear / years) * years + newVal ) .with( TemporalAdjusters.firstDayOfYear() ); }
/** * A utility method that adjusts <a href="https://dev.mysql.com/doc/refman/5.7/en/two-digit-years.html">ambiguous</a> 2-digit * year values of DATETIME, DATE, and TIMESTAMP types using these MySQL-specific rules: * <ul> * <li>Year values in the range 00-69 are converted to 2000-2069.</li> * <li>Year values in the range 70-99 are converted to 1970-1999.</li> * </ul> * * @param temporal the temporal instance to adjust; may not be null * @return the possibly adjusted temporal instance; never null */ protected static Temporal adjustTemporal(Temporal temporal) { if (temporal.isSupported(ChronoField.YEAR)) { int year = temporal.get(ChronoField.YEAR); if (0 <= year && year <= 69) { temporal = temporal.plus(2000, ChronoUnit.YEARS); } else if (70 <= year && year <= 99) { temporal = temporal.plus(1900, ChronoUnit.YEARS); } } return temporal; }
AnyValue millis = Values.intValue( temporal.get( ChronoField.MILLI_OF_SECOND ) ); AnyValue micros = fields.get( "microsecond" ); AnyValue nanos = fields.get( "nanosecond" ); AnyValue micros = Values.intValue( temporal.get( ChronoField.MICRO_OF_SECOND ) ); AnyValue nanos = fields.get( "nanosecond" ); int newNanos = validNano( null, micros, nanos );
/** * A check that we do not go ballistic with the year */ private static boolean checkMaxYear(Temporal temporal) { return temporal.get(ChronoField.YEAR) >= 2200; }
/** * This is the # syntax. We must check that the given weekday is the nth one * in the current month. So we take the day of the month and divide it by 7. * * @param temporal temporal to check * @param nDayInMonth the nth day in the current month to check * @return true if temporal matches nth day in month */ private static boolean isNthWeekDayInMonth(Temporal temporal, int nDayInMonth) { final int day = temporal.get(ChronoField.DAY_OF_MONTH); final int occurrences = 1 + (day - 1) / 7; return nDayInMonth == occurrences; }
/** * Check for the nearest working day. E.g. 15W is the nearest working day around the 15th. * * @param temporal temporal to check * @return true if temporal is nearest to working day */ static boolean isNearestWorkDay(Temporal temporal, int target) { final int day = temporal.get(ChronoField.DAY_OF_MONTH); final DayOfWeek type = DayOfWeek.of(temporal.get(ChronoField.DAY_OF_WEEK)); switch (type) { case MONDAY: return day == target // the actual day || day == target + 1 // target was on a Sunday || (day == target + 2 && day == 3); // target was Saturday 1 case TUESDAY: case WEDNESDAY: case THURSDAY: return day == target; case FRIDAY: return day == target || day + 1 == target; // not a work day default: case SATURDAY: case SUNDAY: return false; } }
/** * @param temporal temporal to check * @return true if temporal is the last week day in this month. I.e. the last Saturday */ private static boolean isLastOfThisWeekDayInMonth(Temporal temporal) { final int day = temporal.get(ChronoField.DAY_OF_MONTH); final int max = (int) ChronoField.DAY_OF_MONTH.rangeRefinedBy(temporal).getMaximum(); return day + 7 > max; }
/** * @param temporal temporal to check * @return true if temporal is the last day in the month */ private static boolean isLastDayInMonth(Temporal temporal) { final int day = temporal.get(ChronoField.DAY_OF_MONTH); final int max = (int) ChronoField.DAY_OF_MONTH.rangeRefinedBy(temporal).getMaximum(); return day == max; }
/** * @param temporal temporal to check * @return true if temporal is the last working day in the month */ private static boolean isLastWorkingDayInMonth(Temporal temporal) { final int day = temporal.get(ChronoField.DAY_OF_MONTH); final DayOfWeek type = DayOfWeek.of(temporal.get(ChronoField.DAY_OF_WEEK)); final int max = (int) ChronoField.DAY_OF_MONTH.rangeRefinedBy(temporal).getMaximum(); switch (type) { case MONDAY: case TUESDAY: case WEDNESDAY: case THURSDAY: return day == max; case FRIDAY: return day + 2 >= max; default: case SATURDAY: case SUNDAY: return false; } }
@Override public void format(StringBuilder sb, Temporal cal) { int month = cal.get(ChronoField.MONTH_OF_YEAR); sb.append((month) / 10); sb.append((month) % 10); } }
@Override public void format(StringBuilder sb, Temporal cal) { int minute = cal.get(ChronoField.MINUTE_OF_HOUR); sb.append((minute / 10) % 6); sb.append((minute) % 10); } }
@Override public void format(StringBuilder sb, Temporal cal) { int second = cal.get(ChronoField.SECOND_OF_MINUTE); sb.append((second / 10) % 6); sb.append((second) % 10); } }
@Override public String format(Temporal temporal) { if (temporal.get(ChronoField.ERA) != IsoEra.CE.getValue()) { return FMT_ERA.format(temporal); } return FMT.format(temporal); }
public static int minute(Object t) { if(t instanceof Date) { return Dates.toCalendar((Date)t).get(Calendar.MINUTE); } if(t instanceof Instant) { return DateTimes.toLocalDateTime((Instant)t).getMinute(); } if(t instanceof Temporal) { return ((Temporal) t).get(ChronoField.MINUTE_OF_HOUR); } throw new IllegalStateException(t + " is not a valid or supported time"); }
@SuppressWarnings( "unchecked" ) @Override public <R extends Temporal> R adjustInto( R temporal, long newValue ) { int newVal = range.checkValidIntValue( newValue, this ); int oldYear = temporal.get( ChronoField.YEAR ); return (R) temporal.with( ChronoField.YEAR, (oldYear / years) * years + newVal ) .with( TemporalAdjusters.firstDayOfYear() ); }
public static TemporalAdjuster nextOrSameDayOfMonth(int dayOfMonth) { validateDayOfMonth(dayOfMonth); TemporalAdjuster nextDayOfMonth = nextDayOfMonth(dayOfMonth); return temporal -> { int currentDayOfMonth = temporal.get(DAY_OF_MONTH); if (currentDayOfMonth == dayOfMonth || (currentDayOfMonth < dayOfMonth && currentDayOfMonth == temporal.range(DAY_OF_MONTH).getMaximum())) { return temporal; } return temporal.with(nextDayOfMonth); }; }