List of usage examples for java.time LocalDate now
public static LocalDate now()
From source file:example.app.model.Person.java
public void setBirthDateFor(int age) { Assert.isTrue(age >= 0, "Age must be greater than equal to 0"); setBirthDate(LocalDate.now().minusYears(age)); }
From source file:nu.yona.server.admin.DashboardController.java
private List<HistoryInterval> determineIntervals(List<Integer> intervalEndOffsets) { HistoryInterval.setNextStart(LocalDate.now()); List<HistoryInterval> intervals = intervalEndOffsets.stream().map(HistoryInterval::nextInstance) .collect(Collectors.toList()); intervals.add(HistoryInterval.nextInstance(LONG_AGO)); return intervals; }
From source file:com.omertron.slackbot.functions.Meetup.java
/** * Format the MeetUp list into a list of Slack Attachments, up to a certain number of days ahead * * @param daysAhead/* w ww.j a v a2 s.c o m*/ * @param detailed * @return */ public static Map<LocalDateTime, SlackAttachment> getMeetupsDays(int daysAhead, boolean detailed) { LocalDate now = LocalDate.now(); Map<LocalDateTime, SlackAttachment> results = new HashMap<>(); Period diff; for (MeetupDetails md : MEETUPS) { // Correct for BST LocalDateTime meetTime = md.getMeetupTime().plusHours(1); diff = Period.between(now, meetTime.toLocalDate()); if (diff.getDays() <= daysAhead) { LOG.info("Add: Days: {} - {} - {}", diff.getDays(), meetTime.format(DT_FORMAT), md.getName()); results.put(meetTime, makeSlackAttachment(md, detailed)); } else { LOG.info("Skip: Days: {} - {} - {}", diff.getDays(), meetTime.format(DT_FORMAT), md.getName()); } } return results; }
From source file:alfio.manager.UploadedResourceIntegrationTest.java
@Before public void ensureConfiguration() { IntegrationTestUtil.ensureMinimalConfiguration(configurationRepository); List<TicketCategoryModification> categories = Collections.singletonList(new TicketCategoryModification(null, "default", AVAILABLE_SEATS, new DateTimeModification(LocalDate.now().minusDays(1), LocalTime.now()), new DateTimeModification(LocalDate.now().plusDays(1), LocalTime.now()), DESCRIPTION, BigDecimal.TEN, false, "", false, null, null, null, null, null)); Pair<Event, String> eventAndUser = initEvent(categories, organizationRepository, userManager, eventManager, eventRepository);/* w w w .ja va 2s . c o m*/ event = eventAndUser.getKey(); user = eventAndUser.getValue() + "_owner"; }
From source file:example.app.model.Person.java
public void setBirthDate(LocalDate birthDate) { if (birthDate != null && birthDate.isAfter(LocalDate.now())) { throw new IllegalArgumentException( String.format("[%s] cannot be born after today [%s]", getName(), toString(LocalDate.now()))); }//from www. ja v a2 s.c o m this.birthDate = birthDate; }
From source file:no.kantega.openaksess.search.searchlog.action.ViewSearchLogAction.java
private LocalDate getFromDate(String fromDateParam) { return java.util.Optional.ofNullable(defaultIfBlank(fromDateParam, null)) .map(s -> LocalDate.parse(s, formatter)).orElseGet(() -> LocalDate.now().minusMonths(1)); }
From source file:net.ceos.project.poi.annotated.bean.MultiTypeObjectBuilder.java
/** * Validate the MultiTypeObject based on the object build with the method * 'buildMultiTypeObject'// w w w .j a v a 2 s . c om * * @param toValidate * the object to validate */ public static void validateMultiTypeObject(MultiTypeObject toValidate) { MultiTypeObject base = buildMultiTypeObject(); Calendar calendar = Calendar.getInstance(); calendar.setTime(new Date()); Calendar calendarUnmarshal = Calendar.getInstance(); calendarUnmarshal.setTime(toValidate.getDateAttribute()); assertEquals(calendar.get(Calendar.YEAR), calendarUnmarshal.get(Calendar.YEAR)); assertEquals(calendar.get(Calendar.MONTH), calendarUnmarshal.get(Calendar.MONTH)); assertEquals(calendar.get(Calendar.DAY_OF_MONTH), calendarUnmarshal.get(Calendar.DAY_OF_MONTH)); LocalDate localDate = LocalDate.now(); assertEquals(localDate.getDayOfMonth(), toValidate.getLocalDateAttribute().getDayOfMonth()); assertEquals(localDate.getMonth(), toValidate.getLocalDateAttribute().getMonth()); assertEquals(localDate.getYear(), toValidate.getLocalDateAttribute().getYear()); LocalDateTime localDateTime = LocalDateTime.now(); assertEquals(localDateTime.getDayOfMonth(), toValidate.getLocalDateTimeAttribute().getDayOfMonth()); assertEquals(localDateTime.getMonth(), toValidate.getLocalDateTimeAttribute().getMonth()); assertEquals(localDateTime.getYear(), toValidate.getLocalDateTimeAttribute().getYear()); assertEquals(localDateTime.getHour(), toValidate.getLocalDateTimeAttribute().getHour()); /* it is possible to have an error below due the time of execution of the test */ assertEquals(localDateTime.getMinute(), toValidate.getLocalDateTimeAttribute().getMinute()); assertEquals(base.getStringAttribute(), toValidate.getStringAttribute()); assertEquals(base.getIntegerAttribute(), toValidate.getIntegerAttribute()); assertEquals(base.getDoubleAttribute(), toValidate.getDoubleAttribute()); assertEquals(base.getLongAttribute(), toValidate.getLongAttribute()); assertEquals(base.getBooleanAttribute(), toValidate.getBooleanAttribute()); assertEquals(base.getJob().getJobCode(), toValidate.getJob().getJobCode()); assertEquals(base.getJob().getJobFamily(), toValidate.getJob().getJobFamily()); assertEquals(base.getJob().getJobName(), toValidate.getJob().getJobName()); assertEquals(base.getIntegerPrimitiveAttribute(), toValidate.getIntegerPrimitiveAttribute()); assertEquals(base.getDoublePrimitiveAttribute(), toValidate.getDoublePrimitiveAttribute()); assertEquals(base.getLongPrimitiveAttribute(), toValidate.getLongPrimitiveAttribute()); assertEquals(base.isBooleanPrimitiveAttribute(), toValidate.isBooleanPrimitiveAttribute()); assertEquals(base.getAddressInfo().getAddress(), toValidate.getAddressInfo().getAddress()); assertEquals(base.getAddressInfo().getNumber(), toValidate.getAddressInfo().getNumber()); assertEquals(base.getAddressInfo().getCity(), toValidate.getAddressInfo().getCity()); assertEquals(base.getAddressInfo().getCityCode(), toValidate.getAddressInfo().getCityCode()); assertEquals(base.getAddressInfo().getCountry(), toValidate.getAddressInfo().getCountry()); assertEquals(base.getFloatAttribute(), toValidate.getFloatAttribute()); assertEquals(base.getFloatPrimitiveAttribute(), toValidate.getFloatPrimitiveAttribute()); assertEquals(base.getUnitFamily(), toValidate.getUnitFamily()); assertEquals(base.getBigDecimalAttribute(), toValidate.getBigDecimalAttribute()); assertEquals(base.getShortAttribute(), toValidate.getShortAttribute()); assertEquals(base.getShortPrimitiveAttribute(), toValidate.getShortPrimitiveAttribute()); // TODO add new validation below }
From source file:currency.converter.openexchangerate.OpenExchangeCurrencyConverter.java
/** * Retrieves latest exchange rates from <a href="https://openexchangerates.org">OpenExchangeRates</a> by using * REST template. Retrieved rates are stored as search history for the specific user. * /* ww w . j a v a2 s.c o m*/ * @param baseCurrency Base currency for exchange rates * @param amount Amount * * @return {@link CurrencyRateModel} * * @throws InvalidParameterException for invalid arguments */ public CurrencyRateModel getLatestCurrencyRates(String baseCurrency, double amount) throws InvalidParameterException { if (StringUtils.isNullOrEmpty(baseCurrency)) { baseCurrency = SupportedCurrencies.USD.name(); } if (amount <= ZERO) { amount = MINIMUM_AMOUNT; } StringBuilder builder = new StringBuilder(); String apiKey = configuration.getOpenExchangeApiKey(); builder.append("https://openexchangerates.org/api/latest.json?app_id=").append(apiKey).append("&base=") .append(baseCurrency); boolean isCommercialApi = configuration.isOpenExchangeCommercialLicense(); if (isCommercialApi) { builder.append(getTargetCurrencies(baseCurrency)); } logger.info("Latest rate API URL : " + builder.toString()); RestTemplate restTemplate = new RestTemplate(); CurrencyRateModel rates = restTemplate.getForObject(builder.toString(), CurrencyRateModel.class); multiplyAmount(rates, amount, baseCurrency); logger.info(rates.toString()); // save currency history String userName = userService.getLoggedInUserName(); saveExchangeRate(rates, baseCurrency, amount, LocalDate.now(), userName); return rates; }
From source file:org.zaproxy.gradle.UpdateAddOnZapVersionsEntries.java
public UpdateAddOnZapVersionsEntries() { ObjectFactory objects = getProject().getObjects(); this.fromFile = objects.fileProperty(); this.fromUrl = objects.property(String.class); this.into = getProject().getLayout().configurableFiles(); this.downloadUrl = objects.property(String.class); this.downloadUrl.set(fromUrl); this.checksumAlgorithm = objects.property(String.class); this.releaseDate = objects.property(LocalDate.class); this.releaseDate.set(LocalDate.now()); setGroup("ZAP"); setDescription("Updates ZapVersions.xml files with an add-on."); }
From source file:alfio.manager.AdminReservationManagerIntegrationTest.java
@Test public void testReserveFromExistingCategory() throws Exception { List<TicketCategoryModification> categories = Collections.singletonList(new TicketCategoryModification(null, "default", AVAILABLE_SEATS, new DateTimeModification(LocalDate.now(), LocalTime.now()), new DateTimeModification(LocalDate.now(), LocalTime.now()), DESCRIPTION, BigDecimal.TEN, false, "", false, null, null, null, null, null)); performExistingCategoryTest(categories, false, Collections.singletonList(1), false, true, 0, AVAILABLE_SEATS);/* ww w .ja v a 2 s. c o m*/ }