private static PlainTime createFromMillis( int millisOfDay, int micros ) { int nanosecond = (millisOfDay % KILO) * MIO + micros; int secondsOfDay = millisOfDay / KILO; int second = secondsOfDay % 60; int minutesOfDay = secondsOfDay / 60; int minute = minutesOfDay % 60; int hour = minutesOfDay / 60; return PlainTime.of(hour, minute, second, nanosecond); }
private static PlainTime createFromMicros( long microsOfDay, int nanos ) { int nanosecond = ((int) (microsOfDay % MIO)) * KILO + nanos; int secondsOfDay = (int) (microsOfDay / MIO); int second = secondsOfDay % 60; int minutesOfDay = secondsOfDay / 60; int minute = minutesOfDay % 60; int hour = minutesOfDay / 60; return PlainTime.of(hour, minute, second, nanosecond); }
@Override public PlainTime getDefaultMaximum() { return PlainTime.of(23, 59, 59, 999999999); }
private static PlainTime createFromNanos(long nanosOfDay) { int nanosecond = (int) (nanosOfDay % MRD); int secondsOfDay = (int) (nanosOfDay / MRD); int second = secondsOfDay % 60; int minutesOfDay = secondsOfDay / 60; int minute = minutesOfDay % 60; int hour = minutesOfDay / 60; return PlainTime.of(hour, minute, second, nanosecond); }
private PlainTime readTime(DataInput in) throws IOException { int hour = in.readByte(); if (hour < 0) { return PlainTime.of(~hour); } else { int second = 0, nano = 0; int minute = in.readByte(); if (minute < 0) { minute = ~minute; } else { second = in.readByte(); if (second < 0) { second = ~second; } else { nano = in.readInt(); } } return PlainTime.of(hour, minute, second, nano); } }
@Override public PlainTime withValue( PlainTime context, Meridiem value, boolean lenient ) { int h = ((context.hour == 24) ? 0 : context.hour); if (value == null) { throw new IllegalArgumentException("Missing am/pm-value."); } else if (value == Meridiem.AM) { if (h >= 12) { h -= 12; } } else if (value == Meridiem.PM) { if (h < 12) { h += 12; } } return PlainTime.of( h, context.minute, context.second, context.nano ); }
private static PlainTime of( int hour, int minute, int second, int nanosecond, boolean validating ) { if ((minute | second | nanosecond) == 0) { if (validating) { return PlainTime.of(hour); } else { return HOURS[hour]; } } return new PlainTime(hour, minute, second, nanosecond, validating); }
/** * <p>Is equivalent to {@code at(PlainTime.of(hour, minute, second))}. </p> * * @param hour hour of day in range (0-24) * @param minute minute of hour in range (0-59) * @param second second of hour in range (0-59) * @return local timestamp as composition of this date and given time * @throws IllegalArgumentException if any argument is out of range */ /*[deutsch] * <p>Entspricht {@code at(PlainTime.of(hour, minute, second))}. </p> * * @param hour hour of day in range (0-24) * @param minute minute of hour in range (0-59) * @param second second of hour in range (0-59) * @return local timestamp as composition of this date and given time * @throws IllegalArgumentException if any argument is out of range */ public PlainTimestamp atTime( int hour, int minute, int second ) { return this.at(PlainTime.of(hour, minute, second)); }
/** * <p>Is equivalent to {@code at(PlainTime.of(hour, minute))}. </p> * * @param hour hour of day in range (0-24) * @param minute minute of hour in range (0-59) * @return local timestamp as composition of this date and given time * @throws IllegalArgumentException if any argument is out of range */ /*[deutsch] * <p>Entspricht {@code at(PlainTime.of(hour, minute))}. </p> * * @param hour hour of day in range (0-24) * @param minute minute of hour in range (0-59) * @return local timestamp as composition of this date and given time * @throws IllegalArgumentException if any argument is out of range */ public PlainTimestamp atTime( int hour, int minute ) { return this.at(PlainTime.of(hour, minute)); }
/** * <p>Creates a wall time with hour and minute. </p> * * @param hour hour of day in the range {@code 0-23} or * {@code 24} if the given minute equals to {@code 0} * @param minute minute in the range {@code 0-59} * @return new or cached wall time * @throws IllegalArgumentException if any argument is out of range */ /*[deutsch] * <p>Erzeugt eine neue Uhrzeit mit Stunde und Minute. </p> * * @param hour hour of day in the range {@code 0-23} or * {@code 24} if the given minute equals to {@code 0} * @param minute minute in the range {@code 0-59} * @return new or cached wall time * @throws IllegalArgumentException if any argument is out of range */ public static PlainTime of( int hour, int minute ) { if (minute == 0) { return PlainTime.of(hour); } return new PlainTime(hour, minute, 0, 0, true); }
private PlainTime getTimeUTC() { int timeOfDay = getTimeOfDay(this); int minutes = timeOfDay / 60; int hour = minutes / 60; int minute = minutes % 60; int second = timeOfDay % 60; int nano = this.getNanosecond(); return PlainTime.of(hour, minute, second, nano); }
/** * <p>Creates a wall time with hour, minute and second. </p> * * @param hour hour in the range {@code 0-23} or {@code 24} * if the other arguments are equal to {@code 0} * @param minute minute in the range {@code 0-59} * @param second second in the range {@code 0-59} * @return new or cached wall time * @throws IllegalArgumentException if any argument is out of range */ /*[deutsch] * <p>Erzeugt eine neue Uhrzeit mit Stunde, Minute und Sekunde. </p> * * @param hour hour in the range {@code 0-23} or {@code 24} * if the other arguments are equal to {@code 0} * @param minute minute in the range {@code 0-59} * @param second second in the range {@code 0-59} * @return new or cached wall time * @throws IllegalArgumentException if any argument is out of range */ public static PlainTime of( int hour, int minute, int second ) { if ((minute | second) == 0) { return PlainTime.of(hour); } return new PlainTime(hour, minute, second, 0, true); }
@Override public PlainTime translate(LocalTime source) { return PlainTime.of(source.getHour(), source.getMinute(), source.getSecond(), source.getNano()); }
@Override public String getValue(ChronoEntity<?> context) { // used in consistency-check after strict parsing PlainTime time = context.get(PlainTime.COMPONENT); if (this.fixed) { return getFixedCode(time); } else { if (this.dayPeriod.isPredefined()) { Map<String, String> textForms = loadTextForms(this.getLocale(), this.getCalendarType()); String code = null; if (time.isMidnight()) { code = "midnight"; } else if (time.isSimultaneous(PlainTime.of(12))) { code = "noon"; } if (code != null) { String key = createKey(textForms, TextWidth.ABBREVIATED, OutputContext.FORMAT, code); if (textForms.containsKey(key)) { return code; } } } PlainTime key = this.dayPeriod.getStart(time); return this.dayPeriod.codeMap.get(key); } }
@Override public java.sql.Date from(PlainDate date) { int year = date.getYear(); if ((year < 1900) || (year > 9999)) { throw new ChronoException( "SQL-Date is only defined in year range of 1900-9999."); } long millis = // localMillis MathUtils.safeMultiply( date.get(EpochDays.UNIX), 86400 * 1000); if (!WITH_SQL_UTC_CONVERSION) { ZonalOffset offset = Timezone.ofSystem().getOffset(date, PlainTime.of(0)); millis -= offset.getIntegralAmount() * 1000; } return new java.sql.Date(millis); }
/** * <p>Common conversion method. </p> * * @param time ISO-time * @return PlainTime */ /*[deutsch] * <p>Allgemeine Konversionsmethode. </p> * * @param time ISO-time * @return PlainTime */ public static PlainTime from(WallTime time) { if (time instanceof PlainTime) { return (PlainTime) time; } else if (time instanceof PlainTimestamp) { return ((PlainTimestamp) time).getWallTime(); } else { return PlainTime.of( time.getHour(), time.getMinute(), time.getSecond(), time.getNanosecond()); } }
int hour = minutesOfDay / 60; return PlainTime.of( hour, minute,
@Override public PlainTimestamp translate(java.sql.Timestamp source) { long millis = source.getTime(); // UTC zone if (!WITH_SQL_UTC_CONVERSION) { Moment unixTime = Moment.of( MathUtils.floorDivide(millis, 1000), TimeScale.POSIX); ZonalOffset offset = Timezone.ofSystem().getOffset(unixTime); millis += offset.getIntegralAmount() * 1000; } PlainDate date = PlainDate.of( MathUtils.floorDivide(millis, 86400 * 1000), EpochDays.UNIX); PlainTime time = PlainTime.of(0).plus( MathUtils.floorModulo(millis, 86400 * 1000), ClockUnit.MILLIS); PlainTimestamp ts = PlainTimestamp.of(date, time); return ts.with(PlainTime.NANO_OF_SECOND, source.getNanos()); }
@Override public PlainTimestamp translate(LocalDateTime source) { return PlainTimestamp.of( PlainDate.of(source.getYear(), source.getMonthValue(), source.getDayOfMonth()), PlainTime.of(source.getHour(), source.getMinute(), source.getSecond(), source.getNano()) ); }
private PlainTimestamp atStartOfDay(TransitionHistory history) { if (history == null) { throw new UnsupportedOperationException( "Timezone repository does not expose its transition history: " + Timezone.getProviderInfo()); } ZonalTransition conflict = history.getConflictTransition(this, PlainTime.MIN); if ((conflict != null) && conflict.isGap()) { long localSeconds = conflict.getPosixTime() + conflict.getTotalOffset(); PlainDate date = PlainDate.of( MathUtils.floorDivide(localSeconds, 86400), EpochDays.UNIX); int secondsOfDay = MathUtils.floorModulo(localSeconds, 86400); int second = secondsOfDay % 60; int minutesOfDay = secondsOfDay / 60; int minute = minutesOfDay % 60; int hour = minutesOfDay / 60; PlainTime time = PlainTime.of(hour, minute, second); return PlainTimestamp.of(date, time); } return this.at(PlainTime.MIN); }