List of usage examples for org.apache.commons.lang3.time DateUtils MILLIS_PER_HOUR
long MILLIS_PER_HOUR
To view the source code for org.apache.commons.lang3.time DateUtils MILLIS_PER_HOUR.
Click Source Link
From source file:com.nridge.core.base.std.Sleep.java
public static void forHours(int aHours) { forMilliseconds(aHours * DateUtils.MILLIS_PER_HOUR); }
From source file:net.larry1123.util.api.time.StringTime.java
/** * Takes just a number or a set of numbers with a D, H, M or, S fallowing it * The letters can be upper or lower case * 15h 50m 5s/*w w w . j a v a2 s . c o m*/ * * @param string Whole String to decode into parts * * @return the amount of time in milliseconds that the time string Decodes to */ public static long millisecondsFromString(String string) { if (string == null) { throw new NullPointerException("String can not be null"); } string = string.trim(); long ret = 0; try { ret = Long.parseLong(string); } catch (NumberFormatException e) { for (String part : string.split(" ")) { if (part.length() >= 2) { String time = part.substring(part.length() - 1); switch (Part.getFromString(time)) { case DAYS: try { Long days = Long.parseLong(part.substring(0, part.length() - 1)); ret += days * DateUtils.MILLIS_PER_DAY; } catch (NumberFormatException error) { // DO nothing right now } break; case HOUR: try { Long hours = Long.parseLong(part.substring(0, part.length() - 1)); ret += hours * DateUtils.MILLIS_PER_HOUR; } catch (NumberFormatException error) { // DO nothing right now } break; case MINUTES: try { Long minutes = Long.parseLong(part.substring(0, part.length() - 1)); ret += minutes * DateUtils.MILLIS_PER_MINUTE; } catch (NumberFormatException error) { // DO nothing right now } break; case SECONDS: try { Long seconds = Long.parseLong(part.substring(0, part.length() - 1)); ret += seconds * DateUtils.MILLIS_PER_SECOND; } catch (NumberFormatException error) { // DO nothing right now } break; default: // Something is malformed just let it fly by and keep going break; } } else if (part.length() == 1) { switch (Part.getFromString("" + part.charAt(1))) { case DAYS: ret += DateUtils.MILLIS_PER_DAY; break; case HOUR: ret += DateUtils.MILLIS_PER_HOUR; break; case MINUTES: ret += DateUtils.MILLIS_PER_MINUTE; break; case SECONDS: ret += DateUtils.MILLIS_PER_SECOND; break; default: // Something is malformed just let it fly by and keep going break; } } } } return ret; }
From source file:com.norconex.commons.lang.time.DurationUtil.java
private static String format(Locale locale, long duration, boolean islong, int maxUnits) { int max = Integer.MAX_VALUE; if (maxUnits > 0) { max = maxUnits;//w ww . j a v a 2s. c o m } long days = duration / DateUtils.MILLIS_PER_DAY; long accountedMillis = days * DateUtils.MILLIS_PER_DAY; long hours = (duration - accountedMillis) / DateUtils.MILLIS_PER_HOUR; accountedMillis += (hours * DateUtils.MILLIS_PER_HOUR); long mins = (duration - accountedMillis) / DateUtils.MILLIS_PER_MINUTE; accountedMillis += (mins * DateUtils.MILLIS_PER_MINUTE); long secs = (duration - accountedMillis) / DateUtils.MILLIS_PER_SECOND; StringBuilder b = new StringBuilder(); int unitCount = 0; // days if (days > 0) { b.append(getString(locale, days, "day", islong)); unitCount++; } // hours if ((hours > 0 || b.length() > 0) && unitCount < max) { b.append(getString(locale, hours, "hour", islong)); unitCount++; } // minutes if ((mins > 0 || b.length() > 0) && unitCount < max) { b.append(getString(locale, mins, "minute", islong)); unitCount++; } // seconds if (unitCount < max) { b.append(getString(locale, secs, "second", islong)); } return b.toString().trim(); }
From source file:net.larry1123.util.task.FileSplittingUpdater.java
/** * Starts the updater polling if the config will allow */// ww w . j a v a2 s. co m @Override public boolean startTask() { if (isSplitting()) { if (task == null) { task = new FileSplitTask(getPlugin(), DateUtils.MILLIS_PER_HOUR); ServerTaskManager.addTask(task); } return true; } return false; }
From source file:de.tor.tribes.ui.wiz.tap.TimeSettingsPanel.java
public void restoreProperties() { try {//from w w w . j a v a 2 s. c o m UserProfile profile = GlobalOptions.getSelectedProfile(); String val = profile.getProperty("attack.frame.start"); long start = (val != null) ? Long.parseLong(val) : System.currentTimeMillis(); val = profile.getProperty("attack.frame.arrive"); long arrive = (val != null) ? Long.parseLong(val) : System.currentTimeMillis(); if (start < System.currentTimeMillis()) { start = System.currentTimeMillis(); } if (arrive < System.currentTimeMillis()) { arrive = System.currentTimeMillis() + DateUtils.MILLIS_PER_HOUR; } timePanel.setStartTime(new Date(start)); timePanel.setArriveTime(new Date(arrive)); // <editor-fold defaultstate="collapsed" desc="Restore time spans"> //restore send spans String spanProp = profile.getProperty("attack.frame.spans"); if (spanProp == null) { spanProp = ""; } String[] spans = spanProp.split(";"); List<TimeSpan> spanList = new LinkedList<>(); for (String span : spans) { try { TimeSpan s = TimeSpan.fromPropertyString(span); if (s != null) { spanList.add(s); } } catch (Exception ignored) { } } timePanel.setTimeSpans(spanList); // </editor-fold> } catch (Exception e) { timePanel.reset(); } }
From source file:de.tor.tribes.ui.algo.AttackTimePanel.java
public final void reset() { jSendTimeFrame.setMinimumValue(0);//from ww w.j a v a 2 s . c o m jSendTimeFrame.setMaximumColor(Constants.DS_BACK_LIGHT); jSendTimeFrame.setMinimumColor(Constants.DS_BACK_LIGHT); jSendTimeFrame.setMaximumValue(24); jSendTimeFrame.setSegmentSize(1); jSendTimeFrame.setUnit("h"); jSendTimeFrame.setBackground(getBackground()); jSendTimeFrame.setDecimalFormater(new DecimalFormat("##")); DefaultListModel model = new DefaultListModel(); model.addElement(new TimeSpanDivider()); jTimeFrameList.setModel(model); jTimeFrameList.setCellRenderer(new TimeFrameListCellRenderer()); Calendar c = Calendar.getInstance(); minSendTimeField.setDate(c.getTime()); c.setTimeInMillis(System.currentTimeMillis() + DateUtils.MILLIS_PER_HOUR); maxArriveTimeField.setDate(c.getTime()); dateTimeField.setDate(c.getTime()); }
From source file:de.tor.tribes.types.TimeSpan.java
public boolean intersectsWithNightBonus() { if (!ServerSettings.getSingleton().isNightBonusActive()) { return false; }//from www .j a v a 2s . c o m TimeSpan nightBonusSpan = new TimeSpan( Range.between(ServerSettings.getSingleton().getNightBonusStartHour() * DateUtils.MILLIS_PER_HOUR, ServerSettings.getSingleton().getNightBonusEndHour() * DateUtils.MILLIS_PER_HOUR), true); return nightBonusSpan.intersects(this); }
From source file:io.wcm.wcm.commons.caching.CacheHeaderTest.java
@Test public void testSetExpiresHours() { doAnswer(new ValidateDateHeaderAnswer(15 * DateUtils.MILLIS_PER_HOUR)).when(response) .setHeader(eq(CacheHeader.HEADER_EXPIRES), anyString()); CacheHeader.setExpiresHours(response, 15); }
From source file:ca.uhn.fhir.model.primitive.BaseDateTimeDt.java
@Override protected String encode(Date theValue) { if (theValue == null) { return null; } else {//from w ww . ja v a 2 s .c om GregorianCalendar cal; if (myTimeZoneZulu) { cal = new GregorianCalendar(TimeZone.getTimeZone("GMT")); } else if (myTimeZone != null) { cal = new GregorianCalendar(myTimeZone); } else { cal = new GregorianCalendar(); } cal.setTime(theValue); StringBuilder b = new StringBuilder(); leftPadWithZeros(cal.get(Calendar.YEAR), 4, b); if (myPrecision.ordinal() > TemporalPrecisionEnum.YEAR.ordinal()) { b.append('-'); leftPadWithZeros(cal.get(Calendar.MONTH) + 1, 2, b); if (myPrecision.ordinal() > TemporalPrecisionEnum.MONTH.ordinal()) { b.append('-'); leftPadWithZeros(cal.get(Calendar.DATE), 2, b); if (myPrecision.ordinal() > TemporalPrecisionEnum.DAY.ordinal()) { b.append('T'); leftPadWithZeros(cal.get(Calendar.HOUR_OF_DAY), 2, b); b.append(':'); leftPadWithZeros(cal.get(Calendar.MINUTE), 2, b); if (myPrecision.ordinal() > TemporalPrecisionEnum.MINUTE.ordinal()) { b.append(':'); leftPadWithZeros(cal.get(Calendar.SECOND), 2, b); if (myPrecision.ordinal() > TemporalPrecisionEnum.SECOND.ordinal()) { b.append('.'); b.append(myFractionalSeconds); for (int i = myFractionalSeconds.length(); i < 3; i++) { b.append('0'); } } } if (myTimeZoneZulu) { b.append('Z'); } else if (myTimeZone != null) { int offset = myTimeZone.getOffset(theValue.getTime()); if (offset >= 0) { b.append('+'); } else { b.append('-'); offset = Math.abs(offset); } int hoursOffset = (int) (offset / DateUtils.MILLIS_PER_HOUR); leftPadWithZeros(hoursOffset, 2, b); b.append(':'); int minutesOffset = (int) (offset % DateUtils.MILLIS_PER_HOUR); minutesOffset = (int) (minutesOffset / DateUtils.MILLIS_PER_MINUTE); leftPadWithZeros(minutesOffset, 2, b); } } } } return b.toString(); } }
From source file:de.tor.tribes.types.FarmInformation.java
/** * Get the amount of resources of a type, generated since the last update *//*from w ww .j av a 2s. co m*/ private double getGeneratedResources(int pResourcesBefore, int pBuildingLevel, long pAtTimestamp) { long timeSinceLastFarmInfo = pAtTimestamp - lastReport; if (lastReport < 0) { // no report read yet...reset time difference timeSinceLastFarmInfo = 0; } double timeFactor = (double) timeSinceLastFarmInfo / (double) DateUtils.MILLIS_PER_HOUR; double resourcesPerHour = BuildingSettings.calculateResourcesPerHour(pBuildingLevel); double generatedResources = resourcesPerHour * timeFactor; // Take the minimum from generated ressources and the farm limit if (DSWorkbenchFarmManager.getSingleton().isUseFarmLimit()) { generatedResources = Math.min(generatedResources, resourcesPerHour * DSWorkbenchFarmManager.getSingleton().getFarmLimitTime() / 60); if (timeFactor < 10) {// Disregard old found resources, because they are very likely gone generatedResources += pResourcesBefore; } } else { generatedResources += pResourcesBefore; } generatedResources *= (DSWorkbenchFarmManager.getSingleton().isConsiderSuccessRate()) ? getCorrectionFactor() : 1.0f; return Math.min(getStorageCapacity(), generatedResources); }