@Override public OffsetDateTime seed(SharedSessionContractImplementor session) { return OffsetDateTime.now(); }
@Override public OffsetDateTime next(OffsetDateTime current, SharedSessionContractImplementor session) { return OffsetDateTime.now(); }
/** * Reset statistics */ public void reset() { statByType.forEach((t, s) -> s.forEach((k, sh) -> sh.resetStatistics()) ); startTime = OffsetDateTime.now(); }
private void setCreatedAfterFromDates(IssueQuery.Builder builder, @Nullable Date createdAfter, @Nullable String createdInLast, boolean createdAfterInclusive) { checkArgument(createdAfter == null || createdInLast == null, format("Parameters %s and %s cannot be set simultaneously", PARAM_CREATED_AFTER, PARAM_CREATED_IN_LAST)); Date actualCreatedAfter = createdAfter; if (createdInLast != null) { actualCreatedAfter = Date.from( OffsetDateTime.now(clock) .minus(Period.parse("P" + createdInLast.toUpperCase(Locale.ENGLISH))) .toInstant()); } builder.createdAfter(actualCreatedAfter, createdAfterInclusive); }
@Override public Set<EventPublisher> execute(EventPublisherMapper mapper) { // 取出3秒前已经发送过至队列但是没有收到ack请求的消息,并进行重试 return mapper.selectLimitedEntityByEventStatusBeforeTheSpecifiedUpdateTime(EventStatus.PENDING, 300, OffsetDateTime.now().minusSeconds(3)); } }
@Override public int updateNonNullProperties(T entity) { Preconditions.checkNotNull(entity, "entity in updating should not be NULL"); entity.setUpdateTime(OffsetDateTime.now()); return getMapper().updateByPrimaryKeySelective(entity); }
@Override public int update(T entity) { Preconditions.checkNotNull(entity, "entity in updating should not be NULL"); entity.setUpdateTime(OffsetDateTime.now()); return getMapper().updateByPrimaryKey(entity); }
@Override public SqlStatementCustomizer createForMethod(Annotation annotation, Class<?> sqlObjectType, Method method) { final String parameterName = ((Timestamped) annotation).value(); return stmt -> { ZoneId zone = stmt.getConfig(TimestampedConfig.class).getTimezone(); stmt.bind(parameterName, OffsetDateTime.now(timeSource.apply(zone))); }; }
/** * 直接向服务查询, 不再自作聪明地在本地进行过期时间检查, 以免无法区分not found与conflict */ @Deprecated private void checkExpireInLocal(TccRequest request, List<Participant> participantLinks) { // 获取最接近过期的时间 final OffsetDateTime theClosestToExpire = fetchTheRecentlyExpireTime(participantLinks); if (theClosestToExpire.minusSeconds(LEEWAY).isBefore(OffsetDateTime.now())) { // 释放全部资源 cancel(request); throw new ReservationAlmostToExpireException("there are resources be about to expire at " + theClosestToExpire); } }
private static String currentTimeZoneOffsetString() { ZoneOffset offset = OffsetDateTime.now().getOffset(); return offset.equals( UTC ) ? "+0000" : offset.toString().replace( ":", "" ); } }
private void initializeOffsetDateTime(T entity) { entity.setCreateTime(OffsetDateTime.now()); if (entity.getUpdateTime() == null) { entity.setUpdateTime(IdentityDomain.DEFAULT_DATE_TIME); } if (entity.getDeleteTime() == null) { entity.setDeleteTime(IdentityDomain.DEFAULT_DATE_TIME); } }
@Override public SqlStatementCustomizer createForType(Annotation annotation, Class<?> sqlObjectType) { return stmt -> stmt.bind("now", OffsetDateTime.now(stmt.getConfig(Config.class).clock)); } }
@Test public void shouldFailWhenOffsetDateTimeIsSentWithRun() throws Exception { testFailureWithV2Value( ValueUtils.of( OffsetDateTime.now() ), "OffsetDateTime" ); }
@Test public void shouldCallExternalErrorOnDateTimeWithOffset() throws Exception { assumeThat( packerUnderTest.version(), equalTo( 1L ) ); testUnpackableStructParametersWithKnownType( new Neo4jPackV2(), ValueUtils.of( OffsetDateTime.now() ), "OffsetDateTime values cannot be unpacked with this version of bolt." ); }
@Test public void offsetDateTime() { OffsetDateTime dt = OffsetDateTime.now(); h.execute("insert into stuff(ts) values (?)", dt); assertThat(h.createQuery("select ts from stuff").mapTo(OffsetDateTime.class).findOnly()).isEqualTo(dt); }
@Test public void offsetDateTimeLosesOffset() { OffsetDateTime dt = OffsetDateTime.now().withOffsetSameInstant(ZoneOffset.ofHours(-7)); h.execute("insert into stuff(ts) values (?)", dt); assertThat(h.createQuery("select ts from stuff").mapTo(OffsetDateTime.class).findOnly().isEqual(dt)).isTrue(); }
@Test public void offsetDateTimeLosesOffset() { OffsetDateTime dt = OffsetDateTime.now().withOffsetSameInstant(ZoneOffset.ofHours(-7)); h.execute("insert into stuff(ts) values (?)", dt); assertThat(dt.isEqual(h.createQuery("select ts from stuff").mapTo(OffsetDateTime.class).findOnly())).isTrue(); }
@Test public void offsetDateTime() { OffsetDateTime dt = OffsetDateTime.now().withOffsetSameInstant(ZoneOffset.UTC); h.execute("insert into stuff(ts) values (?)", dt); assertThat(h.createQuery("select ts from stuff").mapTo(OffsetDateTime.class).findOnly()).isEqualTo(dt); }
@Test public void testParseDateAsDuration() { OffsetDateTime oneMinuteFromNow = OffsetDateTime.now().plusMinutes(1); long parsedMilliseconds = DateTimeUtils.parseDateAsDuration(oneMinuteFromNow.format(DateTimeFormatter.ISO_DATE_TIME)); assertTrue("Parsed date as duration is bigger than " + MINUTE_IN_MILLISECONDS, parsedMilliseconds <= MINUTE_IN_MILLISECONDS); assertTrue("Parsed date as duration is too low! Expected value is between " + MINUTE_IN_MILLISECONDS + " and " + FIFTY_NINE_SECONDS_IN_MILLISECONDS + " but is " + parsedMilliseconds, parsedMilliseconds > FIFTY_NINE_SECONDS_IN_MILLISECONDS); }
@Test public void testParseRepeatablePeriodAndEndDateTime() { OffsetDateTime twoMinutesFromNow = OffsetDateTime.now().plusMinutes(2); String twoMinutesFromNowFormatted = twoMinutesFromNow.format(DateTimeFormatter.ISO_DATE_TIME); String isoString = "R5/PT1M/" + twoMinutesFromNowFormatted; long[] parsedRepeatable = DateTimeUtils.parseRepeatableDateTime(isoString); assertEquals(5L, parsedRepeatable[0]); assertTrue("Parsed delay is bigger than " + MINUTE_IN_MILLISECONDS, parsedRepeatable[1] <= MINUTE_IN_MILLISECONDS); assertTrue("Parsed delay is too low! Expected value is between " + MINUTE_IN_MILLISECONDS + " and " + FIFTY_NINE_SECONDS_IN_MILLISECONDS + " but is " + parsedRepeatable[1], parsedRepeatable[1] > FIFTY_NINE_SECONDS_IN_MILLISECONDS); assertEquals("Parsed period should be one minute in milliseconds but is " + parsedRepeatable[2], MINUTE_IN_MILLISECONDS, parsedRepeatable[2]); }