Example usage for java.time LocalDateTime plusMinutes

List of usage examples for java.time LocalDateTime plusMinutes

Introduction

In this page you can find the example usage for java.time LocalDateTime plusMinutes.

Prototype

public LocalDateTime plusMinutes(long minutes) 

Source Link

Document

Returns a copy of this LocalDateTime with the specified number of minutes added.

Usage

From source file:Main.java

public static void main(String[] args) {
    LocalDateTime a = LocalDateTime.of(2014, 6, 30, 12, 00);

    LocalDateTime t = a.plusMinutes(100);

    System.out.println(t);/*from  ww  w . j  a  va  2 s  . c  o  m*/
}

From source file:io.mandrel.metrics.MetricsService.java

public Timeserie serie(String name) {
    Timeserie serie = metricsRepository.serie(name);

    LocalDateTime now = LocalDateTime.now();
    LocalDateTime minus4Hours = now.withMinute(0).withSecond(0).withNano(0).minusHours(4);

    LocalDateTime firstTime = CollectionUtils.isNotEmpty(serie) && serie.first() != null
            && serie.first().getTime().isBefore(minus4Hours) ? serie.first().getTime() : minus4Hours;
    LocalDateTime lastTime = now;

    Set<Data> results = LongStream.range(0, Duration.between(firstTime, lastTime).toMinutes())
            .mapToObj(minutes -> firstTime.plusMinutes(minutes)).map(time -> Data.of(time, Long.valueOf(0)))
            .collect(TreeSet::new, TreeSet::add, (left, right) -> {
                left.addAll(right);//from ww w .  j  a  v  a2  s .c  om
            });

    Timeserie serieWithBlank = new Timeserie();
    serieWithBlank.addAll(results);
    serieWithBlank.addAll(serie);

    return serieWithBlank;
}

From source file:io.mandrel.metrics.impl.MongoMetricsRepository.java

@Override
public Timeserie serie(String name) {
    Set<Data> results = StreamSupport.stream(timeseries.find(Filters.eq("type", name))
            .sort(Sorts.ascending("timestamp_hour")).limit(3).map(doc -> {
                LocalDateTime hour = LocalDateTime
                        .ofEpochSecond(((Date) doc.get("timestamp_hour")).getTime() / 1000, 0, ZoneOffset.UTC);
                Map<String, Long> values = (Map<String, Long>) doc.get("values");

                List<Data> mapped = values.entrySet().stream()
                        .map(elt -> Data.of(hour.plusMinutes(Long.valueOf(elt.getKey())), elt.getValue()))
                        .collect(Collectors.toList());
                return mapped;
            }).spliterator(), true).flatMap(elts -> elts.stream())
            .collect(TreeSet::new, Set::add, (left, right) -> {
                left.addAll(right);//from w  w w  . j  a va 2  s  .  c  om
            });

    Timeserie timeserie = new Timeserie();
    timeserie.addAll(results);
    return timeserie;
}

From source file:nu.yona.server.device.service.DeviceServiceTestConfiguration.java

private Activity makeActivity(LocalDateTime startTime, ActivityData activityData, UserDevice device) {
    LocalDateTime activityStartTime = startTime.minusMinutes(activityData.minutesAgo);
    return activityRepository.save(Activity.createInstance(device.getDeviceAnonymized(),
            ZoneId.of("Europe/Amsterdam"), activityStartTime,
            activityStartTime.plusMinutes(activityData.durationMinutes), Optional.of(activityData.app)));
}

From source file:edu.usu.sdl.openstorefront.service.ComponentServiceImpl.java

@Override
public void processComponentIntegration(String componentId, String integrationConfigId) {
    ComponentIntegration integrationExample = new ComponentIntegration();
    integrationExample.setActiveStatus(ComponentIntegration.ACTIVE_STATUS);
    integrationExample.setComponentId(componentId);
    ComponentIntegration integration = persistenceService.queryOneByExample(ComponentIntegration.class,
            integrationExample);//  w w w  .j  a va2s  . c  o  m
    if (integration != null) {

        boolean run = true;
        if (RunStatus.WORKING.equals(integration.getStatus())) {
            //check for override
            String overrideTime = PropertiesManager.getValue(PropertiesManager.KEY_JOB_WORKING_STATE_OVERRIDE,
                    "30");
            if (integration.getLastStartTime() != null) {
                LocalDateTime maxLocalDateTime = LocalDateTime
                        .ofInstant(integration.getLastStartTime().toInstant(), ZoneId.systemDefault());
                maxLocalDateTime.plusMinutes(Convert.toLong(overrideTime));
                if (maxLocalDateTime.compareTo(LocalDateTime.now()) <= 0) {
                    log.log(Level.FINE, "Overriding the working state...assume it was stuck.");
                    run = true;
                } else {
                    run = false;
                }
            } else {
                throw new OpenStorefrontRuntimeException("Missing Last Start time.  Data is corrupt.",
                        "Delete the job (Integration) and recreate it.", ErrorTypeCode.INTEGRATION);
            }
        }

        if (run) {
            Component component = persistenceService.findById(Component.class, integration.getComponentId());
            ComponentIntegration liveIntegration = persistenceService.findById(ComponentIntegration.class,
                    integration.getComponentId());

            log.log(Level.FINE, MessageFormat.format("Processing Integration for: {0}", component.getName()));

            liveIntegration.setStatus(RunStatus.WORKING);
            liveIntegration.setLastStartTime(TimeUtil.currentDate());
            liveIntegration.setUpdateDts(TimeUtil.currentDate());
            liveIntegration.setUpdateUser(OpenStorefrontConstant.SYSTEM_USER);
            persistenceService.persist(liveIntegration);

            ComponentIntegrationConfig integrationConfigExample = new ComponentIntegrationConfig();
            integrationConfigExample.setActiveStatus(ComponentIntegrationConfig.ACTIVE_STATUS);
            integrationConfigExample.setComponentId(componentId);
            integrationConfigExample.setIntegrationConfigId(integrationConfigId);

            List<ComponentIntegrationConfig> integrationConfigs = persistenceService
                    .queryByExample(ComponentIntegrationConfig.class, integrationConfigExample);
            boolean errorConfig = false;
            if (integrationConfigs.isEmpty() == false) {
                for (ComponentIntegrationConfig integrationConfig : integrationConfigs) {
                    ComponentIntegrationConfig liveConfig = persistenceService.findById(
                            ComponentIntegrationConfig.class, integrationConfig.getIntegrationConfigId());
                    try {
                        log.log(Level.FINE,
                                MessageFormat.format("Working on {1} Configuration for Integration for: {0}",
                                        component.getName(), integrationConfig.getIntegrationType()));

                        liveConfig.setStatus(RunStatus.WORKING);
                        liveConfig.setLastStartTime(TimeUtil.currentDate());
                        liveConfig.setUpdateDts(TimeUtil.currentDate());
                        liveConfig.setUpdateUser(OpenStorefrontConstant.SYSTEM_USER);
                        persistenceService.persist(liveConfig);

                        BaseIntegrationHandler baseIntegrationHandler = BaseIntegrationHandler
                                .getIntegrationHandler(integrationConfig);
                        if (baseIntegrationHandler != null) {
                            baseIntegrationHandler.processConfig();
                        } else {
                            throw new OpenStorefrontRuntimeException(
                                    "Intergration handler not supported for "
                                            + integrationConfig.getIntegrationType(),
                                    "Add handler", ErrorTypeCode.INTEGRATION);
                        }

                        liveConfig.setStatus(RunStatus.COMPLETE);
                        liveConfig.setLastEndTime(TimeUtil.currentDate());
                        liveConfig.setUpdateDts(TimeUtil.currentDate());
                        liveConfig.setUpdateUser(OpenStorefrontConstant.SYSTEM_USER);
                        persistenceService.persist(liveConfig);

                        log.log(Level.FINE,
                                MessageFormat.format("Completed {1} Configuration for Integration for: {0}",
                                        component.getName(), integrationConfig.getIntegrationType()));
                    } catch (Exception e) {
                        errorConfig = true;
                        //This is a critical loop
                        ErrorInfo errorInfo = new ErrorInfo(e, null);
                        SystemErrorModel errorModel = getSystemService().generateErrorTicket(errorInfo);

                        //put in fail state
                        liveConfig.setStatus(RunStatus.ERROR);
                        liveConfig.setErrorMessage(errorModel.getMessage());
                        liveConfig.setErrorTicketNumber(errorModel.getErrorTicketNumber());
                        liveConfig.setLastEndTime(TimeUtil.currentDate());
                        liveConfig.setUpdateDts(TimeUtil.currentDate());
                        liveConfig.setUpdateUser(OpenStorefrontConstant.SYSTEM_USER);
                        persistenceService.persist(liveConfig);

                        log.log(Level.FINE,
                                MessageFormat.format("Failed on {1} Configuration for Integration for: {0}",
                                        component.getName(), integrationConfig.getIntegrationType()),
                                e);
                    }
                }
            } else {
                log.log(Level.WARNING,
                        MessageFormat.format(
                                "No Active Integration configs for: {0} (Integration is doing nothing)",
                                component.getName()));
            }

            if (errorConfig) {
                liveIntegration.setStatus(RunStatus.ERROR);
            } else {
                liveIntegration.setStatus(RunStatus.COMPLETE);
            }
            liveIntegration.setLastEndTime(TimeUtil.currentDate());
            liveIntegration.setUpdateDts(TimeUtil.currentDate());
            liveIntegration.setUpdateUser(OpenStorefrontConstant.SYSTEM_USER);
            persistenceService.persist(liveIntegration);

            log.log(Level.FINE, MessageFormat.format("Completed Integration for: {0}", component.getName()));
        } else {
            log.log(Level.FINE, MessageFormat.format(
                    "Not time to run integration or the system is currently working on the integration. Component Id: {0}",
                    componentId));
        }
    } else {
        log.log(Level.WARNING, MessageFormat
                .format("There is no active integration for this component. Id: {0}", componentId));
    }
}

From source file:org.jbb.security.impl.lockout.DefaultMemberLockoutService.java

private LocalDateTime calculateLockExpireDate() {
    LocalDateTime localDateTime = DateTimeProvider.now();
    return localDateTime.plusMinutes(properties.lockoutDurationMinutes());
}

From source file:tech.tablesaw.filters.SearchPerformanceTest.java

private static void generateData(int observationCount, LocalDateTime dateTime, Table table) {
    // createFromCsv pools of random values

    RandomStringGenerator generator = new RandomStringGenerator.Builder().withinRange(32, 127).build();

    while (concepts.size() <= CONCEPT_COUNT) {
        concepts.add(generator.generate(30));
    }/*from   ww  w  .java2  s  .  com*/

    while (dates.size() <= numberOfRecordsInTable) {
        dates.add(PackedLocalDateTime.pack(dateTime.plusMinutes(1)));
    }

    DateTimeColumn dateColumn = table.dateTimeColumn("date");
    StringColumn conceptColumn = table.stringColumn("concept");
    DoubleColumn lowValues = table.doubleColumn("lowValue");
    DoubleColumn highValues = table.doubleColumn("highValue");

    // sample from the pools to write the data
    for (int i = 0; i < observationCount; i++) {
        dateColumn.appendInternal(dates.getLong(i));
        conceptColumn.append(concepts.get(RandomUtils.nextInt(0, concepts.size())));
        lowValues.append(RandomUtils.nextDouble(0, 1_000_000));
        highValues.append(RandomUtils.nextDouble(0, 1_000_000));
    }
}