Java Code Examples for java.time.LocalDateTime#now()
The following examples show how to use
java.time.LocalDateTime#now() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestExportProfiles.java From dremio-oss with Apache License 2.0 | 6 votes |
/** * Test export-profiles display message when no profiles were found. */ @Test public void testRetrieveExportProfileStats() throws Exception { final String tmpPath = folder0.newFolder("testStats").getAbsolutePath(); final LocalDateTime toDate = LocalDateTime.now(); final LocalDateTime fromDate = toDate.minusDays(30); ExportProfilesStats stats = new ExportProfilesStats(0, 0, 0, tmpPath); String expect = String.format("Defaulting to %s to %s. No profiles were found for the duration.", fromDate, toDate); assertEquals(expect, stats.retrieveStats(fromDate, toDate, false)); expect = String.format("No profiles were found from %s to %s.", fromDate, toDate); assertEquals(expect, stats.retrieveStats(fromDate, toDate, true)); expect = String.format("No profiles were found."); assertEquals(expect, stats.retrieveStats(null, null, false)); }
Example 2
Source File: MediaScannerService.java From airsonic-advanced with GNU General Public License v3.0 | 6 votes |
/** * Schedule background execution of media library scanning. */ public synchronized void schedule() { if (scheduler != null) { scheduler.shutdown(); } long daysBetween = settingsService.getIndexCreationInterval(); int hour = settingsService.getIndexCreationHour(); if (daysBetween == -1) { LOG.info("Automatic media scanning disabled."); return; } scheduler = Executors.newSingleThreadScheduledExecutor(); LocalDateTime now = LocalDateTime.now(); LocalDateTime nextRun = now.withHour(hour).withMinute(0).withSecond(0); if (now.compareTo(nextRun) > 0) nextRun = nextRun.plusDays(1); long initialDelay = ChronoUnit.MILLIS.between(now, nextRun); scheduler.scheduleAtFixedRate(() -> scanLibrary(), initialDelay, TimeUnit.DAYS.toMillis(daysBetween), TimeUnit.MILLISECONDS); LOG.info("Automatic media library scanning scheduled to run every {} day(s), starting at {}", daysBetween, nextRun); // In addition, create index immediately if it doesn't exist on disk. if (neverScanned()) { LOG.info("Media library never scanned. Doing it now."); scanLibrary(); } }
Example 3
Source File: EntityManagerTest.java From catatumbo with Apache License 2.0 | 5 votes |
@Test public void testUpdateLocalDateTimeField() { LocalDateTimeField entity = new LocalDateTimeField(); LocalDateTime now = LocalDateTime.now(); entity.setTimestamp(now); entity = em.insert(entity); LocalDateTime nextDay = now.plusDays(1); entity.setTimestamp(nextDay); entity = em.update(entity); entity = em.load(LocalDateTimeField.class, entity.getId()); assertEquals(nextDay, entity.getTimestamp()); }
Example 4
Source File: SignupService.java From wallride with Apache License 2.0 | 5 votes |
public boolean validateInvitation(UserInvitation invitation) { if (invitation == null) { return false; } if (invitation.isAccepted()) { return false; } LocalDateTime now = LocalDateTime.now(); if (now.isAfter(invitation.getExpiredAt())) { return false; } return true; }
Example 5
Source File: IntervalIntegrationTests.java From salespoint with Apache License 2.0 | 5 votes |
@Test // #152 void intervalCanBePersistedAsEmbeddable() { LocalDateTime now = LocalDateTime.now(); SomeEntity entity = new SomeEntity(); entity.interval = Interval.from(now).to(now.plusDays(1)); repository.save(entity); em.flush(); em.clear(); Optional<SomeEntity> result = repository.findById(entity.id); assertThat(result).map(it -> it.interval).hasValue(entity.interval); }
Example 6
Source File: TaskUtil.java From GriefDefender with MIT License | 5 votes |
public static long computeDelay(int targetHour, int targetMin, int targetSec) { LocalDateTime localNow = LocalDateTime.now(); ZoneId currentZone = ZoneId.systemDefault(); ZonedDateTime zonedNow = ZonedDateTime.of(localNow, currentZone); ZonedDateTime zonedNextTarget = zonedNow.withHour(targetHour).withMinute(targetMin).withSecond(targetSec); if(zonedNow.compareTo(zonedNextTarget) > 0) { zonedNextTarget = zonedNextTarget.plusDays(1); } Duration duration = Duration.between(zonedNow, zonedNextTarget); return duration.getSeconds(); }
Example 7
Source File: RqueueDashboardChartServiceTest.java From rqueue with Apache License 2.0 | 5 votes |
@Test public void getDashboardChartDataStatsDailyMissingDays() { LocalDateTime localDateTime = LocalDateTime.now(); if (localDateTime.getHour() > 22) { log.info("test cannot be run at this time"); return; } String id = "__rq::q-stat::job"; QueueStatistics queueStatistics = new QueueStatistics(id); LocalDate localDate = DateTimeUtils.today(); for (int i = 10; i < rqueueWebConfig.getHistoryDay() - 10; i++) { QueueStatisticsTest.addData(queueStatistics, localDate, i); } doReturn(Collections.singletonList(queueStatistics)) .when(rqueueQStatsDao) .findAll(Collections.singleton(id)); ChartDataRequest chartDataRequest = new ChartDataRequest(); chartDataRequest.setType(ChartType.STATS); chartDataRequest.setAggregationType(AggregationType.DAILY); chartDataRequest.setQueue("job"); ChartDataResponse response = rqueueDashboardChartService.getDashboardChartData(chartDataRequest); assertEquals(rqueueWebConfig.getHistoryDay() + 1, response.getData().size()); localDate = DateTimeUtils.today(); for (int i = 1; i <= rqueueWebConfig.getHistoryDay(); i++) { LocalDate date = localDate.plusDays(-rqueueWebConfig.getHistoryDay() + i); long discarded = queueStatistics.tasksDiscarded(date.toString()); long successful = queueStatistics.tasksSuccessful(date.toString()); long dlq = queueStatistics.tasksMovedToDeadLetter(date.toString()); long retries = queueStatistics.tasksRetried(date.toString()); List<Serializable> row = response.getData().get(i); assertEquals(successful, row.get(1)); assertEquals(discarded, row.get(2)); assertEquals(dlq, row.get(3)); assertEquals(retries, row.get(4)); } }
Example 8
Source File: CardManageRequestHandler.java From butterfly with Apache License 2.0 | 5 votes |
/** * Handles an incoming request for the <code>cardmng.getrefid</code> module. * @param requestBody The XML document of the incoming request. * @param request The Spark request * @param response The Spark response * @return A response object for Spark */ private Object handleGetRefIdRequest(final Element requestBody, final Request request, final Response response) { // this request is to create a new card final Node requestNode = XmlUtils.nodeAtPath(requestBody, "/cardmng"); final String cardId = requestNode.getAttributes().getNamedItem("cardid").getNodeValue(); final int cardTypeInt = Integer.parseInt(requestNode.getAttributes().getNamedItem("cardtype").getNodeValue()); final CardType cardType = CardType.values()[cardTypeInt - 1]; final String pin = requestNode.getAttributes().getNamedItem("passwd").getNodeValue(); // make sure the card doesn't already exist if (this.cardDao.findByNfcId(cardId) != null) { throw new InvalidRequestException(); } // create a new user that this card is bound to final ButterflyUser newUser = new ButterflyUser(pin, LocalDateTime.now(), LocalDateTime.now(), 10000); userDao.create(newUser); // create the card and save it final Card card = new Card(newUser, cardType, cardId, this.cardIdUtils.encodeCardId(cardId), StringUtils.getRandomHexString(16), LocalDateTime.now(), LocalDateTime.now()); this.cardDao.create(card); // send a response final KXmlBuilder builder = KXmlBuilder.create("response") .e("cardmng").a("dataid", card.getRefId()).a("refid", card.getRefId()); return this.sendResponse(request, response, builder); }
Example 9
Source File: SummerPricePolicy.java From microservice_coffeeshop with Apache License 2.0 | 5 votes |
@Override public boolean seasonMatch() { LocalDateTime localDateTime = LocalDateTime.now(); if (3 <= localDateTime.getDayOfMonth() && localDateTime.getDayOfMonth() <= 9) { return true; } return false; }
Example 10
Source File: TimestampTests.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
@Test public void test43() throws Exception { LocalDateTime ldt = LocalDateTime.now(); Timestamp ts2 = Timestamp.valueOf(ldt); assertTrue(ldt.equals(ts2.toLocalDateTime()), "Error LocalDateTime values are not equal"); }
Example 11
Source File: ApiError.java From eladmin with Apache License 2.0 | 4 votes |
private ApiError() { timestamp = LocalDateTime.now(); }
Example 12
Source File: BotReportData.java From L2jOrg with GNU General Public License v3.0 | 4 votes |
public BotReportData(int botId, int reporterId, String type) { this.botId = botId; this.reporterId = reporterId; reportDate = LocalDateTime.now(); this.type = type; }
Example 13
Source File: WxCouponController.java From BigDataPlatform with GNU General Public License v3.0 | 4 votes |
/** * 优惠券领取 * * @param userId 用户ID * @param body 请求内容, { couponId: xxx } * @return 操作结果 */ @PostMapping("receive") public Object receive(@LoginUser Integer userId, @RequestBody String body) { if (userId == null) { return ResponseUtil.unlogin(); } Integer couponId = JacksonUtil.parseInteger(body, "couponId"); if(couponId == null){ return ResponseUtil.badArgument(); } LitemallCoupon coupon = couponService.findById(couponId); if(coupon == null){ return ResponseUtil.badArgumentValue(); } // 当前已领取数量和总数量比较 Integer total = coupon.getTotal(); Integer totalCoupons = couponUserService.countCoupon(couponId); if((total != 0) && (totalCoupons >= total)){ return ResponseUtil.fail(WxResponseCode.COUPON_EXCEED_LIMIT, "优惠券已领完"); } // 当前用户已领取数量和用户限领数量比较 Integer limit = coupon.getLimit().intValue(); Integer userCounpons = couponUserService.countUserAndCoupon(userId, couponId); if((limit != 0) && (userCounpons >= limit)){ return ResponseUtil.fail(WxResponseCode.COUPON_EXCEED_LIMIT, "优惠券已经领取过"); } // 优惠券分发类型 // 例如注册赠券类型的优惠券不能领取 Short type = coupon.getType(); if(type.equals(CouponConstant.TYPE_REGISTER)){ return ResponseUtil.fail(WxResponseCode.COUPON_RECEIVE_FAIL, "新用户优惠券自动发送"); } else if(type.equals(CouponConstant.TYPE_CODE)){ return ResponseUtil.fail(WxResponseCode.COUPON_RECEIVE_FAIL, "优惠券只能兑换"); } else if(!type.equals(CouponConstant.TYPE_COMMON)){ return ResponseUtil.fail(WxResponseCode.COUPON_RECEIVE_FAIL, "优惠券类型不支持"); } // 优惠券状态,已下架或者过期不能领取 Short status = coupon.getStatus(); if(status.equals(CouponConstant.STATUS_OUT)){ return ResponseUtil.fail(WxResponseCode.COUPON_EXCEED_LIMIT, "优惠券已领完"); } else if(status.equals(CouponConstant.STATUS_EXPIRED)){ return ResponseUtil.fail(WxResponseCode.COUPON_RECEIVE_FAIL, "优惠券已经过期"); } // 用户领券记录 LitemallCouponUser couponUser = new LitemallCouponUser(); couponUser.setCouponId(couponId); couponUser.setUserId(userId); Short timeType = coupon.getTimeType(); if (timeType.equals(CouponConstant.TIME_TYPE_TIME)) { couponUser.setStartTime(coupon.getStartTime()); couponUser.setEndTime(coupon.getEndTime()); } else{ LocalDateTime now = LocalDateTime.now(); couponUser.setStartTime(now); couponUser.setEndTime(now.plusDays(coupon.getDays())); } couponUserService.add(couponUser); return ResponseUtil.ok(); }
Example 14
Source File: BCUserInfo.java From ACManager with GNU General Public License v3.0 | 4 votes |
public void setRating(Integer rating) { this.rating = rating; updateTime = LocalDateTime.now(); }
Example 15
Source File: BaseEntity.java From spring-boot-jpa-data-rest-soft-delete with MIT License | 4 votes |
@PreUpdate protected void onUpdate() { this.updatedOn = LocalDateTime.now(); }
Example 16
Source File: TCKLocalDateTime.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
@Test public void now_Clock_minYear() { Clock clock = Clock.fixed(MIN_INSTANT, ZoneOffset.UTC); LocalDateTime test = LocalDateTime.now(clock); assertEquals(test, MIN_DATE_TIME); }
Example 17
Source File: BCUserInfo.java From ACManager with GNU General Public License v3.0 | 4 votes |
public BCUserInfo(String bcname, Integer rating) { this.bcname = bcname; this.rating = rating; updateTime = LocalDateTime.now(); }
Example 18
Source File: ElapsedTime.java From youtube-comment-suite with MIT License | 4 votes |
public void setNow() { time = LocalDateTime.now(); }
Example 19
Source File: TCKLocalDateTime.java From jdk8u_jdk with GNU General Public License v2.0 | 4 votes |
@Test public void now_Clock_minYear() { Clock clock = Clock.fixed(MIN_INSTANT, ZoneOffset.UTC); LocalDateTime test = LocalDateTime.now(clock); assertEquals(test, MIN_DATE_TIME); }
Example 20
Source File: TCKLocalDateTime.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
@Test(expectedExceptions=DateTimeException.class) public void now_Clock_tooLow() { Clock clock = Clock.fixed(MIN_INSTANT.minusNanos(1), ZoneOffset.UTC); LocalDateTime.now(clock); }