Example usage for java.time.temporal ChronoUnit DAYS

List of usage examples for java.time.temporal ChronoUnit DAYS

Introduction

In this page you can find the example usage for java.time.temporal ChronoUnit DAYS.

Prototype

ChronoUnit DAYS

To view the source code for java.time.temporal ChronoUnit DAYS.

Click Source Link

Document

Unit that represents the concept of a day.

Usage

From source file:com.diversityarrays.update.UpdateDialog.java

public UpdateDialog(UpdateCheckRequest updateCheckRequest, UpdateCheckContext ctx, long exp_ms) {
    super(updateCheckRequest.owner, Msg.TITLE_UPDATE_CHECK(), ModalityType.APPLICATION_MODAL);

    this.updateCheckRequest = updateCheckRequest;
    this.updateCheckContext = ctx;

    setKDXploreUpdate(null);// w w  w  .  java 2 s. c o  m
    installUpdateAction.setEnabled(false);

    cardPanel.setBorder(new EmptyBorder(20, 20, 20, 20));

    progressBar.setIndeterminate(true);
    cardPanel.add(progressBar, CARD_PROGRESS);
    if (exp_ms > 0) {
        daysToGo = 1 + ChronoUnit.DAYS.between(new Date().toInstant(), new Date(exp_ms).toInstant());
        JPanel tmp = new JPanel(new BorderLayout());
        tmp.add(new JLabel(Msg.HTML_THIS_VERSION_EXPIRES_IN_N_DAYS((int) daysToGo)), BorderLayout.NORTH);
        tmp.add(messageLabel, BorderLayout.CENTER);
        cardPanel.add(tmp, CARD_MESSAGE);
    } else {
        daysToGo = 0;
        cardPanel.add(messageLabel, CARD_MESSAGE);
    }

    cardLayout.show(cardPanel, CARD_PROGRESS);

    Box buttons = Box.createHorizontalBox();
    buttons.add(new JButton(closeAction));
    buttons.add(new JButton(moreAction));
    if (RunMode.getRunMode().isDeveloper()) {
        buttons.add(new JButton(installUpdateAction));
    }
    buttons.add(Box.createHorizontalGlue());
    buttons.add(backupDatabaseButton);
    backupDatabaseButton.setVisible(false);
    backupDatabaseAction.setEnabled(updateCheckContext.canBackupDatabase());

    Container cp = getContentPane();

    cp.add(buttons, BorderLayout.SOUTH);
    cp.add(cardPanel, BorderLayout.CENTER);

    pack();

    GuiUtil.centreOnOwner(this);

    addWindowListener(new WindowAdapter() {
        @Override
        public void windowOpened(WindowEvent e) {
            removeWindowListener(this);
            checkForUpdates(updateCheckContext.getPrintStream());
        }
    });
}

From source file:alfio.model.Event.java

public boolean getSameDay() {
    return begin.truncatedTo(ChronoUnit.DAYS).equals(end.truncatedTo(ChronoUnit.DAYS));
}

From source file:com.zuoxiaolong.blog.cache.service.UserArticleServiceManager.java

/**
 * ????//w  w  w . j  ava 2  s .  co m
 *
 * @param map
 * @return
 */
public List<UserArticle> getTopRecommendArticlesByCategoryIdAndTime(Map<String, Object> map) {
    List<UserArticle> userArticles = userArticleService.getTopRecommendArticles(map);
    List<UserArticle> articles = userArticleService
            .getArticlesByCategoryId((Integer) map.get(QUERY_PARAMETER_CATEGORY_ID));
    if (CollectionUtils.isEmpty(userArticles) && !CollectionUtils.isEmpty(articles)) {
        //??DEFAULT_DAYS_BEFORE_PLUS
        map.put(QUERY_PARAMETER_TIME, Timestamp.valueOf(((Timestamp) map.get(QUERY_PARAMETER_TIME))
                .toLocalDateTime().minus(DEFAULT_DAYS_BEFORE_PLUS, ChronoUnit.DAYS)));
        userArticles = this.getTopRecommendArticlesByCategoryIdAndTime(map);
    }
    return userArticles;
}

From source file:com.zuoxiaolong.blog.service.impl.UserArticleServiceImpl.java

/**
 * ????/*from  www. j  ava  2s  .c om*/
 *
 * @param map
 * @return
 */
private List<UserArticle> getTopRecommendArticlesByCategoryIdAndTime(Map<String, Object> map) {
    List<UserArticle> userArticles = userArticleMapper.getTopRecommendArticles(map);
    List<UserArticle> articles = userArticleMapper
            .getArticlesByCategoryId((Integer) map.get(QUERY_PARAMETER_CATEGORY_ID));
    if (CollectionUtils.isEmpty(userArticles) && !CollectionUtils.isEmpty(articles)) {
        //??DEFAULT_DAYS_BEFORE_PLUS
        map.put(QUERY_PARAMETER_TIME, Timestamp.valueOf(((Timestamp) map.get(QUERY_PARAMETER_TIME))
                .toLocalDateTime().minus(DEFAULT_DAYS_BEFORE_PLUS, ChronoUnit.DAYS)));
        userArticles = this.getTopRecommendArticlesByCategoryIdAndTime(map);
    }
    return userArticles;
}

From source file:com.ikanow.aleph2.data_model.utils.TimeUtils.java

/** Returns the suffix of a time-based index given the grouping period
 * @param grouping_period - the grouping period
 * @param lowest_granularity/* w  ww. java  2  s . c  o m*/
 * @return the index suffix, ie added to the base index
 */
public static String getTimeBasedSuffix(final ChronoUnit grouping_period,
        final Optional<ChronoUnit> lowest_granularity) {
    return lowest_granularity
            .map(lg -> grouping_period.compareTo(lg) < 0 ? getTimeBasedSuffix(lg, Optional.empty()) : null)
            .orElse(Patterns.match(grouping_period).<String>andReturn()
                    .when(p -> ChronoUnit.SECONDS == p, __ -> "yyyy.MM.dd.HH:mm:ss")
                    .when(p -> ChronoUnit.MINUTES == p, __ -> "yyyy.MM.dd.HH:mm")
                    .when(p -> ChronoUnit.HOURS == p, __ -> "yyyy.MM.dd.HH")
                    .when(p -> ChronoUnit.DAYS == p, __ -> "yyyy.MM.dd")
                    .when(p -> ChronoUnit.WEEKS == p, __ -> "YYYY-ww") // (deliberately 'Y' (week-year) not 'y' since 'w' is week-of-year 
                    .when(p -> ChronoUnit.MONTHS == p, __ -> "yyyy.MM")
                    .when(p -> ChronoUnit.YEARS == p, __ -> "yyyy").otherwise(__ -> ""));
}

From source file:com.orange.cepheus.broker.persistence.RegistrationsRepositoryTest.java

@Test
public void removeRegistrationTest() throws URISyntaxException, RegistrationPersistenceException {
    RegisterContext registerContext = createRegisterContextTemperature();
    registerContext.setRegistrationId("12345");
    Registration registration = new Registration(Instant.now().plus(1, ChronoUnit.DAYS), registerContext);
    registrationsRepository.saveRegistration(registration);
    Assert.assertEquals(1, registrationsRepository.getAllRegistrations().size());
    registrationsRepository.removeRegistration("12345");
    Assert.assertEquals(0, registrationsRepository.getAllRegistrations().size());
}

From source file:de.siegmar.securetransfer.controller.SendController.java

/**
 * Process the send form./* w ww. j  a v  a2 s . co  m*/
 */
@PostMapping
public ModelAndView create(final HttpServletRequest req, final RedirectAttributes redirectAttributes)
        throws IOException, FileUploadException {

    if (!ServletFileUpload.isMultipartContent(req)) {
        throw new IllegalStateException("No multipart request!");
    }

    // Create encryptionKey and initialization vector (IV) to encrypt data
    final KeyIv encryptionKey = messageService.newEncryptionKey();

    // secret shared with receiver using the link - not stored in database
    final String linkSecret = messageService.newRandomId();

    final DataBinder binder = initBinder();

    final List<SecretFile> tmpFiles = handleStream(req, encryptionKey, binder);

    final EncryptMessageCommand command = (EncryptMessageCommand) binder.getTarget();
    final BindingResult errors = binder.getBindingResult();

    if (!errors.hasErrors() && command.getMessage() == null && (tmpFiles == null || tmpFiles.isEmpty())) {
        errors.reject(null, "Neither message nor files submitted");
    }

    if (errors.hasErrors()) {
        return new ModelAndView(FORM_SEND_MSG, binder.getBindingResult().getModel());
    }

    final String senderId = messageService.storeMessage(command.getMessage(), tmpFiles, encryptionKey,
            HashCode.fromString(linkSecret).asBytes(), command.getPassword(),
            Instant.now().plus(command.getExpirationDays(), ChronoUnit.DAYS));

    redirectAttributes.addFlashAttribute("messageSent", true).addFlashAttribute("message",
            command.getMessage());

    return new ModelAndView("redirect:/send/" + senderId).addObject("linkSecret", linkSecret);
}

From source file:com.orange.cepheus.broker.persistence.SubscriptionsRepositoryTest.java

@Test
public void removeSubscriptionTest() throws URISyntaxException, SubscriptionPersistenceException {
    SubscribeContext subscribeContext = createSubscribeContextTemperature();
    Subscription subscription = new Subscription("12345", Instant.now().plus(1, ChronoUnit.DAYS),
            subscribeContext);/*from   w w  w . j  av a2s . c  om*/
    subscriptionsRepository.saveSubscription(subscription);
    Assert.assertEquals(1, subscriptionsRepository.getAllSubscriptions().size());
    subscriptionsRepository.removeSubscription("12345");
    Assert.assertEquals(0, subscriptionsRepository.getAllSubscriptions().size());
}

From source file:com.ikanow.aleph2.core.shared.utils.TimeSliceDirUtils.java

/** Low level util because java8 time "plus" is odd
 * @param to_adjust/*from   www .  j a va  2  s  . c o  m*/
 * @param increment
 * @return
 */
private static Date adjustTime(Date to_adjust, ChronoUnit increment) {
    return Patterns.match(increment).<Date>andReturn()
            .when(t -> t == ChronoUnit.SECONDS, __ -> DateUtils.addSeconds(to_adjust, 1))
            .when(t -> t == ChronoUnit.MINUTES, __ -> DateUtils.addMinutes(to_adjust, 1))
            .when(t -> t == ChronoUnit.HOURS, __ -> DateUtils.addHours(to_adjust, 1))
            .when(t -> t == ChronoUnit.DAYS, __ -> DateUtils.addDays(to_adjust, 1))
            .when(t -> t == ChronoUnit.WEEKS, __ -> DateUtils.addWeeks(to_adjust, 1))
            .when(t -> t == ChronoUnit.MONTHS, __ -> DateUtils.addMonths(to_adjust, 1))
            .when(t -> t == ChronoUnit.YEARS, __ -> DateUtils.addYears(to_adjust, 1)).otherwiseAssert();
}

From source file:com.netflix.genie.web.tasks.node.DiskCleanupTaskTest.java

/**
 * Make sure we can run successfully when runAsUser is false for the system.
 *
 * @throws IOException    on error//from  ww  w . ja  v a2 s  . co  m
 * @throws GenieException on error
 */
@Test
public void canRunWithoutSudo() throws IOException, GenieException {
    final JobsProperties jobsProperties = JobsProperties.getJobsPropertiesDefaults();
    jobsProperties.getUsers().setRunAsUserEnabled(false);

    // Create some random junk file that should be ignored
    this.tmpJobDir.newFile(UUID.randomUUID().toString());
    final DiskCleanupProperties properties = new DiskCleanupProperties();
    final Instant threshold = TaskUtils.getMidnightUTC().minus(properties.getRetention(), ChronoUnit.DAYS);

    final String job1Id = UUID.randomUUID().toString();
    final String job2Id = UUID.randomUUID().toString();
    final String job3Id = UUID.randomUUID().toString();
    final String job4Id = UUID.randomUUID().toString();
    final String job5Id = UUID.randomUUID().toString();

    final Job job1 = Mockito.mock(Job.class);
    Mockito.when(job1.getStatus()).thenReturn(JobStatus.INIT);
    final Job job2 = Mockito.mock(Job.class);
    Mockito.when(job2.getStatus()).thenReturn(JobStatus.RUNNING);
    final Job job3 = Mockito.mock(Job.class);
    Mockito.when(job3.getStatus()).thenReturn(JobStatus.SUCCEEDED);
    Mockito.when(job3.getFinished()).thenReturn(Optional.of(threshold.minus(1, ChronoUnit.MILLIS)));
    final Job job4 = Mockito.mock(Job.class);
    Mockito.when(job4.getStatus()).thenReturn(JobStatus.FAILED);
    Mockito.when(job4.getFinished()).thenReturn(Optional.of(threshold));

    this.createJobDir(job1Id);
    this.createJobDir(job2Id);
    this.createJobDir(job3Id);
    this.createJobDir(job4Id);
    this.createJobDir(job5Id);

    final TaskScheduler scheduler = Mockito.mock(TaskScheduler.class);
    final Resource jobDir = Mockito.mock(Resource.class);
    Mockito.when(jobDir.exists()).thenReturn(true);
    Mockito.when(jobDir.getFile()).thenReturn(this.tmpJobDir.getRoot());
    final JobSearchService jobSearchService = Mockito.mock(JobSearchService.class);

    Mockito.when(jobSearchService.getJob(job1Id)).thenReturn(job1);
    Mockito.when(jobSearchService.getJob(job2Id)).thenReturn(job2);
    Mockito.when(jobSearchService.getJob(job3Id)).thenReturn(job3);
    Mockito.when(jobSearchService.getJob(job4Id)).thenReturn(job4);
    Mockito.when(jobSearchService.getJob(job5Id)).thenThrow(new GenieServerException("blah"));

    final DiskCleanupTask task = new DiskCleanupTask(properties, scheduler, jobDir, jobSearchService,
            jobsProperties, Mockito.mock(Executor.class), new SimpleMeterRegistry());
    task.run();
    Assert.assertTrue(new File(jobDir.getFile(), job1Id).exists());
    Assert.assertTrue(new File(jobDir.getFile(), job2Id).exists());
    Assert.assertFalse(new File(jobDir.getFile(), job3Id).exists());
    Assert.assertTrue(new File(jobDir.getFile(), job4Id).exists());
    Assert.assertTrue(new File(jobDir.getFile(), job5Id).exists());
}