Example usage for java.time LocalDateTime minusDays

List of usage examples for java.time LocalDateTime minusDays

Introduction

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

Prototype

public LocalDateTime minusDays(long days) 

Source Link

Document

Returns a copy of this LocalDateTime with the specified number of days subtracted.

Usage

From source file:Main.java

public static void main(String[] args) {

    DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss'Z'");

    LocalDateTime now = LocalDateTime.now();
    LocalDateTime then = now.minusDays(7);

    System.out.println(String.format("Now:  %s\nThen: %s", now.format(format), then.format(format)));

}

From source file:Main.java

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

    LocalDateTime t = a.minusDays(100);

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

From source file:ch.algotrader.dao.marketData.TickDaoImpl.java

@Override
public List<Tick> findTicksBySecurityAndMaxDate(int limit, long securityId, Date maxDate, int intervalDays) {

    Validate.notNull(maxDate, "maxDate is null");

    LocalDateTime maxLocalDateTime = DateTimeLegacy.toLocalDateTime(maxDate);
    LocalDateTime minLocalDateTime = maxLocalDateTime.minusDays(intervalDays);
    return find("Tick.findTicksBySecurityAndMaxDate", limit, QueryType.BY_NAME,
            new NamedParam("securityId", securityId),
            new NamedParam("minDate", DateTimeLegacy.toLocalDateTime(minLocalDateTime)),
            new NamedParam("maxDate", DateTimeLegacy.toLocalDateTime(maxLocalDateTime)));
}

From source file:nu.yona.server.analysis.service.AnalysisEngineService_determineRelevantGoalsTest.java

@Before
public void setUp() {
    initMocks(this);

    setUpRepositoryMocks();/*from   ww w .  j av  a2s  . c o  m*/

    LocalDateTime yesterday = TimeUtil.utcNow().minusDays(1);
    LocalDateTime dayBeforeYesterday = yesterday.minusDays(1);
    gamblingGoal = BudgetGoal.createNoGoInstance(dayBeforeYesterday,
            ActivityCategory.createInstance(UUID.randomUUID(), usString("gambling"), false,
                    new HashSet<>(Arrays.asList("poker", "lotto")),
                    new HashSet<>(Arrays.asList("Poker App", "Lotto App")), usString("Descr")));
    newsGoal = BudgetGoal.createNoGoInstance(dayBeforeYesterday,
            ActivityCategory.createInstance(UUID.randomUUID(), usString("news"), false,
                    new HashSet<>(Arrays.asList("refdag", "bbc")), Collections.emptySet(), usString("Descr")));
    gamingGoal = BudgetGoal.createNoGoInstance(dayBeforeYesterday,
            ActivityCategory.createInstance(UUID.randomUUID(), usString("gaming"), false,
                    new HashSet<>(Arrays.asList("games")), Collections.emptySet(), usString("Descr")));
    socialGoal = TimeZoneGoal.createInstance(dayBeforeYesterday,
            ActivityCategory.createInstance(UUID.randomUUID(), usString("social"), false,
                    new HashSet<>(Arrays.asList("social")), Collections.emptySet(), usString("Descr")),
            Collections.emptyList());
    shoppingGoal = BudgetGoal
            .createInstance(dayBeforeYesterday,
                    ActivityCategory.createInstance(UUID.randomUUID(), usString("shopping"), false,
                            new HashSet<>(Arrays.asList("webshop")), Collections.emptySet(), usString("Descr")),
                    1);
    shoppingGoalHistoryItem = shoppingGoal.cloneAsHistoryItem(yesterday);

    // Set up UserAnonymized instance.
    MessageDestination anonMessageDestinationEntity = MessageDestination
            .createInstance(PublicKeyUtil.generateKeyPair().getPublic());
    Set<Goal> goals = new HashSet<>(
            Arrays.asList(gamblingGoal, gamingGoal, socialGoal, shoppingGoal, shoppingGoalHistoryItem));
    deviceAnonEntity = DeviceAnonymized.createInstance(0, operatingSystem, "Unknown", 0, Optional.empty());
    userAnonEntity = UserAnonymized.createInstance(anonMessageDestinationEntity, goals);
    userAnonEntity.addDeviceAnonymized(deviceAnonEntity);
    userAnonDto = UserAnonymizedDto.createInstance(userAnonEntity);
    deviceAnonDto = DeviceAnonymizedDto.createInstance(deviceAnonEntity);
    userAnonZoneId = userAnonDto.getTimeZone();
}

From source file:com.romeikat.datamessie.core.processing.task.documentProcessing.DocumentProcessorTest.java

@Override
protected Operation initDb() {
    final Project project1 = new Project(1, "Project1", false, false);
    final Source source1 = new Source(1, "Source1", "http://www.source1.de/", true);
    final Crawling crawling1 = new Crawling(1, project1.getId());
    final NamedEntity namedEntity = new NamedEntity(1, "NamedEntity");
    final LocalDateTime now = LocalDateTime.now();
    // Document1 with download success
    final LocalDateTime published1 = now.minusDays(1);
    final Document document1 = new Document(1, crawling1.getId(), source1.getId()).setTitle("Title1")
            .setUrl("http://www.document1.de/").setDescription("Description1").setPublished(published1)
            .setDownloaded(now).setState(DocumentProcessingState.DOWNLOADED).setStatusCode(200);
    final RawContent rawContent1 = new RawContent(document1.getId(), "RawContent1");
    final CleanedContent cleanedContent1 = new CleanedContent(document1.getId(), "Outdated CleanedContent1");
    final StemmedContent stemmedContent1 = new StemmedContent(document1.getId(), "Outdated StemmedContent1");
    final NamedEntityOccurrence namedEntityOccurrence1 = new NamedEntityOccurrence(1, namedEntity.getId(),
            namedEntity.getId(), NamedEntityType.MISC, 1, document1.getId());
    // Document2 with failed download
    final LocalDateTime published2 = now.minusDays(2);
    final Document document2 = new Document(2, crawling1.getId(), source1.getId()).setTitle("Title2")
            .setUrl("http://www.document2.de/").setDescription("Description2").setPublished(published2)
            .setDownloaded(now).setState(DocumentProcessingState.DOWNLOAD_ERROR).setStatusCode(400);
    final RawContent rawContent2 = new RawContent(document2.getId(), "Outdated RawContent2");
    final CleanedContent cleanedContent2 = new CleanedContent(document2.getId(), "Outdated CleanedContent2");
    final StemmedContent stemmedContent2 = new StemmedContent(document2.getId(), "Outdated StemmedContent3");
    final NamedEntityOccurrence namedEntityOccurrence2 = new NamedEntityOccurrence(2, namedEntity.getId(),
            namedEntity.getId(), NamedEntityType.MISC, 1, document2.getId());

    return sequenceOf(CommonOperations.DELETE_ALL_FOR_DATAMESSIE,
            sequenceOf(insertIntoProject(project1), insertIntoSource(source1), insertIntoCrawling(crawling1),
                    insertIntoNamedEntity(namedEntity), insertIntoDocument(document1),
                    insertIntoRawContent(rawContent1), insertIntoCleanedContent(cleanedContent1),
                    insertIntoStemmedContent(stemmedContent1),
                    insertIntoNamedEntityOccurrence(namedEntityOccurrence1), insertIntoDocument(document2),
                    insertIntoRawContent(rawContent2), insertIntoCleanedContent(cleanedContent2),
                    insertIntoStemmedContent(stemmedContent2),
                    insertIntoNamedEntityOccurrence(namedEntityOccurrence2)));
}

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

@Override
public void cleanupOldUserMessages() {
    int maxDays = Convert.toInteger(PropertiesManager.getValue(PropertiesManager.KEY_MESSAGE_KEEP_DAYS, "30"));

    LocalDateTime archiveTime = LocalDateTime.now();
    archiveTime = archiveTime.minusDays(maxDays);
    archiveTime = archiveTime.truncatedTo(ChronoUnit.DAYS);
    String deleteQuery = "updateDts < :maxUpdateDts AND activeStatus = :activeStatusParam";

    ZonedDateTime zdt = archiveTime.atZone(ZoneId.systemDefault());
    Date archiveDts = Date.from(zdt.toInstant());

    Map<String, Object> queryParams = new HashMap<>();
    queryParams.put("maxUpdateDts", archiveDts);
    queryParams.put("activeStatusParam", UserMessage.INACTIVE_STATUS);

    persistenceService.deleteByQuery(UserMessage.class, deleteQuery, queryParams);
}

From source file:ch.algotrader.service.LookupServiceImpl.java

private List<Tick> getTicksByMaxDate(final int limit, final long securityId, final Date maxDate,
        int intervalDays) {

    Validate.notNull(maxDate, "Max date is null");

    LocalDateTime maxLocalDateTime = DateTimeLegacy.toLocalDateTime(maxDate);
    LocalDateTime minLocalDateTime = maxLocalDateTime.minusDays(intervalDays);
    return this.genericDao.find(Tick.class, "Tick.findTicksBySecurityAndMaxDate", limit, QueryType.BY_NAME,
            new NamedParam("securityId", securityId),
            new NamedParam("minDate", DateTimeLegacy.toLocalDateTime(minLocalDateTime)),
            new NamedParam("maxDate", DateTimeLegacy.toLocalDateTime(maxLocalDateTime)));
}

From source file:no.kantega.openaksess.search.searchlog.action.ViewSearchLogAction.java

private void defaultSearch(Map<String, Object> model, int siteId) {
    LocalDateTime now = LocalDateTime.now();
    LocalDateTime thirtyMinutesAgo = now.minusMinutes(30);
    model.put("last30min", searchLogDao.getSearchCountForPeriod(thirtyMinutesAgo, now, siteId));

    LocalDateTime oneMonthAgo = now.minusDays(30);
    model.put("sumLastMonth", searchLogDao.getSearchCountForPeriod(oneMonthAgo, now, siteId));

    model.put("most", searchLogDao.getMostPopularQueries(siteId, 100));
    model.put("least", searchLogDao.getQueriesWithLeastHits(siteId, 100));
}

From source file:org.ambraproject.rhino.rest.controller.ArticleCrudController.java

/**
 * Calculate the date range using the specified rule. For example:
 *
 * <ul>//from   ww  w .j a va  2  s . com
 * <li>sinceRule=2y  - 2 years</li>
 * <li>sinceRule=5m  - 5 months</li>
 * <li>sinceRule=10d - 10 days</li>
 * <li>sinceRule=5h  - 5 hours</li>
 * <li>sinceRule=33  - 33 minutes</li>
 * </ul>
 *
 * The method will result in a {@link java.util.Map Map} containing the following keys:
 *
 * <ul>
 * <li><b>fromDate</b> - the starting date
 * <li><b>toDate</b> - the ending date, which will be the current system date (i.e. now())
 * </ul>
 *
 * @param sinceRule The rule to calculate the date range
 *
 * @return A {@link java.util.Map Map}
 */
public static final Map<String, LocalDateTime> calculateDateRange(String sinceRule) {
    if (StringUtils.isBlank(sinceRule)) {
        return ImmutableMap.of();
    }

    final String timeDesignation = StringUtils.right(sinceRule, 1);
    long timeDelta = 0;
    try {
        // Assume last character is NOT a letter (i.e. all characters are digits).
        timeDelta = Long.parseLong(sinceRule);
    } catch (NumberFormatException exception) {
        // If an exception, then last character MUST have been a letter,
        // so we now exclude the last character and re-try conversion.
        try {
            timeDelta = Long.parseLong(sinceRule.substring(0, sinceRule.length() - 1));
        } catch (NumberFormatException error) {
            log.warn("Failed to convert {} to a timeDelta/timeDesignation!", sinceRule);
            timeDelta = 0;
        }
    }

    if (timeDelta < 1) {
        return ImmutableMap.of();
    }

    final LocalDateTime toDate = LocalDateTime.now();
    final LocalDateTime fromDate;
    if (timeDesignation.equalsIgnoreCase("y")) {
        fromDate = toDate.minusYears(timeDelta);
    } else if (timeDesignation.equalsIgnoreCase("m")) {
        fromDate = toDate.minusMonths(timeDelta);
    } else if (timeDesignation.equalsIgnoreCase("d")) {
        fromDate = toDate.minusDays(timeDelta);
    } else if (timeDesignation.equalsIgnoreCase("h")) {
        fromDate = toDate.minus(timeDelta, ChronoUnit.HOURS);
    } else {
        fromDate = toDate.minus(timeDelta, ChronoUnit.MINUTES);
    }

    final ImmutableMap<String, LocalDateTime> dateRange = ImmutableMap.of(FROM_DATE, fromDate, TO_DATE, toDate);
    return dateRange;
}