List of usage examples for org.joda.time DateTime getMinuteOfHour
public int getMinuteOfHour()
From source file:org.openhab.binding.stiebelheatpump.internal.CommunicationService.java
License:Open Source License
/** * This method set the time of the heat pump to the current time * /*from www. j a v a 2 s . c o m*/ * @return true if time has been updated */ public Map<String, String> setTime() throws StiebelHeatPumpException { startCommunication(); Map<String, String> data = new HashMap<String, String>(); Request timeRequest = null; for (Request request : heatPumpSettingConfiguration) { if (request.getName().equals("Time")) { timeRequest = request; break; } } if (timeRequest == null) { logger.warn("Could not find request definition for time settings! Skip setting time."); return data; } logger.debug("Loading current time data ..."); try { // get time from heat pump byte[] requestMessage = createRequestMessage(timeRequest); byte[] response = getData(requestMessage); // get current time from local machine DateTime dt = DateTime.now(); logger.debug("Current time is : {}", dt.toString()); String weekday = Integer.toString(dt.getDayOfWeek() - 1); String day = Integer.toString(dt.getDayOfMonth()); String month = Integer.toString(dt.getMonthOfYear()); String year = Integer.toString(dt.getYearOfCentury()); String seconds = Integer.toString(dt.getSecondOfMinute()); String hours = Integer.toString(dt.getHourOfDay()); String minutes = Integer.toString(dt.getMinuteOfHour()); data = parser.parseRecords(response, timeRequest); boolean updateRequired = false; for (Map.Entry<String, String> entry : data.entrySet()) { String entryName = entry.getKey(); String entryValue = entry.getValue(); RecordDefinition currentRecord = null; for (RecordDefinition record : timeRequest.getRecordDefinitions()) { if (record.getName().equals(entryName)) { currentRecord = record; break; } } if (entryName.equals("WeekDay") && !entryValue.equals(weekday)) { updateRequired = true; response = parser.composeRecord(weekday, response, currentRecord); logger.debug("WeekDay needs update from {} to {}", entryValue, weekday); continue; } if (entryName.equals("Hours") && !entryValue.equals(hours)) { updateRequired = true; response = parser.composeRecord(hours, response, currentRecord); logger.debug("Hours needs update from {} to {}", entryValue, hours); continue; } if (entryName.equals("Minutes") && !entryValue.equals(minutes)) { updateRequired = true; response = parser.composeRecord(minutes, response, currentRecord); logger.debug("Minutes needs update from {} to {}", entryValue, minutes); continue; } if (entryName.equals("Seconds") && !entryValue.equals(seconds)) { updateRequired = true; response = parser.composeRecord(seconds, response, currentRecord); logger.debug("Seconds needs update from {} to {}", entryValue, seconds); continue; } if (entryName.equals("Year") && !entryValue.equals(year)) { updateRequired = true; response = parser.composeRecord(year, response, currentRecord); logger.debug("Year needs update from {} to {}", entryValue, year); continue; } if (entryName.equals("Month") && !entryValue.equals(month)) { updateRequired = true; response = parser.composeRecord(month, response, currentRecord); logger.debug("Month needs update from {} to {}", entryValue, month); continue; } if (entryName.equals("Day") && !entryValue.equals(day)) { updateRequired = true; response = parser.composeRecord(day, response, currentRecord); logger.debug("Day needs update from {} to {}", entryValue, day); continue; } } if (updateRequired) { Thread.sleep(WAITING_TIME_BETWEEN_REQUESTS); logger.info("Time need update. Set time to " + dt.toString()); setData(response); Thread.sleep(WAITING_TIME_BETWEEN_REQUESTS); response = getData(requestMessage); data = parser.parseRecords(response, timeRequest); dt = DateTime.now(); logger.debug("Current time is : {}", dt.toString()); } return data; } catch (InterruptedException e) { throw new StiebelHeatPumpException(e.toString()); } }
From source file:org.openmainframe.ade.ext.main.VerifyLinuxTraining.java
License:Open Source License
/** * Count the number of occurences of unique messages IDs in the given time range * for all of the sources, assumed to be from a single model group. * Also sets the member variables for the number of intervals and the number * of intervals containing messages./*from w w w .j av a 2s . c om*/ * * @param sourceSet * @param start * @param end * * @return MessageMetrics - interesting data to use in computing whether the training can proceed. * * @throws AdeException */ private static MessageMetrics computeMessageMetrics(Ade ade, Set<ISource> sourceSet, Date start, Date end) throws AdeException { int numIntervals = 0; int numIntervalsWithMessages = 0; final Map<Integer, Integer> occurrence = new HashMap<Integer, Integer>(); System.out.println("Start computeMessageMetrics "); /* * Get data from the database * * get list of periods from start date to end date for each source */ final Collection<IPeriod> periods = new ArrayList<IPeriod>(); for (ISource source : sourceSet) { periods.addAll(Ade.getAde().getDataStore().periods().getAllPeriods(source, start, end)); } /* return if no periods */ if (periods.isEmpty()) { return new MessageMetrics(0, 0, 0); } /* extract data from the database for each period */ final List<IInterval> curIntervals = new ArrayList<IInterval>(); final Comparator<IInterval> intervalComparator = new Comparator<IInterval>() { @Override public int compare(IInterval int1, IInterval int2) { final long diff = int1.getIntervalStartTime() - int2.getIntervalStartTime(); // Casting to an int isn't a shortcut here. if (diff < 0) { return -1; } else if (diff > 0) { return 1; } else { return 0; } } }; // Periods are days. 120 with default training params for Linux. for (IPeriod period : periods) { final FramingFlowType framingFlowType = Ade.getAde().getFlowFactory().getFlowByName("LINUX") .getMyFramingFlows().get("tenMinutesTrain"); final IAdeIterator<IInterval> iterator = ade.getDataStore().periods().getPeriodIntervals(period, framingFlowType); try { /* For each interval update count of messages * fetch data */ curIntervals.clear(); iterator.open(); // Because intervals overlap (each includes 50 minutes of the previous interval), // we only want to count one interval with messages per hour so sort the intervals // by time and make sure that intervals in the same hour don't increases the amount // of messages multiple times IInterval curInt; while ((curInt = iterator.getNext()) != null) { curIntervals.add(curInt); } Collections.sort(curIntervals, intervalComparator); // We need the total number of intervals for notification messages. numIntervals += curIntervals.size(); DateTime lastIntervalTime = null; boolean addedMessage = false; for (IInterval curInterval : curIntervals) { // Check to see if this interval is for the same hour as the previously processed one, // if it's not set it as the new interval and allow the amount of intervals with messages // to be incremented if (lastIntervalTime == null) { lastIntervalTime = new DateTime(curInterval.getIntervalStartTime()); } else { DateTime currentIntervalTime = new DateTime(curInterval.getIntervalStartTime()); currentIntervalTime = currentIntervalTime .minusMinutes(currentIntervalTime.getMinuteOfHour()) .minusSeconds(currentIntervalTime.getSecondOfMinute()) .minusMillis(currentIntervalTime.getMillisOfSecond()); if (!lastIntervalTime.isEqual(currentIntervalTime)) { lastIntervalTime = currentIntervalTime; addedMessage = false; } } final Collection<IMessageSummary> msgSummaries = curInterval.getMessageSummaries(); if (!msgSummaries.isEmpty() && !addedMessage) { numIntervalsWithMessages++; addedMessage = true; } for (IMessageSummary msgSummary : msgSummaries) { final int msgID = msgSummary.getMessageInternalId(); if (occurrence.containsKey(msgID)) { /* get number of occurrences for this msgID (internal msgID) * increment it and put back again */ occurrence.put(msgID, occurrence.get(msgID) + 1); } else { /* this is first time we see this word, set value '1' */ occurrence.put(msgID, 1); } } } iterator.close(); } finally { iterator.quietCleanup(); } } return new MessageMetrics(occurrence.size(), numIntervalsWithMessages, numIntervals); }
From source file:org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.DlmsHelperService.java
License:Open Source License
/** * Creates a COSEM date-time object based on the given {@code dateTime}. * <p>//from w w w .j a v a 2 s. co m * The deviation and clock status (is daylight saving active or not) are * based on the zone of the given {@code dateTime}. * <p> * To use a DateTime as indication of the instant of time to be used with a * specific deviation (that does not have to match the zone of the * DateTime), use {@link #asDataObject(DateTime, int, boolean)} instead. * * @param dateTime * a DateTime to translate into COSEM date-time format. * @return a DataObject having a CosemDateTime matching the given DateTime * as value. */ public DataObject asDataObject(final DateTime dateTime) { final CosemDate cosemDate = new CosemDate(dateTime.getYear(), dateTime.getMonthOfYear(), dateTime.getDayOfMonth()); final CosemTime cosemTime = new CosemTime(dateTime.getHourOfDay(), dateTime.getMinuteOfHour(), dateTime.getSecondOfMinute(), dateTime.getMillisOfSecond() / 10); final int deviation = -(dateTime.getZone().getOffset(dateTime.getMillis()) / MILLISECONDS_PER_MINUTE); final ClockStatus[] clockStatusBits; if (dateTime.getZone().isStandardOffset(dateTime.getMillis())) { clockStatusBits = new ClockStatus[0]; } else { clockStatusBits = new ClockStatus[1]; clockStatusBits[0] = ClockStatus.DAYLIGHT_SAVING_ACTIVE; } final CosemDateTime cosemDateTime = new CosemDateTime(cosemDate, cosemTime, deviation, clockStatusBits); return DataObject.newDateTimeData(cosemDateTime); }
From source file:org.opensmartgridplatform.adapter.protocol.dlms.domain.commands.DlmsHelperService.java
License:Open Source License
/** * Creates a COSEM date-time object based on the given {@code dateTime}. * This COSEM date-time will be for the same instant in time as the given * {@code dateTime} but may be for another time zone. * <p>//from ww w . j a va 2 s .c o m * Because the time zone with the {@code deviation} may be different than * the one with the {@code dateTime}, and the {@code deviation} alone does * not provide sufficient information on whether daylight savings is active * for the given instant in time, {@code dst} has to be provided to indicate * whether daylight savings are active. * <p> * If a DateTime for an instant in time is known with the correct time zone * set, you can use {@link #asDataObject(DateTime)} as a simpler * alternative. * * @param dateTime * a DateTime indicating an instant in time to be used for the * COSEM date-time. * @param deviation * the deviation in minutes of local time to GMT to be included * in the COSEM date-time. * @param dst * {@code true} if daylight savings are active for the instant of * the COSEM date-time, otherwise {@code false}. * @return a DataObject having a CosemDateTime for the instant of the given * DateTime, with the given deviation and DST status information, as * value. */ public DataObject asDataObject(final DateTime dateTime, final int deviation, final boolean dst) { /* * Create a date time that may not point to the right instant in time, * but that will give proper values getting the different fields for the * COSEM date and time objects. */ final DateTime dateTimeWithOffset = dateTime.toDateTime(DateTimeZone.UTC).minusMinutes(deviation); final CosemDate cosemDate = new CosemDate(dateTimeWithOffset.getYear(), dateTimeWithOffset.getMonthOfYear(), dateTimeWithOffset.getDayOfMonth()); final CosemTime cosemTime = new CosemTime(dateTimeWithOffset.getHourOfDay(), dateTimeWithOffset.getMinuteOfHour(), dateTimeWithOffset.getSecondOfMinute(), dateTimeWithOffset.getMillisOfSecond() / 10); final ClockStatus[] clockStatusBits; if (dst) { clockStatusBits = new ClockStatus[1]; clockStatusBits[0] = ClockStatus.DAYLIGHT_SAVING_ACTIVE; } else { clockStatusBits = new ClockStatus[0]; } final CosemDateTime cosemDateTime = new CosemDateTime(cosemDate, cosemTime, deviation, clockStatusBits); return DataObject.newDateTimeData(cosemDateTime); }
From source file:org.openvpms.web.workspace.workflow.appointment.AbstractMultiDayScheduleGrid.java
License:Open Source License
/** * Returns the no. of slots an event occupies, from the specified slot. * <p>/*from w w w . ja v a2 s. com*/ * If the event begins prior to the slot, the remaining slots will be returned. * * @param event the event * @param slot the starting slot * @return the no. of slots that the event occupies */ public int getSlots(PropertySet event, int slot) { DateTime endTime = new DateTime(event.getDate(ScheduleEvent.ACT_END_TIME)); int endSlot = Days.daysBetween(new DateTime(getStartDate()), endTime).getDays(); if (endTime.getHourOfDay() > 0 || endTime.getMinuteOfHour() > 0) { ++endSlot; } return endSlot - slot; }
From source file:org.openvpms.web.workspace.workflow.appointment.FreeAppointmentSlotQuery.java
License:Open Source License
/** * Returns the next slot nearest to the specified time. * * @param time the slot time// w ww .j a v a 2 s . c o m * @return the next nearest slot */ private Date getNextSlot(Date time) { Date from; int slotSize = 15; DateTime dt = new DateTime(time); int min = (dt.getMinuteOfHour() / slotSize) * slotSize; if (dt.getMinuteOfHour() % slotSize != 0) { min += slotSize; if (min >= 60) { dt = dt.plusHours(1); min = 0; } } from = dt.withMinuteOfHour(min).minuteOfDay().roundFloorCopy().toDate(); return from; }
From source file:org.pidome.server.services.clients.remoteclient.RemoteClient.java
License:Apache License
/** * Returns the date since this client connected (From successful login). * @return /*ww w . ja v a 2s . co m*/ */ public final String getConnectedSinceDateTime() { DateTime dt = new DateTime(connectedSince); return TimeUtils.composeDDMMYYYYDate(dt.getDayOfMonth(), dt.getMonthOfYear(), dt.getYear()) + " " + TimeUtils.compose24Hours(dt.getHourOfDay(), dt.getMinuteOfHour()); }
From source file:org.richfaces.fragment.calendar.TimeEditor.java
License:Open Source License
public TimeEditor setTime(DateTime time, SetValueBy inputType) { return setTime(time.getHourOfDay(), time.getMinuteOfHour(), time.getSecondOfMinute(), inputType); }
From source file:org.richfaces.tests.page.fragments.impl.calendar.common.editor.time.RichFacesTimeEditor.java
License:Open Source License
@Override public TimeEditor setTime(DateTime time, SetValueBy inputType) { return setTime(time.getHourOfDay(), time.getMinuteOfHour(), time.getSecondOfMinute(), inputType); }
From source file:org.rockholla.date.DateUtility.java
License:Open Source License
/** * Formats a datetime for use in a MySQL datetime field * //from ww w . j a v a2 s . c o m * @param dateTime the org.joda.time.DateTime value to format * @param offset offset the input datetime by this amount of hours * @return the formatted datetime */ public static String getMySqlDate(DateTime dateTime, int offset) { if (offset > 0 || offset < 0) { dateTime = dateTime.plusHours(offset); } String result = String.valueOf(dateTime.getYear()) + "-" + NumberUtility.format(dateTime.getMonthOfYear(), NumberUtility.FORMAT.TWO_CHARACTER_INTEGER) + "-" + NumberUtility.format(dateTime.getDayOfMonth(), NumberUtility.FORMAT.TWO_CHARACTER_INTEGER) + " " + NumberUtility.format(dateTime.getHourOfDay(), NumberUtility.FORMAT.TWO_CHARACTER_INTEGER) + ":" + NumberUtility.format(dateTime.getMinuteOfHour(), NumberUtility.FORMAT.TWO_CHARACTER_INTEGER) + ":" + NumberUtility.format(dateTime.getSecondOfMinute(), NumberUtility.FORMAT.TWO_CHARACTER_INTEGER); return result; }