List of usage examples for org.joda.time Period hours
public static Period hours(int hours)
From source file:com.mirth.connect.server.util.LoginRequirementsChecker.java
License:Open Source License
public String getPrintableLockoutPeriod() { return PeriodFormat.getDefault().print(Period.hours(passwordRequirements.getLockoutPeriod())); }
From source file:com.netflix.iep.config.Strings.java
License:Apache License
private static Period parseAtPeriod(String amt, String unit) { int v = Integer.valueOf(amt); if (unit.equals("s") || unit.equals("second") || unit.equals("seconds")) return Period.seconds(v); if (unit.equals("m") || unit.equals("min") || unit.equals("minute") || unit.equals("minutes")) return Period.minutes(v); if (unit.equals("h") || unit.equals("hour") || unit.equals("hours")) return Period.hours(v); if (unit.equals("d") || unit.equals("day") || unit.equals("days")) return Period.days(v); if (unit.equals("w") || unit.equals("wk") || unit.equals("week") || unit.equals("weeks")) return Period.weeks(v); if (unit.equals("month") || unit.equals("months")) return Period.months(v); if (unit.equals("y") || unit.equals("year") || unit.equals("years")) return Period.years(v); throw new IllegalArgumentException("unknown unit " + unit); }
From source file:com.sap.dirigible.runtime.metrics.TimeUtils.java
License:Open Source License
public static Date roundCeilingHour(Date date) { DateTime bound = dateTimeCeiling(new DateTime(date.getTime()), Period.hours(1)); return new Date(bound.getMillis()); }
From source file:com.serotonin.m2m2.Common.java
License:Open Source License
public static Period getPeriod(int periodType, int periods) { switch (periodType) { case TimePeriods.MILLISECONDS: return Period.millis(periods); case TimePeriods.SECONDS: return Period.seconds(periods); case TimePeriods.MINUTES: return Period.minutes(periods); case TimePeriods.HOURS: return Period.hours(periods); case TimePeriods.DAYS: return Period.days(periods); case TimePeriods.WEEKS: return Period.weeks(periods); case TimePeriods.MONTHS: return Period.months(periods); case TimePeriods.YEARS: return Period.years(periods); default:/*from w w w . ja v a 2 s . c om*/ throw new ShouldNeverHappenException("Unsupported time period: " + periodType); } }
From source file:com.thinkbiganalytics.scheduler.util.TimerToCronExpression.java
License:Apache License
/** * Parse a timer string to a Joda time period * * @param timer a string indicating a time unit (i.e. 5 sec) * @param periodType the Period unit to use. *//*from w w w . ja va 2 s . co m*/ public static Period timerStringToPeriod(String timer, PeriodType periodType) { String cronString = null; Integer time = Integer.parseInt(StringUtils.substringBefore(timer, " ")); String units = StringUtils.substringAfter(timer, " ").toLowerCase(); //time to years,days,months,hours,min, sec Integer days = 0; Integer hours = 0; Integer min = 0; Integer sec = 0; Period p = null; if (units.startsWith("sec")) { p = Period.seconds(time); } else if (units.startsWith("min")) { p = Period.minutes(time); } else if (units.startsWith("hr") || units.startsWith("hour")) { p = Period.hours(time); } else if (units.startsWith("day")) { p = Period.days(time); } if (periodType != null) { p = p.normalizedStandard(periodType); } else { } return p; }
From source file:de.ifgi.airbase.feeder.data.EEAMeasurementType.java
License:Open Source License
public Period getPeriod() { switch (this) { case HOUR://w w w . j a va2s .co m return Period.hours(1); case THREE_HOURS: return Period.hours(3); case EIGHT_HOURS: return Period.hours(8); case DAY: case DAY_MAX: return Period.days(1); case WEEK: return Period.weeks(1); case TWO_WEEKS: return Period.weeks(2); case FOUR_WEEKS: return Period.weeks(4); case MONTH: return Period.months(1); case THREE_MONTH: return Period.months(3); case YEAR: return Period.years(1); case VAR: default: throw new Error("Period not known"); } }
From source file:io.konig.dao.core.SimpleChartFactory.java
License:Apache License
private Period toPeriod(ShapeQuery query) throws DaoException { String value = query.getParameters().get("timeInterval.durationUnit"); if (value == null) { throw new DaoException("durationUnit is not defined"); }/*from ww w . ja v a2 s.c o m*/ value = value.toLowerCase(); switch (value) { case "second": return Period.seconds(1); case "hour": return Period.hours(1); case "day": return Period.days(1); case "week": return Period.weeks(1); case "month": return Period.months(1); case "quarter": return Period.months(3); case "year": return Period.years(1); } throw new DaoException("Invalid durationUnit: " + value); }
From source file:net.solarnetwork.central.dras.mock.biz.MockDRASObserverBiz.java
License:Open Source License
public MockDRASObserverBiz() { TimeZone tz = TimeZone.getTimeZone("Pacific/Auckland"); uniLocation = new SolarLocation(); uniLocation.setId(counter.decrementAndGet()); uniLocation.setCountry("NZ"); uniLocation.setCreated(new DateTime()); uniLocation.setName("Mock Location"); uniLocation.setRegion("UNI"); uniLocation.setTimeZoneId(tz.getID()); uniLocation.setLatitude(groupLatitude); uniLocation.setLongitude(groupLongitude); uniLocations = new LinkedHashMap<Long, SolarLocation>(); uniLocations.put(uniLocation.getId(), uniLocation); uniGroups = new ArrayList<SolarNodeGroup>(numGroups); addGroup(new SolarNodeGroup(counter.decrementAndGet(), uniLocation.getId(), "Mock Group A")); addGroup(new SolarNodeGroup(counter.decrementAndGet(), uniLocation.getId(), "Mock Group B")); participantGroups = new ArrayList<CapabilityInformation>(numGroups); for (SolarNodeGroup group : uniGroups) { SimpleCapabilityInformation groupInfo = new SimpleCapabilityInformation(); groupInfo.setId(group.getId());/*ww w .java 2 s .c om*/ groupInfo.setLocation(uniLocation); groupInfo.setGenerationCapacityWatts(participantGenerationCapacity); groupInfo.setStorageCapacityWattHours(participantStorageCapacity); participantGroups.add(groupInfo); } uniProgramParticipants = new LinkedHashSet<Identity<Long>>(numNodes); participantGroupMemebers = new LinkedHashMap<Long, Set<CapabilityInformation>>(numGroups); for (int i = 0; i < numNodes; i++) { SolarNode participant = new SolarNode(counter.decrementAndGet(), createRandomLocation().getId()); uniProgramParticipants.add(participant); int groupIndex = (i % numGroups); SimpleCapabilityInformation group = (SimpleCapabilityInformation) participantGroups.get(groupIndex); Set<CapabilityInformation> groupMembers = participantGroupMemebers.get(group.getId()); if (groupMembers == null) { groupMembers = new LinkedHashSet<CapabilityInformation>(numNodes); participantGroupMemebers.put(group.getId(), groupMembers); } SimpleCapabilityInformation info = new SimpleCapabilityInformation(); info.setId(participant.getId()); info.setLocation(uniLocations.get(participant.getLocationId())); info.setGenerationCapacityWatts(participantGenerationCapacity); info.setStorageCapacityWattHours(participantStorageCapacity); groupMembers.add(info); group.addGenerationCapacityWatts(participantGenerationCapacity); group.addStorageCapacityWattHours(participantStorageCapacity); } uniProgram = new Program(counter.decrementAndGet(), "UNI Program", 1); MutableDateTime mdt = new MutableDateTime(2011, 1, 1, 8, 0, 0, 0, DateTimeZone.forTimeZone(tz)); uniEvents = new ArrayList<Event>(numEvents); uniEventParticipants = new LinkedHashMap<Long, EventParticipants>(numEvents); uniEventTargets = new LinkedHashMap<Long, EventTargets>(numEvents); EventRule eventRule = new EventRule(counter.decrementAndGet(), EventRule.RuleKind.LOAD_AMOUNT, EventRule.ScheduleKind.DYNAMIC); addEventRule(eventRule); for (int i = 0; i < numEvents; i++) { Event event = new Event(counter.decrementAndGet(), uniProgram.getId(), String.format("Mock Event %d", (i + 1)), mdt.toDateTime(), mdt.toDateTime().plus(Period.hours(2))); Set<Identity<Long>> groupSet = new LinkedHashSet<Identity<Long>>(2); switch (i % 3) { case 0: groupSet.add(participantGroups.get(0)); break; case 1: groupSet.add(participantGroups.get(1)); break; case 2: groupSet.add(participantGroups.get(0)); groupSet.add(participantGroups.get(1)); break; } EventParticipants ep = new EventParticipants(counter.decrementAndGet(), event.getId(), null, groupSet); uniEventParticipants.put(event.getId(), ep); // give each event a load shed target of 1kW EventTargets et = new EventTargets(counter.decrementAndGet(), eventRule.getId(), new TreeSet<EventTarget>(Arrays.asList(new EventTarget(Duration.ZERO, 1000D)))); addEvent(event, ep, et); mdt.addWeeks(1); } }
From source file:net.solarnetwork.central.dras.mock.biz.MockDRASQueryBiz.java
License:Open Source License
@Override public List<? extends NodeDatum> getAggregatedDatum(Class<? extends NodeDatum> datumClass, DatumQueryCommand criteria) {//from w w w . j a va2s .c o m MutableDateTime mdt = new MutableDateTime(criteria.getStartDate()); Period period; switch (criteria.getAggregate()) { case Hour: period = Period.hours(1); break; case Day: period = Period.days(1); break; case Week: period = Period.weeks(1); break; case Month: period = Period.months(1); break; default: period = Period.minutes(1); } List<NodeDatum> results = new ArrayList<NodeDatum>(); do { NodeDatum datum = null; if (ConsumptionDatum.class.isAssignableFrom(datumClass)) { ReportingConsumptionDatum d = new ReportingConsumptionDatum(); d.setNodeId(criteria.getNodeId()); d.setCreated(mdt.toDateTime()); Duration dur = period.toDurationFrom(mdt); float hours = (float) ((double) dur.getMillis() / (double) (1000 * 60 * 60)); d.setWattHours(Double.valueOf(hours * consumptionWattHours)); datum = d; } else if (PowerDatum.class.isAssignableFrom(datumClass)) { ReportingPowerDatum d = new ReportingPowerDatum(); d.setNodeId(criteria.getNodeId()); d.setCreated(mdt.toDateTime()); Duration dur = period.toDurationFrom(mdt); float hours = (float) ((double) dur.getMillis() / (double) (1000 * 60 * 60)); d.setWattHours(Double.valueOf(hours * generationWattHours)); datum = d; } if (datum != null) { results.add(datum); } mdt.add(period); } while (mdt.isBefore(criteria.getEndDate())); return results; }
From source file:org.jevis.jealarm.AlarmHandler.java
License:Open Source License
/** * Checks the Data Objects for alarms and send an email. * * @param alarm//w ww .j ava 2 s . c o m * @throws JEVisException */ public void checkAlarm(Alarm alarm) throws JEVisException { List<JEVisObject> outOfBount = new ArrayList<>(); List<JEVisObject> dps = getDataPoints(alarm); DateTime now = new DateTime(); DateTime ignoreTS = now.minus(Period.hours(alarm.getIgnoreOld())); DateTime limit = now.minus(Period.hours(alarm.getTimeLimit())); for (JEVisObject obj : dps) { JEVisSample lsample = obj.getAttribute("Value").getLatestSample(); if (lsample != null) { if (lsample.getTimestamp().isBefore(limit) && lsample.getTimestamp().isAfter(ignoreTS)) { outOfBount.add(obj); } } } DateTimeFormatter dtf = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm"); StringBuilder sb = new StringBuilder(); sb.append("<html>"); sb.append(alarm.getGreeting()); sb.append(","); sb.append("<br>"); sb.append("<br>"); sb.append(alarm.getMessage()); sb.append("<br>"); sb.append("<br>"); String tabelCSS = "background-color:#FFF;" + "text-color: #024457;" + "outer-border: 1px solid #167F92;" + "empty-cells:show;" + "border-collapse:collapse;" // + "border: 2px solid #D9E4E6;" + "cell-border: 1px solid #D9E4E6"; String headerCSS = "background-color: #1a719c;" + "color: #FFF;"; String rowCss = "text-color: #024457;padding: 5px;";//"border: 1px solid #D9E4E6;" String highlight = "background-color: #EAF3F3"; sb.append("<table style=\"" + tabelCSS + "\" border=\"1\" >"); //border=\"0\" sb.append("<tr style=\"" + headerCSS + "\" >" + " <th>Organisation</th>" + " <th>Building</th>" + " <th>Directory</th>" + " <th>Datapoint</th>" + " <th>Last Value</th>" + " </tr>"); JEVisClass orga = _ds.getJEVisClass("Organization"); JEVisClass building = _ds.getJEVisClass("Monitored Object"); JEVisClass dir = _ds.getJEVisClass("Data Directory"); boolean odd = false; for (JEVisObject probelObj : outOfBount) { String css = rowCss; if (odd) { css += highlight; } odd = !odd; sb.append("<tr>");// style=\"border: 1px solid #D9E4E6;\">"); sb.append("<td style=\""); sb.append(css); sb.append("\">"); sb.append(getParentName(probelObj, orga)); sb.append("</td>"); sb.append("<td style=\""); sb.append(css); sb.append("\">"); sb.append(getParentName(probelObj, building)); sb.append("</td>"); sb.append("<td style=\""); sb.append(css); sb.append("\">"); sb.append(getParentName(probelObj, dir)); sb.append("</td>"); sb.append("<td style=\""); sb.append(css); sb.append("\">"); sb.append(probelObj.getName()); sb.append("</td>"); //Last Sample //TODO: the fetch the sample again everytime is bad for the performace, store the sample somewhere sb.append("<td style=\""); sb.append(css); sb.append("\">"); sb.append(dtf.print(probelObj.getAttribute("Value").getLatestSample().getTimestamp())); sb.append("</td>"); sb.append("</tr>"); } sb.append("</tr>"); sb.append("</tr>"); sb.append("</table>"); sb.append("<br>"); sb.append(_conf.getSmtpSignatur()); sb.append("</html>"); if (outOfBount.isEmpty() && alarm.isIgnoreFalse()) { //Do nothing then } else { sendAlarm(_conf, alarm, sb.toString()); } }