List of usage examples for java.time Period ofDays
public static Period ofDays(int days)
From source file:Main.java
public static void main(String[] args) { LocalTime localTime = LocalTime.of(11, 20, 50); System.out.println(localTime.plus(3, ChronoUnit.HOURS)); System.out.println(localTime.plus(Duration.ofDays(3))); //11:20:50 try {//w ww . j a v a 2 s.co m System.out.println(localTime.plus(Period.ofDays(3))); } catch (UnsupportedTemporalTypeException e) { e.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) { ZonedDateTime _130AMChicagoTime = ZonedDateTime.of(2014, 3, 9, 1, 30, 0, 0, ZoneId.of("America/Chicago")); System.out.println(_130AMChicagoTime.plusHours(3)); System.out.println(_130AMChicagoTime.plus(Duration.ofHours(3))); System.out.println(_130AMChicagoTime.plus(Duration.ofDays(2))); System.out.println(_130AMChicagoTime.plus(Period.ofDays(2))); }
From source file:org.apache.archiva.repository.maven2.MavenRepositoryProvider.java
@Override public void updateManagedInstance(EditableManagedRepository repo, ManagedRepositoryConfiguration cfg) throws RepositoryException { try {/*from w ww. j a va2 s. c o m*/ repo.setLocation(getURIFromString(cfg.getLocation())); } catch (UnsupportedURIException e) { throw new RepositoryException("The location entry is not a valid uri: " + cfg.getLocation()); } setBaseConfig(repo, cfg); Path repoDir = repo.getLocalPath(); if (!Files.exists(repoDir)) { log.debug("Creating repo directory {}", repoDir); try { Files.createDirectories(repoDir); } catch (IOException e) { log.error("Could not create directory {} for repository {}", repo.getLocalPath(), repo.getId(), e); throw new RepositoryException("Could not create directory for repository " + repo.getLocalPath()); } } repo.setSchedulingDefinition(cfg.getRefreshCronExpression()); repo.setBlocksRedeployment(cfg.isBlockRedeployments()); repo.setScanned(cfg.isScanned()); if (cfg.isReleases()) { repo.addActiveReleaseScheme(ReleaseScheme.RELEASE); } if (cfg.isSnapshots()) { repo.addActiveReleaseScheme(ReleaseScheme.SNAPSHOT); } StagingRepositoryFeature stagingRepositoryFeature = repo.getFeature(StagingRepositoryFeature.class).get(); stagingRepositoryFeature.setStageRepoNeeded(cfg.isStageRepoNeeded()); IndexCreationFeature indexCreationFeature = repo.getFeature(IndexCreationFeature.class).get(); indexCreationFeature.setSkipPackedIndexCreation(cfg.isSkipPackedIndexCreation()); indexCreationFeature.setIndexPath(getURIFromString(cfg.getIndexDir())); indexCreationFeature.setPackedIndexPath(getURIFromString(cfg.getPackedIndexDir())); /* -> Should be created by MavenIndexProvider Path indexPath; if (indexCreationFeature.getIndexPath().getScheme() == null) { indexPath = Paths.get(indexCreationFeature.getIndexPath().getPath()); } else { indexPath = Paths.get(indexCreationFeature.getIndexPath()); } Path absoluteIndexPath; if (indexPath.isAbsolute()) { absoluteIndexPath = indexPath; } else { absoluteIndexPath = PathUtil.getPathFromUri(repo.getLocation()).resolve(indexCreationFeature.getIndexPath().getPath()); } try { Files.createDirectories(absoluteIndexPath); } catch (IOException e) { log.error("Could not create index directory {}", absoluteIndexPath); throw new RepositoryException("Could not create index directory " + absoluteIndexPath); }*/ ArtifactCleanupFeature artifactCleanupFeature = repo.getFeature(ArtifactCleanupFeature.class).get(); artifactCleanupFeature.setDeleteReleasedSnapshots(cfg.isDeleteReleasedSnapshots()); artifactCleanupFeature.setRetentionCount(cfg.getRetentionCount()); artifactCleanupFeature.setRetentionPeriod(Period.ofDays(cfg.getRetentionPeriod())); }
From source file:org.apache.solr.util.UtilsToolTest.java
@Test public void testRemoveOldSolrLogs() throws Exception { String[] args = { "utils", "-remove_old_solr_logs", "1", "-l", dir.toString() }; assertEquals(files.size(), fileCount()); assertEquals(0, runTool(args));/* w w w . ja va 2 s . c o m*/ assertEquals(files.size(), fileCount()); // No logs older than 1 day Files.setLastModifiedTime(dir.resolve("solr_log_20160102"), FileTime.from(Instant.now().minus(Period.ofDays(2)))); assertEquals(0, runTool(args)); assertEquals(files.size() - 1, fileCount()); // One logs older than 1 day Files.setLastModifiedTime(dir.resolve("solr_log_20160304"), FileTime.from(Instant.now().minus(Period.ofDays(3)))); assertEquals(0, runTool(args)); assertEquals(files.size() - 2, fileCount()); // Two logs older than 1 day }