Java Code Examples for org.apache.commons.lang3.time.DateUtils#MILLIS_PER_HOUR
The following examples show how to use
org.apache.commons.lang3.time.DateUtils#MILLIS_PER_HOUR .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FarmInformation.java From dsworkbench with Apache License 2.0 | 6 votes |
/** * Get the amount of resources of a type, generated since the last update */ 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); }
Example 2
Source File: FarmInformation.java From dsworkbench with Apache License 2.0 | 6 votes |
private void guessResourceBuildings(FightReport pReport1, FightReport pReport2) { double dt = (double) (pReport2.getTimestamp() - pReport1.getTimestamp()) / (double) DateUtils.MILLIS_PER_HOUR; for (int i = 0; i < 3; i++) { // get resources in village at time of arrival int resourceInVillage1 = pReport1.getHaul()[i] + ((pReport1.getSpyedResources() != null) ? pReport1.getSpyedResources()[i] : 0); int resourceInVillage2 = pReport2.getHaul()[i] + ((pReport2.getSpyedResources() != null) ? pReport2.getSpyedResources()[i] : 0); int dResource = resourceInVillage2 - resourceInVillage1; int resourceBuildingLevel = DSCalculator.calculateEstimatedResourceBuildingLevel(dResource, dt); switch (i) { case 0: setBuilding("wood", Math.max(getBuilding("wood"), resourceBuildingLevel)); break; case 1: setBuilding("stone", Math.max(getBuilding("stone"), resourceBuildingLevel)); break; case 2: setBuilding("iron", Math.max(getBuilding("iron"), resourceBuildingLevel)); break; } } }
Example 3
Source File: BaseDateTimeType.java From org.hl7.fhir.core with Apache License 2.0 | 5 votes |
private boolean couldBeTheSameTime(BaseDateTimeType theArg1, BaseDateTimeType theArg2) { boolean theCouldBeTheSameTime = false; if (theArg1.getTimeZone() == null && theArg2.getTimeZone() != null) { long lowLeft = new DateTimeType(theArg1.getValueAsString()+"Z").getValue().getTime() - (14 * DateUtils.MILLIS_PER_HOUR); long highLeft = new DateTimeType(theArg1.getValueAsString()+"Z").getValue().getTime() + (14 * DateUtils.MILLIS_PER_HOUR); long right = theArg2.getValue().getTime(); if (right >= lowLeft && right <= highLeft) { theCouldBeTheSameTime = true; } } return theCouldBeTheSameTime; }
Example 4
Source File: BaseDateTimeType.java From org.hl7.fhir.core with Apache License 2.0 | 5 votes |
private boolean couldBeTheSameTime(BaseDateTimeType theArg1, BaseDateTimeType theArg2) { boolean theCouldBeTheSameTime = false; if (theArg1.getTimeZone() == null && theArg2.getTimeZone() != null) { long lowLeft = new DateTimeType(theArg1.getValueAsString()+"Z").getValue().getTime() - (14 * DateUtils.MILLIS_PER_HOUR); long highLeft = new DateTimeType(theArg1.getValueAsString()+"Z").getValue().getTime() + (14 * DateUtils.MILLIS_PER_HOUR); long right = theArg2.getValue().getTime(); if (right >= lowLeft && right <= highLeft) { theCouldBeTheSameTime = true; } } return theCouldBeTheSameTime; }
Example 5
Source File: PortalMapper.java From KaellyBot with GNU General Public License v3.0 | 5 votes |
private static String getLabelTimeAgo(Instant time, Language lg){ long timeLeft = Math.abs(Duration.between(time, Instant.now()).toMillis()); if (timeLeft < DateUtils.MILLIS_PER_MINUTE) return Translator.getLabel(lg, "portal.date.now"); else if (timeLeft < DateUtils.MILLIS_PER_HOUR) return Translator.getLabel(lg, "portal.date.minutes_ago") .replace("{time}", String.valueOf(timeLeft / DateUtils.MILLIS_PER_MINUTE)); else return Translator.getLabel(lg, "portal.date.hours_ago") .replace("{time}", String.valueOf(timeLeft / DateUtils.MILLIS_PER_HOUR)); }
Example 6
Source File: FarmInformation.java From dsworkbench with Apache License 2.0 | 5 votes |
private void guessResourceBuildings(FightReport pReport) { if (pReport == null || pReport.getHaul() == null) { // no info return; } // only use if last report is not too old....!! -> send time - 30min !? // and if last attack returned empty long send = pReport.getTimestamp() - DSCalculator.calculateMoveTimeInMillis(pReport.getSourceVillage(), pReport.getTargetVillage(), pReport.getAttackers().getSpeed()); if (resourcesFoundInLastReport || lastReport == -1 || lastReport < send - 200 * DateUtils.MILLIS_PER_MINUTE || lastReport == pReport.getTimestamp()) { // ignore this report return; } int wood = pReport.getHaul()[0]; int clay = pReport.getHaul()[1]; int iron = pReport.getHaul()[2]; double dt = (pReport.getTimestamp() - lastReport) / (double) DateUtils.MILLIS_PER_HOUR; int woodBuildingLevel = DSCalculator.calculateEstimatedResourceBuildingLevel(wood, dt); int clayBuildingLevel = DSCalculator.calculateEstimatedResourceBuildingLevel(clay, dt); int ironBuildingLevel = DSCalculator.calculateEstimatedResourceBuildingLevel(iron, dt); setBuilding("wood", Math.max(getBuilding("wood"), woodBuildingLevel)); setBuilding("stone", Math.max(getBuilding("stone"), clayBuildingLevel)); setBuilding("iron", Math.max(getBuilding("iron"), ironBuildingLevel)); }
Example 7
Source File: TimeSettingsPanel.java From dsworkbench with Apache License 2.0 | 4 votes |
public void restoreProperties() { try { 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(); } }