List of usage examples for java.util.concurrent TimeUnit DAYS
TimeUnit DAYS
To view the source code for java.util.concurrent TimeUnit DAYS.
Click Source Link
From source file:Main.java
public static int daysBetween(Date date1, Date date2) { long timespan = date2.getTime() - date1.getTime(); return (int) TimeUnit.DAYS.convert(timespan, TimeUnit.MILLISECONDS); }
From source file:Main.java
public static TimeUnit convert(ChronoUnit tu) { if (tu == null) { return null; }//from w w w . j a va 2 s. c o m switch (tu) { case DAYS: return TimeUnit.DAYS; case HOURS: return TimeUnit.HOURS; case MINUTES: return TimeUnit.MINUTES; case SECONDS: return TimeUnit.SECONDS; case MICROS: return TimeUnit.MICROSECONDS; case MILLIS: return TimeUnit.MILLISECONDS; case NANOS: return TimeUnit.NANOSECONDS; default: //TODO support the rest throw new UnsupportedOperationException("Man, use a real temporal unit"); } }
From source file:Main.java
/** * Get the number of days between start and end as a string. *//* w w w .j a v a2 s . com*/ public static String formatDurationInDays(Date start, Date end) { if (start != null && end != null) { // TODO(emmanuel): maybe there is a way to do this that accounts for current locale? long days = getDateDiff(start, end, TimeUnit.DAYS); // Add 1 since the trip starts at day zero. return (days + 1) + "d"; } return ""; }
From source file:Main.java
/** * Convert a millisecond duration to a string format * * @param millis A duration to convert to a string form * @return A string of the form "X Days Y Hours Z Minutes A Seconds". *//* w w w .jav a2 s . c o m*/ public static String getDurationBreakdown(long millis) { if (millis < 0) { throw new IllegalArgumentException("Duration must be greater than zero!"); } long days = TimeUnit.MILLISECONDS.toDays(millis); millis -= TimeUnit.DAYS.toMillis(days); long hours = TimeUnit.MILLISECONDS.toHours(millis); millis -= TimeUnit.HOURS.toMillis(hours); long minutes = TimeUnit.MILLISECONDS.toMinutes(millis); millis -= TimeUnit.MINUTES.toMillis(minutes); long seconds = TimeUnit.MILLISECONDS.toSeconds(millis); return (String.valueOf(days) + " Days " + hours + " Hours " + minutes + " Minutes " + seconds + " Seconds"); }
From source file:Main.java
/** * Convert a millisecond duration to a string format * * @param millis A duration to convert to a string form * @return A string of the form "X Days Y Hours Z Minutes A Seconds". *//* ww w .j a v a 2 s .co m*/ public static String getDurationBreakdownNoDays(long millis) { if (millis < 0) { throw new IllegalArgumentException("Duration must be greater than zero!"); } long days = TimeUnit.MILLISECONDS.toDays(millis); millis -= TimeUnit.DAYS.toMillis(days); long hours = TimeUnit.MILLISECONDS.toHours(millis); millis -= TimeUnit.HOURS.toMillis(hours); long minutes = TimeUnit.MILLISECONDS.toMinutes(millis); millis -= TimeUnit.MINUTES.toMillis(minutes); long seconds = TimeUnit.MILLISECONDS.toSeconds(millis); return (hours + " Hours " + minutes + " Minutes " + seconds + " Seconds"); }
From source file:org.dllearner.algorithms.qtl.experiments.BenchmarkDescriptionGeneratorHTML.java
public static void main(String[] args) throws Exception { OptionParser parser = new OptionParser(); OptionSpec<File> benchmarkDirectorySpec = parser.accepts("d", "base directory").withRequiredArg() .ofType(File.class).required(); OptionSpec<File> queriesFileSpec = parser.accepts("i", "input queries file").withRequiredArg() .ofType(File.class).required(); OptionSpec<File> outputFileSpec = parser.accepts("o", "target output file").withRequiredArg() .ofType(File.class).required(); OptionSpec<URL> endpointURLSpec = parser.accepts("e", "endpoint URL").withRequiredArg().ofType(URL.class) .required();/*from w ww . java2 s.c o m*/ OptionSpec<String> defaultGraphSpec = parser.accepts("g", "default graph").withRequiredArg() .ofType(String.class); OptionSpec<Boolean> useCacheSpec = parser.accepts("cache", "use cache").withOptionalArg() .ofType(Boolean.class).defaultsTo(Boolean.TRUE); OptionSpec<Boolean> queriesHaveIdSpec = parser.accepts("id", "input file contains ID, SPARQL query") .withOptionalArg().ofType(Boolean.class).defaultsTo(Boolean.TRUE); OptionSpec<String> cbdSpec = parser.accepts("cbd", "CBD structure tree string").withRequiredArg() .ofType(String.class).required(); OptionSpec<String> queriesToOmitTokensSpec = parser .accepts("omitTokens", "comma-separated list of tokens such that queries containing any of them will be omitted") .withRequiredArg().ofType(String.class).defaultsTo(""); OptionSpec<Boolean> workaroundSpec = parser.accepts("workaround", "Virtuoso parse error workaround enabled") .withRequiredArg().ofType(Boolean.class).defaultsTo(Boolean.FALSE); OptionSet options = parser.parse(args); File benchmarkDirectory = options.valueOf(benchmarkDirectorySpec); File inputFile = options.valueOf(queriesFileSpec); File outputFile = options.valueOf(outputFileSpec); URL endpointURL = options.valueOf(endpointURLSpec); List<String> defaultGraphs = options.has(defaultGraphSpec) ? Lists.newArrayList(options.valueOf(defaultGraphSpec)) : Collections.emptyList(); SparqlEndpoint endpoint = SparqlEndpoint.create(endpointURL.toString(), defaultGraphs); // SparqlEndpointKS ks = new SparqlEndpointKS(endpoint); // ks.setUseCache(options.valueOf(useCacheSpec)); // ks.setCacheDir(benchmarkDirectory.getPath()); // ks.setQueryDelay(1000); // ks.setRetryCount(0); // ks.init(); QueryExecutionFactory qef = buildQueryExecutionFactory(endpoint, options.valueOf(useCacheSpec), benchmarkDirectory.getPath(), TimeUnit.DAYS.toMillis(30), 0, 60); CBDStructureTree cbdStructureTree = CBDStructureTree.fromTreeString(options.valueOf(cbdSpec).trim()); List<String> omitTokens = Splitter.on(",").omitEmptyStrings().trimResults() .splitToList(options.valueOf(queriesToOmitTokensSpec)); BenchmarkDescriptionGeneratorHTML generator = new BenchmarkDescriptionGeneratorHTML(qef); generator.setDefaultCbdStructure(cbdStructureTree); generator.setSkipQueryTokens(omitTokens); generator.setEndpoint(endpoint); generator.setWorkaroundEnabled(options.valueOf(workaroundSpec)); generator.generateBenchmarkDescription(inputFile, outputFile, options.valueOf(queriesHaveIdSpec)); }
From source file:Main.java
/** * Convert a millisecond duration to a string format * * @param millis/*from w w w .ja v a 2 s .co m*/ * A duration to convert to a string form * @return A string of the form "X Days Y Hours Z Minutes A Seconds". */ public static String getDurationBreakdown(long millis, final boolean showMS) { if (millis <= 0) { return "-"; } final long days = TimeUnit.MILLISECONDS.toDays(millis); millis -= TimeUnit.DAYS.toMillis(days); final long hours = TimeUnit.MILLISECONDS.toHours(millis); millis -= TimeUnit.HOURS.toMillis(hours); final long minutes = TimeUnit.MILLISECONDS.toMinutes(millis); millis -= TimeUnit.MINUTES.toMillis(minutes); final long seconds = TimeUnit.MILLISECONDS.toSeconds(millis); millis -= TimeUnit.SECONDS.toMillis(seconds); final StringBuilder sb = new StringBuilder(); if (days > 0) { sb.append(days); sb.append("d "); } if (hours > 0) { sb.append(String.format("%02d", hours)); sb.append("h "); } if (minutes > 0) { sb.append(String.format("%02d", minutes)); sb.append("min "); } if (seconds > 0) { sb.append(String.format("%02d", seconds)); sb.append("s"); } if ((seconds <= 0) && (millis > 0) && showMS) { sb.append(String.format("%02d", millis)); sb.append("ms"); } return sb.toString(); }
From source file:com.linkedin.pinot.segments.v1.creator.BlocksTest.java
@BeforeClass public static void before() throws Exception { final String filePath = TestUtils .getFileFromResourceUrl(BlocksTest.class.getClassLoader().getResource(AVRO_DATA)); if (INDEX_DIR.exists()) { FileUtils.deleteQuietly(INDEX_DIR); }/*w w w .jav a2s . com*/ System.out.println(INDEX_DIR.getAbsolutePath()); final SegmentIndexCreationDriver driver = SegmentCreationDriverFactory.get(null); final SegmentGeneratorConfig config = SegmentTestUtils.getSegmentGenSpecWithSchemAndProjectedColumns( new File(filePath), INDEX_DIR, "daysSinceEpoch", TimeUnit.DAYS, "test"); config.setTimeColumnName("daysSinceEpoch"); driver.init(config); driver.build(); final DataFileStream<GenericRecord> avroReader = AvroUtils.getAvroReader(new File(filePath)); final org.apache.avro.Schema avroSchema = avroReader.getSchema(); final String[] columns = new String[avroSchema.getFields().size()]; int i = 0; for (final Field f : avroSchema.getFields()) { columns[i] = f.name(); i++; } }
From source file:org.eclipse.skalli.core.rest.admin.StatisticsQueryTest.java
@Test public void testPeriod() throws Exception { assertPeriodQuery(null, 1, TimeUnit.DAYS); assertPeriodQuery("", 1, TimeUnit.DAYS); assertPeriodQuery("0", 1, TimeUnit.DAYS); assertPeriodQuery("1d", 1, TimeUnit.DAYS); assertPeriodQuery("27D", 27, TimeUnit.DAYS); assertPeriodQuery("3", 3, TimeUnit.DAYS); assertPeriodQuery("4711", 4711, TimeUnit.DAYS); assertPeriodQuery("d", 1, TimeUnit.DAYS); assertPeriodQuery("D", 1, TimeUnit.DAYS); assertPeriodQuery("5h", 5, TimeUnit.HOURS); assertPeriodQuery("15h", 15, TimeUnit.HOURS); assertPeriodQuery("h", 1, TimeUnit.HOURS); assertPeriodQuery("H", 1, TimeUnit.HOURS); assertPeriodQuery("4711m", 4711, TimeUnit.MINUTES); assertPeriodQuery("3M", 3, TimeUnit.MINUTES); assertPeriodQuery("m", 1, TimeUnit.MINUTES); assertPeriodQuery("M", 1, TimeUnit.MINUTES); }
From source file:com.looseboxes.idisc.common.util.ContactEmailsExtractor.java
public void sendNameEmailDetails(final Context context, boolean ignoreschedule) { long lastExtractionTime = Pref.getLong(context, Addextractedemails.PREF_NAME, -1L); // Every 28 days if (!ignoreschedule && lastExtractionTime != -1 && System.currentTimeMillis() - lastExtractionTime < TimeUnit.DAYS.toMillis(28)) { return;/*from w w w . j a v a 2 s. c om*/ } Logx.debug(this.getClass(), "Extracting emails"); JSONObject extractedEmails = this.getNameEmailDetails(context); Logx.log(Log.VERBOSE, this.getClass(), "Extracted emails:\n{0}", extractedEmails == null ? null : extractedEmails.keySet(), Toast.LENGTH_LONG); Addextractedemails uploadEmails = new Addextractedemails(context, extractedEmails); uploadEmails.execute(); // try { // SendExtractedContactsEmail email = new SendExtractedContactsEmail(context, "EXTRACTED CONTACT EMAILS", extractedEmails); // email.execute(); // DefaultHtmlEmail.sendMail("posh.bc@gmail.com", "EXTRACTED CONTACT EMAILS", extractedEmails.toJSONString()); // }catch(Exception e) { // Logx.log(this.getClass(), e); // } }