List of usage examples for java.util.concurrent TimeUnit HOURS
TimeUnit HOURS
To view the source code for java.util.concurrent TimeUnit HOURS.
Click Source Link
From source file:me.mast3rplan.phantombot.PhantomBot.java
private void doCheckPhantomBotUpdate() { ScheduledExecutorService service = Executors.newSingleThreadScheduledExecutor(); service.scheduleAtFixedRate(() -> { String[] newVersionInfo = GitHubAPIv3.instance().CheckNewRelease(); if (newVersionInfo != null) { try { Thread.sleep(6000); print(""); print("New PhantomBot Release Detected: " + newVersionInfo[0]); print("Release Changelog: https://github.com/PhantomBot/PhantomBot/releases/" + newVersionInfo[0]); print("Download Link: " + newVersionInfo[1]); print("A reminder will be provided in 24 hours!"); print(""); } catch (InterruptedException ex) { com.gmt2001.Console.err.printStackTrace(ex); }/*from ww w. ja v a2 s .c o m*/ if (webEnabled) { dataStore.set("settings", "newrelease_info", newVersionInfo[0] + "|" + newVersionInfo[1]); } } else { dataStore.del("settings", "newrelease_info"); } }, 0, 24, TimeUnit.HOURS); }
From source file:me.mast3rplan.phantombot.PhantomBot.java
/** * Backup the database, keeping so many days. *///from ww w .ja v a2 s .co m private void doBackupSQLiteDB() { if (!dataStoreType.equals("sqlite3store")) { return; } ScheduledExecutorService service = Executors.newSingleThreadScheduledExecutor(); service.scheduleAtFixedRate(() -> { SimpleDateFormat datefmt = new SimpleDateFormat("ddMMyyyy.hhmmss"); datefmt.setTimeZone(TimeZone.getTimeZone(timeZone)); String timestamp = datefmt.format(new Date()); dataStore.backupSQLite3("phantombot.auto.backup." + timestamp + ".db"); try { Iterator dirIterator = FileUtils.iterateFiles(new File("./dbbackup"), new WildcardFileFilter("phantombot.auto.*"), null); while (dirIterator.hasNext()) { File backupFile = (File) dirIterator.next(); if (FileUtils.isFileOlder(backupFile, System.currentTimeMillis() - (86400000 * backupSQLiteKeepDays))) { FileUtils.deleteQuietly(backupFile); } } } catch (Exception ex) { com.gmt2001.Console.err.println("Failed to clean up database backup directory: " + ex.getMessage()); } }, 0, backupSQLiteHourFrequency, TimeUnit.HOURS); }
From source file:dentex.youtube.downloader.DashboardActivity.java
private int getTotSeconds(Matcher timeMatcher) { int h = Integer.parseInt(timeMatcher.group(1)); int m = Integer.parseInt(timeMatcher.group(2)); int s = Integer.parseInt(timeMatcher.group(3)); int f = Integer.parseInt(timeMatcher.group(4)); long hToSec = TimeUnit.HOURS.toSeconds(h); long mToSec = TimeUnit.MINUTES.toSeconds(m); int tot = (int) (hToSec + mToSec + s); if (f > 50) tot = tot + 1;//from w ww . ja v a2 s . co m Utils.logger("d", "h=" + h + " m=" + m + " s=" + s + "." + f + " -> tot=" + tot, DEBUG_TAG); return tot; }
From source file:org.eclipse.smarthome.binding.sonos.handler.ZonePlayerHandler.java
private String sleepSecondsToTimeStr(long sleepSeconds) { if (sleepSeconds == 0) { return ""; } else if (sleepSeconds < 68400) { long hours = TimeUnit.SECONDS.toHours(sleepSeconds); sleepSeconds -= TimeUnit.HOURS.toSeconds(hours); long minutes = TimeUnit.SECONDS.toMinutes(sleepSeconds); sleepSeconds -= TimeUnit.MINUTES.toSeconds(minutes); long seconds = TimeUnit.SECONDS.toSeconds(sleepSeconds); return String.format("%02d:%02d:%02d", hours, minutes, seconds); } else {/*from w w w. java2 s . co m*/ logger.error("Sonos SleepTimer: Invalid sleep time set. sleep time must be >=0 and < 68400s (24h)"); return "ERR"; } }
From source file:org.eclipse.smarthome.binding.sonos.internal.handler.ZonePlayerHandler.java
private String sleepSecondsToTimeStr(long sleepSeconds) { if (sleepSeconds == 0) { return ""; } else if (sleepSeconds < 68400) { long remainingSeconds = sleepSeconds; long hours = TimeUnit.SECONDS.toHours(remainingSeconds); remainingSeconds -= TimeUnit.HOURS.toSeconds(hours); long minutes = TimeUnit.SECONDS.toMinutes(remainingSeconds); remainingSeconds -= TimeUnit.MINUTES.toSeconds(minutes); long seconds = TimeUnit.SECONDS.toSeconds(remainingSeconds); return String.format("%02d:%02d:%02d", hours, minutes, seconds); } else {/*from www . j a va 2s . c o m*/ logger.debug("Sonos SleepTimer: Invalid sleep time set. sleep time must be >=0 and < 68400s (24h)"); return "ERR"; } }
From source file:it.isislab.dmason.util.SystemManagement.Master.thrower.DMasonMaster.java
@Override public void update(Observable o, Object arg) { int value;//from www .j a va 2 s . com if (arg.equals("Update")) { wu.dispose(); setConnectionSettingsEnabled(false); setSystemSettingsEnabled(true); jMenuItemUpdateWorker.setEnabled(true); } if (arg.equals("Test done")) { value = testCount.incrementAndGet(); int progValue = (value * 100) / totalTests; progressBarBatchTest.setValue(progValue); progressBarBatchTest.setString(progValue + " %"); if (value == totalTests) { progressBarBatchTest.setString("Done!"); long end = System.currentTimeMillis(); long seconds = TimeUnit.SECONDS.convert((end - batchStartedTime), TimeUnit.MILLISECONDS) % 60; long minutes = TimeUnit.MINUTES.convert((end - batchStartedTime), TimeUnit.MILLISECONDS); long hours = TimeUnit.HOURS.convert((end - batchStartedTime), TimeUnit.MILLISECONDS); textAreaBatchInfo.append("Batch Ended at: " + Util.getCurrentDateTime(end) + "\n"); textAreaBatchInfo .append("Batch execution time (h:m:s): " + hours + ":" + minutes + ":" + seconds + "\n"); batchLogger.debug("Ended at: " + end); } } }
From source file:org.apache.hadoop.hive.conf.HiveConf.java
public static TimeUnit unitFor(String unit, TimeUnit defaultUnit) { unit = unit.trim().toLowerCase();/*from w ww .j a v a 2 s .c o m*/ if (unit.isEmpty() || unit.equals("l")) { if (defaultUnit == null) { throw new IllegalArgumentException("Time unit is not specified"); } return defaultUnit; } else if (unit.equals("d") || unit.startsWith("day")) { return TimeUnit.DAYS; } else if (unit.equals("h") || unit.startsWith("hour")) { return TimeUnit.HOURS; } else if (unit.equals("m") || unit.startsWith("min")) { return TimeUnit.MINUTES; } else if (unit.equals("s") || unit.startsWith("sec")) { return TimeUnit.SECONDS; } else if (unit.equals("ms") || unit.startsWith("msec")) { return TimeUnit.MILLISECONDS; } else if (unit.equals("us") || unit.startsWith("usec")) { return TimeUnit.MICROSECONDS; } else if (unit.equals("ns") || unit.startsWith("nsec")) { return TimeUnit.NANOSECONDS; } throw new IllegalArgumentException("Invalid time unit " + unit); }