Example usage for java.time ZonedDateTime now

List of usage examples for java.time ZonedDateTime now

Introduction

In this page you can find the example usage for java.time ZonedDateTime now.

Prototype

public static ZonedDateTime now(Clock clock) 

Source Link

Document

Obtains the current date-time from the specified clock.

Usage

From source file:alfio.model.modification.EventWithStatistics.java

public boolean isExpired() {
    return ZonedDateTime.now(event.getZoneId()).truncatedTo(ChronoUnit.DAYS)
            .isAfter(event.getEnd().truncatedTo(ChronoUnit.DAYS));
}

From source file:io.stallion.utils.GeneralUtils.java

@Deprecated
public static ZonedDateTime utcNow() {
    return ZonedDateTime.now(UTC);
}

From source file:io.stallion.utils.GeneralUtils.java

@Deprecated
public static ZonedDateTime localNow() {
    return ZonedDateTime.now(Context.getSettings().getTimeZoneId());
}

From source file:org.openlmis.fulfillment.web.ShipmentControllerIntegrationTest.java

@Before
public void setUp() {
    when(dateHelper.getCurrentDateTimeWithSystemZone()).thenReturn(ZonedDateTime.now(ZoneId.of("UTC")));
    when(authenticationHelper.getCurrentUser()).thenReturn(new UserDto(userId));

    generateShipment();/*from  w  ww  .  jav a2  s .co  m*/

    when(shipmentRepository.findOne(shipmentDtoExpected.getId())).thenReturn(shipment);
    when(shipmentRepository.save(any(Shipment.class))).thenAnswer(new SaveAnswer<>());
    when(orderRepository.findOne(shipmentDtoExpected.getOrder().getId())).thenReturn(order);
    when(orderRepository.save(any(Order.class))).thenAnswer(new SaveAnswer<>());

    when(order.canBeFulfilled()).thenReturn(true);
}

From source file:alfio.manager.plugin.PluginManager.java

@Override
public void onApplicationEvent(ContextRefreshedEvent event) {
    eventRepository.findAll().stream().filter(e -> e.getEnd().isBefore(ZonedDateTime.now(e.getZoneId())))
            .forEach(this::installPlugins);
}

From source file:nu.yona.server.batch.jobs.ActivityAggregationBatchJob.java

@Bean(name = "activityAggregationJobWeekActivityReader", destroyMethod = "")
@StepScope//from  w w w .j a  v a  2  s .c o  m
public ItemReader<Long> weekActivityReader() {
    return intervalActivityIdReader(
            Date.valueOf(TimeUtil.getStartOfWeek(DEFAULT_TIME_ZONE, ZonedDateTime.now(DEFAULT_TIME_ZONE))
                    .minusWeeks(1).toLocalDate()),
            WeekActivity.class, WEEK_ACTIVITY_CHUNK_SIZE);
}

From source file:alfio.controller.form.ReservationForm.java

public Optional<Pair<List<TicketReservationWithOptionalCodeModification>, List<ASReservationWithOptionalCodeModification>>> validate(
        Errors bindingResult, TicketReservationManager tickReservationManager,
        AdditionalServiceRepository additionalServiceRepository, EventManager eventManager, Event event) {
    int selectionCount = ticketSelectionCount();

    if (selectionCount <= 0) {
        bindingResult.reject(ErrorsCode.STEP_1_SELECT_AT_LEAST_ONE);
        return Optional.empty();
    }//from  w ww  .  ja va  2s .  co m

    List<Pair<TicketReservationModification, Integer>> maxTicketsByTicketReservation = selected().stream()
            .map(r -> Pair.of(r, tickReservationManager.maxAmountOfTicketsForCategory(event.getOrganizationId(),
                    event.getId(), r.getTicketCategoryId())))
            .collect(toList());
    Optional<Pair<TicketReservationModification, Integer>> error = maxTicketsByTicketReservation.stream()
            .filter(p -> p.getKey().getAmount() > p.getValue()).findAny();

    if (error.isPresent()) {
        bindingResult.reject(ErrorsCode.STEP_1_OVER_MAXIMUM, new Object[] { error.get().getValue() }, null);
        return Optional.empty();
    }

    final List<TicketReservationModification> categories = selected();
    final List<AdditionalServiceReservationModification> additionalServices = selectedAdditionalServices();

    final boolean validCategorySelection = categories.stream().allMatch(c -> {
        TicketCategory tc = eventManager.getTicketCategoryById(c.getTicketCategoryId(), event.getId());
        return OptionalWrapper.optionally(() -> eventManager.findEventByTicketCategory(tc)).isPresent();
    });

    final boolean validAdditionalServiceSelected = additionalServices.stream().allMatch(asm -> {
        AdditionalService as = eventManager.getAdditionalServiceById(asm.getAdditionalServiceId(),
                event.getId());
        ZonedDateTime now = ZonedDateTime.now(event.getZoneId());
        return as.getInception(event.getZoneId()).isBefore(now)
                && as.getExpiration(event.getZoneId()).isAfter(now) && asm.getQuantity() >= 0
                && ((as.isFixPrice() && asm.isQuantityValid(as, selectionCount)) || (!as.isFixPrice()
                        && asm.getAmount() != null && asm.getAmount().compareTo(BigDecimal.ZERO) >= 0))
                && OptionalWrapper.optionally(() -> eventManager.findEventByAdditionalService(as)).isPresent();
    });

    if (!validCategorySelection || !validAdditionalServiceSelected) {
        bindingResult.reject(ErrorsCode.STEP_1_TICKET_CATEGORY_MUST_BE_SALEABLE);
        return Optional.empty();
    }

    List<TicketReservationWithOptionalCodeModification> res = new ArrayList<>();
    //
    Optional<SpecialPrice> specialCode = Optional.ofNullable(StringUtils.trimToNull(promoCode))
            .flatMap((trimmedCode) -> tickReservationManager.getSpecialPriceByCode(trimmedCode));
    //
    final ZonedDateTime now = ZonedDateTime.now(event.getZoneId());
    maxTicketsByTicketReservation.forEach((pair) -> validateCategory(bindingResult, tickReservationManager,
            eventManager, event, pair.getRight(), res, specialCode, now, pair.getLeft()));
    return bindingResult.hasErrors() ? Optional.empty()
            : Optional.of(Pair.of(res,
                    additionalServices.stream()
                            .map(as -> new ASReservationWithOptionalCodeModification(as, specialCode))
                            .collect(Collectors.toList())));
}

From source file:org.silverpeas.core.webapi.reminder.ReminderResource.java

/**
 * Gets the identifier list of possible of durations.
 * <p>//w w  w .j a  v a  2s.  com
 * An identifier of a duration is the concatenation about the duration value and the duration
 * unit ({@link TimeUnit}).<br>
 * {@code 15MINUTE} for example.
 * </p>
 * @return a filled list if any, or an empty one if no trigger can be scheduled.
 * @see WebProcess#execute()
 */
@Path("possibledurations/{property}")
@GET
@Produces(MediaType.APPLICATION_JSON)
@SuppressWarnings("ConstantConditions")
public List<String> getPossibleDurations(@PathParam("property") final String contributionProperty) {
    if (getSessionVolatileResourceCacheService().contains(localId, componentInstanceId)) {
        return getPossibleReminders().map(DURATION_IDS).collect(Collectors.toList());
    }
    final ContributionModel model = getContribution().getModel();
    final ZoneId userZoneId = getUserPreferences().getZoneId();
    final ZoneId platformZoneId = ZoneId.systemDefault();
    final Mutable<Boolean> lastMatchOk = Mutable.of(true);
    return getPossibleReminders().filter(r -> {
        if (lastMatchOk.is(false)) {
            return false;
        }
        final ZonedDateTime from = ZonedDateTime.now(userZoneId).plus(r.getLeft(), r.getRight().toChronoUnit());
        final ZonedDateTime dateReference = model.filterByType(contributionProperty, from)
                .matchFirst(Date.class::isAssignableFrom,
                        d -> ZonedDateTime.ofInstant(((Date) d).toInstant(), platformZoneId))
                .matchFirst(OffsetDateTime.class::equals,
                        d -> ((OffsetDateTime) d).atZoneSameInstant(platformZoneId))
                .matchFirst(LocalDate.class::equals,
                        d -> ((LocalDate) d).atStartOfDay(userZoneId).withZoneSameInstant(platformZoneId))
                .matchFirst(LocalDateTime.class::equals, d -> ((LocalDateTime) d).atZone(platformZoneId))
                .matchFirst(ZonedDateTime.class::equals,
                        d -> ((ZonedDateTime) d).withZoneSameInstant(platformZoneId))
                .result().orElse(null);
        lastMatchOk.set(dateReference != null);
        return lastMatchOk.get();
    }).map(DURATION_IDS).collect(Collectors.toList());
}

From source file:com.match_tracker.twitter.TwitterSearch.java

protected ZonedDateTime calculatePostedTimeEnd(ZonedDateTime endTime) {
    ZonedDateTime postedTimeEnd = ZonedDateTime.now(ZoneOffset.UTC).minusSeconds(SEARCH_END_DELAY_SECONDS);
    if (postedTimeEnd.isAfter(endTime)) {
        postedTimeEnd = endTime;/* w ww. ja  va 2  s  .  c om*/
    }

    return postedTimeEnd;
}

From source file:objective.taskboard.controller.FollowUpController.java

private String templateDate(Optional<LocalDate> date, ZoneId timezone) {
    return date.map(d -> ZonedDateTime.of(d, LocalTime.MIDNIGHT, timezone)).orElse(ZonedDateTime.now(timezone))
            .format(formatter);// w w w. j a v a 2s. co  m
}