List of usage examples for org.joda.time DateTime getSecondOfMinute
public int getSecondOfMinute()
From source file:org.kalypso.ui.rrm.internal.calccase.CatchmentModelHelper.java
License:Open Source License
private static DateRange modifyWithTimestamp(final LocalTime timestamp, final DateTime simulationStart, final DateTime simulationEnd) { /* Nothing to do. */ if (timestamp == null) return new DateRange(simulationStart.toDate(), simulationEnd.toDate()); /* Convert to a date with the kalypso timezone. */ /* The date fields are ignored. */ final DateTime timestampUTC = timestamp .toDateTimeToday(DateTimeZone.forTimeZone(TimeZone.getTimeZone("UTC"))); //$NON-NLS-1$ final DateTime timestampDate = new DateTime(timestampUTC.toDate(), DateTimeZone.forTimeZone(KalypsoCorePlugin.getDefault().getTimeZone())); /* Further adjust range by predefined time. */ final DateTime startWithTime = simulationStart.withTime(timestampDate.getHourOfDay(), timestampDate.getMinuteOfHour(), timestampDate.getSecondOfMinute(), timestampDate.getMillisOfSecond()); final DateTime endWithTime = simulationEnd.withTime(timestampDate.getHourOfDay(), timestampDate.getMinuteOfHour(), timestampDate.getSecondOfMinute(), timestampDate.getMillisOfSecond()); return new DateRange(startWithTime.toDate(), endWithTime.toDate()); }
From source file:org.kalypso.ui.rrm.internal.calccase.CatchmentModelHelper.java
License:Open Source License
/** * This function calculates the range for the timeseries to be generated. The range equals the range defined in the * simulation adjusted as follows:// w w w . java 2s. c o m * <ul> * <li>1 timestep earlier</li> * <li>3 timesteps later</li> * </ul> * * @param control * The na control. * @param timestep * The timestep. * @param timestamp * The timestamp in UTC. * @return The date range. */ public static DateRange getRange(final NAControl control, final Period timestep, final LocalTime timestamp) { final Date simulationStart = control.getSimulationStart(); final Date simulationEnd = control.getSimulationEnd(); final DateTime start = new DateTime(simulationStart); final DateTime end = new DateTime(simulationEnd); final DateTime adjustedStart = start.minus(timestep); final DateTime adjustedEnd = end.plus(timestep).plus(timestep).plus(timestep); if (timestep.getDays() == 0 || timestamp == null) return new DateRange(adjustedStart.toDate(), adjustedEnd.toDate()); /* Convert to a date with the kalypso timezone. */ /* The date fields are ignored. */ final DateTime timestampUTC = timestamp .toDateTimeToday(DateTimeZone.forTimeZone(TimeZone.getTimeZone("UTC"))); //$NON-NLS-1$ final DateTime timestampDate = new DateTime(timestampUTC.toDate(), DateTimeZone.forTimeZone(KalypsoCorePlugin.getDefault().getTimeZone())); /* Further adjust range by predefined time. */ final DateTime startWithTime = adjustedStart.withTime(timestampDate.getHourOfDay(), timestampDate.getMinuteOfHour(), timestampDate.getSecondOfMinute(), timestampDate.getMillisOfSecond()); final DateTime endWithTime = adjustedEnd.withTime(timestampDate.getHourOfDay(), timestampDate.getMinuteOfHour(), timestampDate.getSecondOfMinute(), timestampDate.getMillisOfSecond()); /* New start must always be before unadjusted start, fix, if this is not the case. */ DateTime startWithTimeFixed; if (startWithTime.isAfter(adjustedStart)) startWithTimeFixed = startWithTime.minus(timestep); else startWithTimeFixed = startWithTime; /* New end must always be after unadjusted end, fix, if this is not the case. */ DateTime endWithTimeFixed; if (endWithTime.isBefore(adjustedEnd)) endWithTimeFixed = endWithTime.plus(timestep); else endWithTimeFixed = endWithTime; return new DateRange(startWithTimeFixed.toDate(), endWithTimeFixed.toDate()); }
From source file:org.mongoste.util.DateUtil.java
License:Open Source License
public static DateTime toUTC(DateTime fromDate) { if (DateTimeZone.UTC.equals(fromDate.getZone())) { return fromDate; }//from w w w . j a v a 2 s . c o m MutableDateTime dt = getDateTimeUTC().toMutableDateTime(); dt.setDateTime(fromDate.getYear(), fromDate.getMonthOfYear(), fromDate.getDayOfMonth(), fromDate.getHourOfDay(), fromDate.getMinuteOfHour(), fromDate.getSecondOfMinute(), fromDate.getMillisOfSecond()); return dt.toDateTime(); }
From source file:org.opencastproject.index.service.catalog.adapter.DublinCoreMetadataUtil.java
License:Educational Community License
/** * Gets the current hour, minute and second from a dublin core period if available. * * @param period/* w w w. j a v a 2 s. c om*/ * The current period from dublin core. * @return A new DateTime with the current hour, minute and second. */ static DateTime getCurrentStartTime(Opt<DCMIPeriod> period) { DateTime currentStartTime = new DateTime(); currentStartTime = currentStartTime.withZone(DateTimeZone.UTC); currentStartTime = currentStartTime.withHourOfDay(0); currentStartTime = currentStartTime.withMinuteOfHour(0); currentStartTime = currentStartTime.withSecondOfMinute(0); if (period.isSome() && period.get().hasStart()) { DateTime fromDC = new DateTime(period.get().getStart().getTime()); fromDC = fromDC.withZone(DateTimeZone.UTC); currentStartTime = currentStartTime.withZone(DateTimeZone.UTC); currentStartTime = currentStartTime.withHourOfDay(fromDC.getHourOfDay()); currentStartTime = currentStartTime.withMinuteOfHour(fromDC.getMinuteOfHour()); currentStartTime = currentStartTime.withSecondOfMinute(fromDC.getSecondOfMinute()); } return currentStartTime; }
From source file:org.opencastproject.index.service.catalog.adapter.DublinCoreMetadataUtil.java
License:Educational Community License
/** * Sets the start date in a dublin core catalog to the right value and keeps the start time and duration the same. * * @param dc//www. ja va 2 s . c om * The dublin core catalog to adjust * @param field * The metadata field that contains the start date. * @param ename * The EName in the catalog to identify the property that has the dublin core period. */ static void setTemporalStartDate(DublinCoreCatalog dc, MetadataField<?> field, EName ename) { if (field.getValue().isNone() || (field.getValue().get() instanceof String && StringUtils.isBlank(field.getValue().get().toString()))) { logger.debug("No value was set for metadata field with dublin core id '{}' and json id '{}'", field.getInputID(), field.getOutputID()); return; } try { // Get the current date SimpleDateFormat dateFormat = MetadataField.getSimpleDateFormatter(field.getPattern().get()); Date startDate = dateFormat.parse((String) field.getValue().get()); // Get the current period Opt<DCMIPeriod> period = getPeriodFromCatalog(dc, ename); // Get the current duration Long duration = getDuration(period); // Get the current start time hours, minutes and seconds DateTime currentStartTime = getCurrentStartTime(period); // Setup the new start time DateTime startDateTime = new DateTime(startDate.getTime()); startDateTime = startDateTime.withZone(DateTimeZone.UTC); startDateTime = startDateTime.withHourOfDay(currentStartTime.getHourOfDay()); startDateTime = startDateTime.withMinuteOfHour(currentStartTime.getMinuteOfHour()); startDateTime = startDateTime.withSecondOfMinute(currentStartTime.getSecondOfMinute()); // Get the current end date based on new date and duration. DateTime endDate = new DateTime(startDateTime.toDate().getTime() + duration); dc.set(ename, EncodingSchemeUtils.encodePeriod(new DCMIPeriod(startDateTime.toDate(), endDate.toDate()), Precision.Second)); } catch (ParseException e) { logger.error("Not able to parse date {} to update the dublin core because: {}", field.getValue(), ExceptionUtils.getStackTrace(e)); } }
From source file:org.opencastproject.index.service.catalog.adapter.DublinCoreMetadataUtil.java
License:Educational Community License
/** * Gets the current hour, minute and second from a dublin core period if available. * * @param period/* w w w . j a va 2 s .c om*/ * The current period from dublin core. * @return A new DateTime with the current hour, minute and second. */ private static DateTime getCurrentStartDateTime(Opt<DCMIPeriod> period) { DateTime currentStartTime = new DateTime(); currentStartTime = currentStartTime.withZone(DateTimeZone.UTC); currentStartTime = currentStartTime.withYear(2001); currentStartTime = currentStartTime.withMonthOfYear(1); currentStartTime = currentStartTime.withDayOfMonth(1); currentStartTime = currentStartTime.withHourOfDay(0); currentStartTime = currentStartTime.withMinuteOfHour(0); currentStartTime = currentStartTime.withSecondOfMinute(0); if (period.isSome() && period.get().hasStart()) { DateTime fromDC = new DateTime(period.get().getStart().getTime()); fromDC = fromDC.withZone(DateTimeZone.UTC); currentStartTime = currentStartTime.withZone(DateTimeZone.UTC); currentStartTime = currentStartTime.withYear(fromDC.getYear()); currentStartTime = currentStartTime.withMonthOfYear(fromDC.getMonthOfYear()); currentStartTime = currentStartTime.withDayOfMonth(fromDC.getDayOfMonth()); currentStartTime = currentStartTime.withHourOfDay(fromDC.getHourOfDay()); currentStartTime = currentStartTime.withMinuteOfHour(fromDC.getMinuteOfHour()); currentStartTime = currentStartTime.withSecondOfMinute(fromDC.getSecondOfMinute()); } return currentStartTime; }
From source file:org.openehr.rm.datatypes.quantity.datetime.DvDateTimeParser.java
License:LGPL
public static DateTime defaultTime() { DateTime time = new DateTime(); return new DateTime(1970, 1, 1, time.getHourOfDay(), time.getMinuteOfHour(), time.getSecondOfMinute(), time.getMillisOfSecond());/*from w ww. j a va2 s . com*/ }
From source file:org.openehr.rm.datatypes.quantity.datetime.DvTime.java
License:LGPL
/** * Parses a string value and return a DvTime *///from w w w .java 2 s . c om public DvTime parse(String value) { DateTime time = DvDateTimeParser.parseTime(value); return new DvTime(time.getHourOfDay(), time.getMinuteOfHour(), time.getSecondOfMinute(), time.getMillisOfSecond(), time.getZone().toTimeZone()); }
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 w w w. java2 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 a v a 2 s. com*/ * * @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); }