List of usage examples for org.joda.time DateTime getHourOfDay
public int getHourOfDay()
From source file:net.sourceforge.fenixedu.presentationTier.TagLib.GanttDiagramTagLib.java
License:Open Source License
private int calculateTimeOfDay(DateTime time) { int hourOfDay = time.getHourOfDay(); int minuteOfHour = time.getMinuteOfHour(); switch (getViewTypeEnum()) { case WEEKLY:/*from w w w . j a v a 2 s. c o m*/ // unit = 15 minutes int result = (hourOfDay + 1) * 2; if (minuteOfHour <= 30) { return result - 1; } else { return result; } case DAILY: // unit = 5 minutes for (int i = 1, j = 0; j < 60; j += 5, i++) { if (minuteOfHour < j + 5) { return i + (12 * hourOfDay); } } case MONTHLY: // unit = hour of day return hourOfDay; case YEAR_DAILY: // unit = hour of day return hourOfDay; default: return 0; } }
From source file:net.stickycode.scheduled.aligned.AlignedPeriodicSchedule.java
License:Open Source License
/** * The delay in seconds to wait before the initial execution to align the schedule as specified. * <b>An alignment of 0 means there is no delay</b> * <p>//from w ww .j av a2s . co m * e.g. * <ul> * <li>if the user configured a schedule as 'every hour at 15 minutes past'</li> * <li>and the service started at 10 minutes past</li> * <li>then the period would be 60 * 60 seconds</li> * <li>and the delay would be 5 * 60 seconds such that the first execution is 15 minutes past</li> * </ul> * </p> */ @Override public long getInitialDelay() { if (alignment == 0) return 0; DateTime time = new DateTime(); switch (alignmentUnit) { case HOURS: return calculateDelay(time.getHourOfDay(), alignment, 24); case MINUTES: return calculateDelay(time.getMinuteOfHour(), alignment, 60); case SECONDS: return calculateDelay(time.getSecondOfMinute(), alignment, 60); case MILLISECONDS: return calculateDelay(time.getMillisOfSecond(), alignment, 1000); default: throw new AlignmentNotSupportedException(alignmentUnit); } }
From source file:net.tourbook.database.TourDatabase.java
License:Open Source License
/** * Persist {@link TourData} in the database and updates the tour data cache with the persisted * tour<br>//from w ww .jav a 2s. c o m * <br> * When a tour has no person the tour will not be saved, a person must be set first before the * tour can be saved * * @param tourData * @return persisted {@link TourData} or <code>null</code> when saving fails */ public static TourData saveTour(final TourData tourData) { /* * prevent saving a tour which was deleted before */ if (tourData.isTourDeleted) { return null; } /* * prevent saving a tour when a person is not set, this check is for internal use that all * data are valid */ if (tourData.getTourPerson() == null) { StatusUtil.log("Cannot save a tour without a person: " + tourData); //$NON-NLS-1$ return null; } /* * check size of varcar fields */ if (tourData.isValidForSave() == false) { return null; } final DateTime dtNow = new DateTime(); final long dtSaved = (dtNow.getYear() * 10000000000L) + (dtNow.getMonthOfYear() * 100000000L) + (dtNow.getDayOfMonth() * 1000000L) + (dtNow.getHourOfDay() * 10000L) + (dtNow.getMinuteOfHour() * 100L) + dtNow.getSecondOfMinute(); EntityManager em = TourDatabase.getInstance().getEntityManager(); TourData persistedEntity = null; if (em != null) { final EntityTransaction ts = em.getTransaction(); try { tourData.onPrePersist(); ts.begin(); { final TourData tourDataEntity = em.find(TourData.class, tourData.getTourId()); if (tourDataEntity == null) { // tour is not yet persisted tourData.setDateTimeCreated(dtSaved); em.persist(tourData); persistedEntity = tourData; } else { tourData.setDateTimeModified(dtSaved); persistedEntity = em.merge(tourData); } } ts.commit(); } catch (final Exception e) { StatusUtil.showStatus(Messages.Tour_Database_TourSaveError, e); } finally { if (ts.isActive()) { ts.rollback(); } em.close(); } } if (persistedEntity != null) { em = TourDatabase.getInstance().getEntityManager(); try { persistedEntity = em.find(TourData.class, tourData.getTourId()); } catch (final Exception e) { StatusUtil.log(e); } em.close(); TourManager.getInstance().updateTourInCache(persistedEntity); } return persistedEntity; }
From source file:net.tourbook.device.garmin.GarminSAXHandler.java
License:Open Source License
private void finalizeTour() { // check if data are available if (_dtList.size() == 0) { return;/*from w w w. j a v a 2 s . com*/ } validateTimeSeries(); // create data object for each tour final TourData tourData = new TourData(); // set tour notes setTourNotes(tourData); /* * set tour start date/time */ adjustTourStart(); final DateTime dtTourStart = new DateTime(_dtList.get(0).absoluteTime); tourData.setStartHour((short) dtTourStart.getHourOfDay()); tourData.setStartMinute((short) dtTourStart.getMinuteOfHour()); tourData.setStartSecond((short) dtTourStart.getSecondOfMinute()); tourData.setStartYear((short) dtTourStart.getYear()); tourData.setStartMonth((short) dtTourStart.getMonthOfYear()); tourData.setStartDay((short) dtTourStart.getDayOfMonth()); tourData.setWeek(dtTourStart); tourData.setIsDistanceFromSensor(_isDistanceFromSensor); tourData.setDeviceTimeInterval((short) -1); tourData.importRawDataFile = _importFilePath; tourData.setTourImportFilePath(_importFilePath); tourData.createTimeSeries(_dtList, true); tourData.setDeviceModeName(_activitySport); tourData.setCalories(_tourCalories); // after all data are added, the tour id can be created final int[] distanceSerie = tourData.getMetricDistanceSerie(); String uniqueKey; if (_deviceDataReader.isCreateTourIdWithRecordingTime) { /* * 25.5.2009: added recording time to the tour distance for the unique key because tour * export and import found a wrong tour when exporting was done with camouflage speed -> * this will result in a NEW tour */ final int tourRecordingTime = tourData.getTourRecordingTime(); if (distanceSerie == null) { uniqueKey = Integer.toString(tourRecordingTime); } else { final long tourDistance = distanceSerie[(distanceSerie.length - 1)]; uniqueKey = Long.toString(tourDistance + tourRecordingTime); } } else { /* * original version to create tour id */ if (distanceSerie == null) { uniqueKey = Util.UNIQUE_ID_SUFFIX_GARMIN_TCX; } else { uniqueKey = Integer.toString(distanceSerie[distanceSerie.length - 1]); } } final Long tourId = tourData.createTourId(uniqueKey); // check if the tour is already imported if (_tourDataMap.containsKey(tourId) == false) { tourData.computeAltitudeUpDown(); tourData.computeTourDrivingTime(); tourData.computeComputedValues(); final String deviceName = _sport.creatorName; final String majorVersion = _sport.creatorVersionMajor; final String minorVersion = _sport.creatorVersionMinor; tourData.setDeviceId(_deviceDataReader.deviceId); tourData.setDeviceName( _deviceDataReader.visibleName + (deviceName == null ? UI.EMPTY_STRING : UI.SPACE + deviceName)); tourData.setDeviceFirmwareVersion(majorVersion == null // ? UI.EMPTY_STRING : majorVersion + (minorVersion == null // ? UI.EMPTY_STRING : UI.DOT + minorVersion)); // add new tour to other tours _tourDataMap.put(tourId, tourData); } _isImported = true; }
From source file:net.tourbook.device.gpx.GPX_SAX_Handler.java
License:Open Source License
private void finalizeTour() { if (_timeDataList.size() == 0) { // there is not data return;//from www. jav a 2 s . co m } final TimeData firstTimeData = _timeDataList.get(0); // create data object for each tour final TourData tourData = new TourData(); tourData.setTourTitle(_trkName); /* * set tour start date/time */ final DateTime dtTourStart = new DateTime(firstTimeData.absoluteTime); tourData.setStartYear((short) dtTourStart.getYear()); tourData.setStartMonth((short) dtTourStart.getMonthOfYear()); tourData.setStartDay((short) dtTourStart.getDayOfMonth()); tourData.setStartHour((short) dtTourStart.getHourOfDay()); tourData.setStartMinute((short) dtTourStart.getMinuteOfHour()); tourData.setStartSecond((short) dtTourStart.getSecondOfMinute()); tourData.setWeek(tourData.getStartYear(), tourData.getStartMonth(), tourData.getStartDay()); tourData.setDeviceTimeInterval((short) -1); tourData.setTemperatureScale(TourbookDevice.TEMPERATURE_SCALE); tourData.importRawDataFile = _importFilePath; tourData.setTourImportFilePath(_importFilePath); tourData.createTimeSeries(_timeDataList, true); tourData.computeAltitudeUpDown(); tourData.setWayPoints(_wptList); /* * adjust default marker which are created in tourData.createTimeSeries() */ for (final TourMarker tourMarker : tourData.getTourMarkers()) { tourMarker.setVisualPosition(ChartLabel.VISUAL_VERTICAL_BOTTOM_CHART); // disable time/distance tourMarker.setTime(-1); tourMarker.setDistance(-1); } // after all data are added, the tour id can be created final int[] distanceSerie = tourData.getMetricDistanceSerie(); String uniqueKey; if (_deviceDataReader.isCreateTourIdWithRecordingTime) { /* * 23.3.2009: added recording time to the tour distance for the unique key because tour * export and import found a wrong tour when exporting was done with camouflage speed -> * this will result in a NEW tour */ final int tourRecordingTime = tourData.getTourRecordingTime(); if (distanceSerie == null) { uniqueKey = Integer.toString(tourRecordingTime); } else { final long tourDistance = distanceSerie[(distanceSerie.length - 1)]; uniqueKey = Long.toString(tourDistance + tourRecordingTime); } } else { /* * original version to create tour id */ if (distanceSerie == null) { uniqueKey = Util.UNIQUE_ID_SUFFIX_GPX; } else { uniqueKey = Integer.toString(distanceSerie[distanceSerie.length - 1]); } } final Long tourId = tourData.createTourId(uniqueKey); // check if the tour is already imported if (_tourDataMap.containsKey(tourId) == false) { tourData.computeTourDrivingTime(); tourData.computeComputedValues(); tourData.setDeviceId(_deviceDataReader.deviceId); tourData.setDeviceName(_deviceDataReader.visibleName); // add new tour to other tours _tourDataMap.put(tourId, tourData); } _isImported = true; }
From source file:net.tourbook.device.polar.hrm.PolarHRMDataReader.java
License:Open Source License
private void createTourData(final HashMap<Long, TourData> tourDataMap) { // create data object for each tour final TourData tourData = new TourData(); /*/*from www .j av a 2s . co m*/ * set tour start date/time */ final DateTime dtTourStart = new DateTime(_sectionParams.startYear, _sectionParams.startMonth, _sectionParams.startDay, _sectionParams.startHour, _sectionParams.startMinute, _sectionParams.startSecond, 0); tourData.setStartHour((short) dtTourStart.getHourOfDay()); tourData.setStartMinute((short) dtTourStart.getMinuteOfHour()); tourData.setStartSecond((short) dtTourStart.getSecondOfMinute()); tourData.setStartYear((short) dtTourStart.getYear()); tourData.setStartMonth((short) dtTourStart.getMonthOfYear()); tourData.setStartDay((short) dtTourStart.getDayOfMonth()); tourData.setWeek(dtTourStart); tourData.setDeviceTimeInterval((short) _sectionParams.mtInterval); tourData.importRawDataFile = _importFilePath; tourData.setTourImportFilePath(_importFilePath); // tourData.setCalories(_calories); tourData.setRestPulse(_sectionParams.restHR == Integer.MIN_VALUE ? 0 : _sectionParams.restHR); if (_sectionTrip != null) { tourData.setStartDistance(_sectionTrip.odometer == Integer.MIN_VALUE ? 0 : _sectionTrip.odometer); } final ArrayList<TimeData> timeSeries = createTourData10CreateTimeSeries(dtTourStart); createTourData20SetTemperature(tourData, timeSeries); tourData.createTimeSeries(timeSeries, true); createTourData30CreateMarkers(tourData); tourData.computeAltitudeUpDown(); // after all data are added, the tour id can be created final Long tourId = tourData.createTourId(createUniqueId(tourData, Util.UNIQUE_ID_SUFFIX_POLAR_HRM)); // check if the tour is already imported if (tourDataMap.containsKey(tourId) == false) { tourData.computeTourDrivingTime(); tourData.computeComputedValues(); tourData.setDeviceId(deviceId); tourData.setDeviceName(_sectionParams.monitorName); tourData.setDeviceFirmwareVersion(Integer.toString(_hrmVersion)); // add new tour to other tours tourDataMap.put(tourId, tourData); } }
From source file:net.tourbook.device.polartrainer.PolarTrainerSAXHandler.java
License:Open Source License
private void finalizeTour() throws InvalidDeviceSAXException { if (finalizeTour10CreateTimeSlices() == false) { _isImported = false;// w w w.ja v a 2 s . c o m return; } // create data object for each tour final TourData tourData = new TourData(); /* * set tour start date/time */ final DateTime tourStart = _currentExercise.tourStart; tourData.setStartHour((short) tourStart.getHourOfDay()); tourData.setStartMinute((short) tourStart.getMinuteOfHour()); tourData.setStartSecond((short) tourStart.getSecondOfMinute()); tourData.setStartYear((short) tourStart.getYear()); tourData.setStartMonth((short) tourStart.getMonthOfYear()); tourData.setStartDay((short) tourStart.getDayOfMonth()); tourData.setWeek(tourStart); tourData.setDeviceTimeInterval(_currentExercise.timeInterval); tourData.setTemperatureScale(TourbookDevice.TEMPERATURE_SCALE); tourData.importRawDataFile = _importFilePath; tourData.setTourImportFilePath(_importFilePath); tourData.setTourTitle(_currentExercise.tourTitle); tourData.setCalories(_currentExercise.calories); tourData.setRestPulse(_currentExercise.restPulse); tourData.createTimeSeries(_timeSlices, true); finalizeTour20CreateMarkers(tourData); finalizeTour30SetTourType(tourData); tourData.computeAltitudeUpDown(); // after all data are added, the tour id can be created final Long tourId = tourData .createTourId(_device.createUniqueId(tourData, Util.UNIQUE_ID_SUFFIX_POLAR_TRAINER)); // check if the tour is already imported if (_tourDataMap.containsKey(tourId) == false) { tourData.computeTourDrivingTime(); tourData.computeComputedValues(); tourData.setDeviceId(_device.deviceId); tourData.setDeviceName(DEVICE_NAME_POLAR_PERSONALTRAINER); tourData.setDeviceFirmwareVersion(_dataVersion == 1 ? TAG_ROOT_VERSION_1 : UI.EMPTY_STRING); // add new tour to other tours _tourDataMap.put(tourId, tourData); } _isImported = true; }
From source file:net.tourbook.device.sporttracks.FitLogSAXHandler.java
License:Open Source License
private void finalizeTour() { boolean isComputeDrivingTime = true; // create data object for each tour final TourData tourData = new TourData(); /*// w w w . ja v a2s . c om * set tour start date/time */ // DateTime tourDateTime = _currentActivity.trackTourDateTime; // final long trackStartTime = _currentActivity.trackTourStartTime; // if (trackStartTime != Long.MIN_VALUE && trackStartTime < 0) { // // // this case occured, e.g. year was 0002 // tourDateTime = _currentActivity.tourStartTime; // // } else if (tourDateTime == null) { // // // this case can occure when a tour do not have a track // tourDateTime = _currentActivity.tourStartTime; // } final DateTime tourStartTime = _currentActivity.tourStartTime; tourData.setStartHour((short) tourStartTime.getHourOfDay()); tourData.setStartMinute((short) tourStartTime.getMinuteOfHour()); tourData.setStartSecond((short) tourStartTime.getSecondOfMinute()); tourData.setStartYear((short) tourStartTime.getYear()); tourData.setStartMonth((short) tourStartTime.getMonthOfYear()); tourData.setStartDay((short) tourStartTime.getDayOfMonth()); tourData.setWeek(tourStartTime); tourData.setTourTitle(_currentActivity.name); tourData.setTourDescription(_currentActivity.notes); tourData.setTourStartPlace(_currentActivity.location); tourData.setCalories(_currentActivity.calories); /* * weather */ tourData.setWeather(_currentActivity.weatherText); tourData.setWeatherClouds(_weatherId.get(_currentActivity.weatherConditions)); final float weatherTemperature = _currentActivity.weatherTemperature; if (weatherTemperature != Float.MIN_VALUE) { tourData.setTemperatureScale(TourbookDevice.TEMPERATURE_SCALE); tourData.setAvgTemperature((int) (weatherTemperature * TourbookDevice.TEMPERATURE_SCALE)); } tourData.importRawDataFile = _importFilePath; tourData.setTourImportFilePath(_importFilePath); tourData.setDeviceTimeInterval((short) -1); if (_currentActivity.timeSlices.size() == 0) { // tour do not contain a track tourData.setTourDistance(_currentActivity.distance); tourData.setTourRecordingTime(_currentActivity.duration); tourData.setTourDrivingTime(_currentActivity.duration); isComputeDrivingTime = false; tourData.setTourAltUp(_currentActivity.elevationUp); tourData.setTourAltDown(_currentActivity.elevationDown); } else { tourData.createTimeSeries(_currentActivity.timeSlices, false); } // after all data are added, the tour id can be created because it depends on the tour distance final Long tourId = tourData .createTourId(_device.createUniqueId(tourData, Util.UNIQUE_ID_SUFFIX_SPORT_TRACKS_FITLOG)); // check if the tour is already imported if (_tourDataMap.containsKey(tourId) == false) { if (isComputeDrivingTime) { tourData.computeTourDrivingTime(); } tourData.computeAltitudeUpDown(); tourData.computeComputedValues(); if (tourData.pulseSerie == null) { tourData.setAvgPulse(_currentActivity.avgPulse); tourData.setMaxPulse(_currentActivity.maxPulse); } if (tourData.cadenceSerie == null) { tourData.setAvgCadence(_currentActivity.avgCadence); } tourData.setDeviceId(_device.deviceId); tourData.setDeviceName(_device.visibleName); finalizeTour10SetTourType(tourData); finalizeTour20SetTags(tourData); finalizeTour30CreateMarkers(tourData); // add new tour to other tours _tourDataMap.put(tourId, tourData); } // cleanup _currentActivity.timeSlices.clear(); _currentActivity.laps.clear(); _currentActivity.equipmentName.clear(); _isImported = true; }
From source file:net.tourbook.export.gpx.DialogExportTour.java
License:Open Source License
/** * Set filename with the first tour date/time, when tour is merged "<#default>" is displayed *///from w w w. j a v a2s. co m private void setFileName() { // search for the first tour TourData minTourData = null; final long minTourMillis = 0; for (final TourData tourData : _tourDataList) { final DateTime checkingTourDate = TourManager.getTourDateTime(tourData); if (minTourData == null) { minTourData = tourData; } else { final long tourMillis = checkingTourDate.getMillis(); if (tourMillis < minTourMillis) { minTourData = tourData; } } } if (_isMultipleTourAndMultipleFile) { // use default file name for each exported tour _comboFile.setText(Messages.dialog_export_label_DefaultFileName); } else if ((_tourDataList.size() == 1) && (_tourStartIndex != -1) && (_tourEndIndex != -1)) { // display the start date/time final DateTime dtTour = new DateTime(minTourData.getStartYear(), minTourData.getStartMonth(), minTourData.getStartDay(), minTourData.getStartHour(), minTourData.getStartMinute(), minTourData.getStartSecond(), 0); // adjust start time final int startTime = minTourData.timeSerie[_tourStartIndex]; final DateTime tourTime = dtTour.plusSeconds(startTime); _comboFile.setText(UI.format_yyyymmdd_hhmmss(tourTime.getYear(), tourTime.getMonthOfYear(), tourTime.getDayOfMonth(), tourTime.getHourOfDay(), tourTime.getMinuteOfHour(), tourTime.getSecondOfMinute())); } else { // display the tour date/time _comboFile.setText(UI.format_yyyymmdd_hhmmss(minTourData)); } }
From source file:net.tourbook.printing.DialogPrintTour.java
License:Open Source License
/** * Overwrite filename with the first tour date/time when the tour is not merged *//*from w ww. jav a 2 s . co m*/ private void setFileName() { // search for the first tour TourData minTourData = null; final long minTourMillis = 0; for (final TourData tourData : _tourDataList) { final DateTime checkingTourDate = TourManager.getTourDateTime(tourData); if (minTourData == null) { minTourData = tourData; } else { final long tourMillis = checkingTourDate.getMillis(); if (tourMillis < minTourMillis) { minTourData = tourData; } } } if ((_tourDataList.size() == 1) && (_tourStartIndex != -1) && (_tourEndIndex != -1)) { // display the start date/time final DateTime dtTour = new DateTime(minTourData.getStartYear(), minTourData.getStartMonth(), minTourData.getStartDay(), minTourData.getStartHour(), minTourData.getStartMinute(), minTourData.getStartSecond(), 0); final int startTime = minTourData.timeSerie[_tourStartIndex]; final DateTime tourTime = dtTour.plusSeconds(startTime); _comboFile.setText(UI.format_yyyymmdd_hhmmss(tourTime.getYear(), tourTime.getMonthOfYear(), tourTime.getDayOfMonth(), tourTime.getHourOfDay(), tourTime.getMinuteOfHour(), tourTime.getSecondOfMinute())); } else { // display the tour date/time _comboFile.setText(UI.format_yyyymmdd_hhmmss(minTourData)); } }