@Override public LocalTime convert(OffsetDateTime source) { return source.toLocalTime(); } }
@Override public LocalTime convert(OffsetDateTime source) { return source.toLocalTime(); } }
@Override public LocalTime decode(final BsonReader reader, final DecoderContext decoderContext) { return Instant.ofEpochMilli(validateAndReadDateTime(reader)).atOffset(ZoneOffset.UTC).toLocalTime(); }
@Override public LocalTime convert(OffsetDateTime source) { return source.toLocalTime(); } }
OffsetDateTime odt = instant.atOffset( ZoneOffset.UTC ); LocalTime lt = odt.toLocalTime(); // 10:00:00
ZoneOffset offset = ZoneOffset.ofHours( -7 ); OffsetDateTime odt = OffsetDateTime.now( offset ); String output1 = odt.toLocalTime().toString(); System.out.println( "Current time in " + offset + ": " + output1 );
/** * Checks if the instant of this date-time is equal to that of the specified date-time. * <p> * This method differs from the comparison in {@link #compareTo} and {@link #equals} * in that it only compares the instant of the date-time. This is equivalent to using * {@code dateTime1.toInstant().equals(dateTime2.toInstant());}. * * @param other the other date-time to compare to, not null * @return true if the instant equals the instant of the specified date-time */ public boolean isEqual(OffsetDateTime other) { return toEpochSecond() == other.toEpochSecond() && toLocalTime().getNano() == other.toLocalTime().getNano(); }
/** * Checks if the instant of this date-time is before that of the specified date-time. * <p> * This method differs from the comparison in {@link #compareTo} in that it * only compares the instant of the date-time. This is equivalent to using * {@code dateTime1.toInstant().isBefore(dateTime2.toInstant());}. * * @param other the other date-time to compare to, not null * @return true if this is before the instant of the specified date-time */ public boolean isBefore(OffsetDateTime other) { long thisEpochSec = toEpochSecond(); long otherEpochSec = other.toEpochSecond(); return thisEpochSec < otherEpochSec || (thisEpochSec == otherEpochSec && toLocalTime().getNano() < other.toLocalTime().getNano()); }
/** * Checks if the instant of this date-time is after that of the specified date-time. * <p> * This method differs from the comparison in {@link #compareTo} and {@link #equals} in that it * only compares the instant of the date-time. This is equivalent to using * {@code dateTime1.toInstant().isAfter(dateTime2.toInstant());}. * * @param other the other date-time to compare to, not null * @return true if this is after the instant of the specified date-time */ public boolean isAfter(OffsetDateTime other) { long thisEpochSec = toEpochSecond(); long otherEpochSec = other.toEpochSecond(); return thisEpochSec > otherEpochSec || (thisEpochSec == otherEpochSec && toLocalTime().getNano() > other.toLocalTime().getNano()); }
@Override public void executeTerminateResourceJob(boolean isAppliedForClusters) { OffsetDateTime currentDateTime = OffsetDateTime.now(); List<SchedulerJobData> jobsToTerminate = getSchedulerJobsForAction(UserInstanceStatus.TERMINATED, currentDateTime, isAppliedForClusters); if (!jobsToTerminate.isEmpty()) { log.debug(isAppliedForClusters ? "Scheduler computational resource terminate job is executing..." : "Scheduler exploratory terminate job is executing..."); log.info(CURRENT_DATETIME_INFO, LocalTime.of(currentDateTime.toLocalTime().getHour(), currentDateTime.toLocalTime().getMinute()), currentDateTime.toLocalDate(), currentDateTime.getDayOfWeek()); log.info(isAppliedForClusters ? "Quantity of clusters for terminating: {}" : "Quantity of exploratories for terminating: {}", jobsToTerminate.size()); jobsToTerminate.forEach(job -> changeResourceStatusTo(UserInstanceStatus.TERMINATED, job, isAppliedForClusters)); } }
@Override public void executeStartResourceJob(boolean isAppliedForClusters) { OffsetDateTime currentDateTime = OffsetDateTime.now(); List<SchedulerJobData> jobsToStart = getSchedulerJobsForAction(UserInstanceStatus.RUNNING, currentDateTime, isAppliedForClusters); if (!jobsToStart.isEmpty()) { log.debug(isAppliedForClusters ? "Scheduler computational resource start job is executing..." : "Scheduler exploratory start job is executing..."); log.info(CURRENT_DATETIME_INFO, LocalTime.of(currentDateTime.toLocalTime().getHour(), currentDateTime.toLocalTime().getMinute()), currentDateTime.toLocalDate(), currentDateTime.getDayOfWeek()); log.info(isAppliedForClusters ? "Quantity of clusters for starting: {}" : "Quantity of exploratories for starting: {}", jobsToStart.size()); jobsToStart.forEach(job -> changeResourceStatusTo(UserInstanceStatus.RUNNING, job, isAppliedForClusters)); } }
@Override public void executeStopResourceJob(boolean isAppliedForClusters) { OffsetDateTime currentDateTime = OffsetDateTime.now(); List<SchedulerJobData> jobsToStop = getSchedulerJobsForAction(STOPPED, currentDateTime, isAppliedForClusters); if (!jobsToStop.isEmpty()) { log.debug(isAppliedForClusters ? "Scheduler computational resource stop job is executing..." : "Scheduler exploratory stop job is executing..."); log.info(CURRENT_DATETIME_INFO, LocalTime.of(currentDateTime.toLocalTime().getHour(), currentDateTime.toLocalTime().getMinute()), currentDateTime.toLocalDate(), currentDateTime.getDayOfWeek()); log.info(isAppliedForClusters ? "Quantity of clusters for stopping: {}" : "Quantity of exploratories for stopping: {}", jobsToStop.size()); jobsToStop.forEach(job -> changeResourceStatusTo(STOPPED, job, isAppliedForClusters)); } }
protected static String printLiteral(OffsetDateTime val) { return "TIMESTAMP '" + val.toLocalDate() + " " + printTime(val.toLocalTime()) + val.getOffset() + "'"; } }
/** * Serializes the {@code OffsetDateTime.toLocalDate}, * {@code LocalDateTime.toLocalTime}, and * {@code LocalDateTime.getOffset} values to {@code buffer}. * @param o an {@code OffsetDateTime} instance. * @param buffer write to this buffer. * @throws BufferOverflowException * if {@code buffer} does not contain enough space to store * the date, time, and offset values. */ @Override public void serialize(final Object o, final ByteBuffer buffer) throws BufferOverflowException { if (o instanceof OffsetDateTime) { final OffsetDateTime odt = (OffsetDateTime) o; buffer.putLong((odt.toLocalDate()).toEpochDay()) .putLong((odt.toLocalTime()).toNanoOfDay()) .putInt((odt.getOffset()).getTotalSeconds()); } return; } // end of serialize(Object, ByteBuffer)
public void write(Kryo kryo, Output out, OffsetDateTime obj) { LocalDateSerializer.write(out, obj.toLocalDate()); LocalTimeSerializer.write(out, obj.toLocalTime()); ZoneOffsetSerializer.write(out, obj.getOffset()); }
public void write (Kryo kryo, Output out, OffsetDateTime obj) { LocalDateSerializer.write(out, obj.toLocalDate()); LocalTimeSerializer.write(out, obj.toLocalTime()); ZoneOffsetSerializer.write(out, obj.getOffset()); }
public void write (Kryo kryo, Output out, OffsetDateTime obj) { LocalDateSerializer.write(out, obj.toLocalDate()); LocalTimeSerializer.write(out, obj.toLocalTime()); ZoneOffsetSerializer.write(out, obj.getOffset()); }
@SuppressWarnings("unchecked") public static <F extends AbstractField<?>> F fromLongValue(DataType type, int tagNum, long value) { switch (type) { case STRING: return (F) new StringField(tagNum, Long.toString(value)); case FLOAT: case PRICE: case PRICEOFFSET: case PERCENTAGE: case AMT: case QTY: // return (F) new FloatField(tagNum, new FixedPointNumber(value)); case INT: case LENGTH: case SEQNUM: case NUMINGROUP: return (F) new IntField(tagNum, (int) value); case UTCTIMESTAMP: return (F) new UTCTimestampField(tagNum, Instant.ofEpochMilli(value).atOffset(ZoneOffset.UTC).toZonedDateTime()); case UTCTIMEONLY: return (F) new UTCTimeOnlyField(tagNum, Instant.ofEpochMilli(value).atOffset(ZoneOffset.UTC).toLocalTime()); case UTCDATEONLY: return (F) new UTCDateOnlyField(tagNum, Instant.ofEpochMilli(value).atOffset(ZoneOffset.UTC).toLocalDate()); default: throw new IllegalArgumentException("Value " + value + " is not applicable for field: " + tagNum + '(' + type + ')'); } }
/** * Checks if scheduler's time data satisfies existing time parameters. * * @param dto scheduler job data. * @param dateTime existing time data. * @param desiredStatus target exploratory status which has influence for time/date checking ('running' status * requires for checking start time, 'stopped' - for end time, 'terminated' - for * 'terminatedDateTime'). * @return true/false. */ private boolean isSchedulerJobDtoSatisfyCondition(SchedulerJobDTO dto, OffsetDateTime dateTime, UserInstanceStatus desiredStatus) { ZoneOffset zOffset = dto.getTimeZoneOffset(); OffsetDateTime roundedDateTime = OffsetDateTime.of( dateTime.toLocalDate(), LocalTime.of(dateTime.toLocalTime().getHour(), dateTime.toLocalTime().getMinute()), dateTime.getOffset()); LocalDateTime convertedDateTime = ZonedDateTime.ofInstant(roundedDateTime.toInstant(), ZoneId.ofOffset(TIMEZONE_PREFIX, zOffset)).toLocalDateTime(); return desiredStatus == TERMINATED ? Objects.nonNull(dto.getTerminateDateTime()) && convertedDateTime.toLocalDate().equals(dto.getTerminateDateTime().toLocalDate()) && convertedDateTime.toLocalTime().equals(getDesiredTime(dto, desiredStatus)) : !convertedDateTime.toLocalDate().isBefore(dto.getBeginDate()) && isFinishDateMatchesCondition(dto, convertedDateTime) && getDaysRepeat(dto, desiredStatus).contains(convertedDateTime.toLocalDate().getDayOfWeek()) && convertedDateTime.toLocalTime().equals(getDesiredTime(dto, desiredStatus)); }
@Test public void testObjectToOffsetTime() throws Exception { ZoneId zoneId = ZoneId.systemDefault(); OffsetTime offsetTime = OffsetTime.now(zoneId); testObjectToOffsetTime(null, null); testObjectToOffsetTime(offsetTime, offsetTime); testObjectToOffsetTime(offsetTime.atDate(LocalDate.now()), offsetTime); testObjectToOffsetTime(offsetTime.atDate(LocalDate.now()).atZoneSimilarLocal(zoneId), offsetTime); testObjectToOffsetTime(offsetTime.atDate(LocalDate.now()).toLocalDateTime(), offsetTime); testObjectToOffsetTime(offsetTime.atDate(LocalDate.now()).toLocalTime(), offsetTime); testObjectToOffsetTime(offsetTime.atDate(LocalDate.now()).toInstant(), offsetTime); testObjectToOffsetTime(Date.from(offsetTime.atDate(LocalDate.now()).toInstant()), offsetTime.truncatedTo(ChronoUnit.MILLIS)); try { testObjectToOffsetTime("a string", offsetTime); fail(); } catch (IllegalArgumentException e) { // expected } }