List of usage examples for org.joda.time DateTime getDayOfMonth
public int getDayOfMonth()
From source file:org.openehr.rm.datatypes.quantity.datetime.DvDateTimeParser.java
License:LGPL
public static DateTime defaultDate() { DateTime date = new DateTime(); return new DateTime(date.getYear(), date.getMonthOfYear(), date.getDayOfMonth(), 0, 0, 0, 0); }
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 * /*w ww . ja va 2s .co 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.openlmis.core.model.RnRForm.java
License:Open Source License
private static boolean isMissed(Period period) { DateTime today = new DateTime(LMISApp.getInstance().getCurrentTimeMillis()); DateTime periodEnd = period.getEnd(); int monthOffset = DateUtil.calculateMonthOffset(today, periodEnd); if (monthOffset > 0 || (monthOffset == 0 && today.getDayOfMonth() >= Period.INVENTORY_END_DAY_NEXT)) { return true; }/*from www . j a va2s. c o m*/ return false; }
From source file:org.openlmis.core.utils.DateUtil.java
License:Open Source License
public static Period generateRnRFormPeriodBy(Date generateDate) { DateTime dateTime = new DateTime(generateDate); Period period = new Period(dateTime); if (isInSubmitDates(dateTime.getDayOfMonth())) { return period.previous(); }/* w ww . ja v a2s .c o m*/ return period; }
From source file:org.openmrs.mobile.activities.addeditvisit.AddEditVisitFragment.java
License:Open Source License
private void createVisitDatePicker(DateTime dateTime, long maxDate, boolean startDate) { if (context == null) { return;//from ww w.ja v a 2 s. c o m } int currentYear = dateTime.getYear(); int currentMonth = dateTime.getMonthOfYear() - 1; int currentDay = dateTime.getDayOfMonth(); DatePickerDialog mDatePicker = new DatePickerDialog(context, (DatePicker datepicker, int selectedyear, int selectedmonth, int selectedday) -> { if (startDate) { presenter.getVisit().setStartDatetime( DateUtils.constructDate(selectedyear, selectedmonth, selectedday)); visitStartDateInput .setText(DateUtils.convertTime(presenter.getVisit().getStartDatetime().getTime(), DateUtils.OPEN_MRS_REQUEST_PATIENT_FORMAT)); } else { presenter.getVisit() .setStopDatetime(DateUtils.constructDate(selectedyear, selectedmonth, selectedday)); visitEndDateInput .setText(DateUtils.convertTime(presenter.getVisit().getStopDatetime().getTime(), DateUtils.OPEN_MRS_REQUEST_PATIENT_FORMAT)); } }, currentYear, currentMonth, currentDay); if (maxDate > 0) mDatePicker.getDatePicker().setMaxDate(maxDate); mDatePicker.show(); }
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>// www .j av a 2s . 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>/* w w w. j av a 2s.c om*/ * 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.opentestsystem.delivery.testadmin.persistence.validator.FacilityAvailabilityValidator.java
License:Open Source License
@Override public void validate(final Object target, final Errors errors, final Object... validationHints) { // execute JSR-303 validations (annotations) super.validate(target, errors, validationHints); final DateTime now = new DateTime(); String errorLabel = "time period"; // validate business rules // find facility availabilities for this facility final FacilityAvailability favailability = (FacilityAvailability) target; Sb11Entity institutionEntity = null; if (StringUtils.isNotBlank(favailability.getInstitutionId())) { institutionEntity = this.testRegPersister.findById(favailability.getInstitutionId(), FormatType.INSTITUTION); } else if (StringUtils.isNotBlank(favailability.getInstitutionIdentifier()) && StringUtils.isNotBlank(favailability.getStateAbbreviation())) { institutionEntity = this.sb11EntityService.findByEntityIdAndStateAbbreviation( favailability.getInstitutionIdentifier(), favailability.getStateAbbreviation(), HierarchyLevel.INSTITUTION.getEntityClass()); }/*from w w w. j a v a 2 s .c o m*/ if (institutionEntity == null && StringUtils.isNotBlank(favailability.getInstitutionIdentifier()) && StringUtils.isNotBlank(favailability.getStateAbbreviation())) { errors.rejectValue("institutionIdentifier", favailability.getInstitutionIdentifier(), "Institution identifier " + favailability.getInstitutionIdentifier() + " not found in the database"); } else if (institutionEntity != null) { favailability.setInstitutionId(institutionEntity.getId()); } if (favailability.getStatus() == Availability.AVAILABLE) { errorLabel = "testing slot"; if (!CollectionUtils.isEmpty(favailability.getFacilityTimes())) { for (final FacilityTimeSlot fts : favailability.getFacilityTimes()) { if (CollectionUtils.isEmpty(fts.getSeatConfigurations())) { errors.rejectValue("facilityTimes", favailability.getInstitutionIdentifier(), "At least one seat configuration must be added for testing slot"); } } } if (favailability.getFromDate() != null && favailability.getToDate() != null) { final List<FacilityAvailability> availabilities = this.facilityAvailabilityService .getAvailabilities(favailability.getFacilityId()); for (final FacilityAvailability fa : availabilities) { if (favailability.getId() != null && favailability.getId().equals(fa.getId())) { // do not validate already saved availability continue; } if (favailability.getFromDate().isAfter(fa.getFromDate()) && favailability.getFromDate().isBefore(fa.getToDate()) || favailability.getToDate().isAfter(fa.getFromDate()) && favailability.getToDate().isBefore(fa.getToDate())) { // add error errors.rejectValue("fromDate", null, "From date and To date overlaps with from and to date of another facility availability"); break; } if (favailability.getFromDate().isEqual(fa.getFromDate()) || favailability.getFromDate().isEqual(fa.getToDate()) || favailability.getToDate().isEqual(fa.getFromDate()) || favailability.getToDate().isEqual(fa.getFromDate())) { // add error errors.rejectValue("fromDate", null, "From date and To date overlaps with from and to date of another facility availability"); break; } // check if from date and to date encompass other dates if (favailability.getFromDate().isBefore(fa.getFromDate()) && favailability.getToDate().isAfter(fa.getToDate())) { // add error errors.rejectValue("fromDate", null, "From date and To date overlaps with from and to date of another facility availability"); break; } } } } if (!CollectionUtils.isEmpty(favailability.getFacilityTimes())) { int index = 0; for (final FacilityTimeSlot ftcurrent : favailability.getFacilityTimes()) { final TimeSlot currentTS = ftcurrent.getTimeSlot(); if (currentTS.getStartTime() == null || currentTS.getEndTime() == null) { // don't validate if it is null, there will already be bean validation error continue; } if (favailability.getFromDate() != null && favailability.getFromDate().getDayOfMonth() == now.getDayOfMonth() && favailability.getFromDate().getMonthOfYear() == now.getMonthOfYear() && favailability.getFromDate().getYear() == now.getYear() && now.isAfter(currentTS.getStartTime())) { // add error errors.rejectValue("facilityTimes", null, "Start time cannot be earlier than current time for today's date"); } if (currentTS.getStartTime().isEqual(currentTS.getEndTime())) { // add error errors.rejectValue("facilityTimes", null, "Start time and End time of " + errorLabel + " cannot be same"); } int subindex = 0; if (errors.hasErrors()) { break; } for (final FacilityTimeSlot ft : favailability.getFacilityTimes()) { final TimeSlot ts = ft.getTimeSlot(); if (currentTS.compareTo(ts) != 0) { if (currentTS.getStartTime().isAfter(ts.getStartTime()) && currentTS.getStartTime().isBefore(ts.getEndTime()) || currentTS.getEndTime().isAfter(ts.getStartTime()) && currentTS.getEndTime().isBefore(ts.getEndTime())) { // add error errors.rejectValue("facilityTimes", null, "Start time and End time of " + errorLabel + " overlaps with start and end time of another " + errorLabel); break; } if (currentTS.getStartTime().isEqual(ts.getStartTime()) || currentTS.getEndTime().isEqual(ts.getEndTime())) { // add error errors.rejectValue("facilityTimes", null, "Start time and End time of " + errorLabel + " overlaps with start and end time of another " + errorLabel); break; } if (currentTS.getStartTime().isBefore(ts.getStartTime()) && currentTS.getEndTime().isAfter(ts.getEndTime())) { // add error errors.rejectValue("facilityTimes", null, "Start time and End time of " + errorLabel + " overlaps with start and end time of another " + errorLabel); break; } } else { // add error if (index != subindex) { errors.rejectValue("facilityTimes", null, "Start time and End time of " + errorLabel + " overlaps with start and end time of another " + errorLabel); break; } } subindex += 1; } if (errors.hasErrors()) { break; } index += 1; } } }
From source file:org.opentestsystem.delivery.testadmin.scheduling.Scheduler.java
License:Open Source License
private Schedule generateScheduleStructure(final Schedule inSchedule, final Map<String, FacilityData> facilityData) { // build out the full Schedule structure // Create a List of ScheduledDay objects, one object for each day in the schedule // Each ScheduledDay object contains a List of ScheduledFacility objects, one for each Facility for this // institution // Each ScheduledFacility contains a list of ScheduledTimeSlots which are based upon the FacilityTimeSlot List // in each FacilityAvailability object // Each ScheduledTimeSlot contains a List of ScheduledSeat objects which are based off of the SeatConfigurations // setup in each FacilityTimeSlot Schedule scheduled = null;/*from w ww .j ava2s .c o m*/ try { scheduled = (Schedule) inSchedule.clone(); } catch (CloneNotSupportedException e) { throw new ScheduleException("Failed to clone schedule object, cannot generate schedule ", e); } TreeMap<DateTime, ScheduledDay> scheduledDaysMap = new TreeMap<DateTime, ScheduledDay>(); DateTime scheduleStart = scheduled.getStartDate(); DateTime scheduleEnd = scheduled.getEndDate(); DateTime curTime = scheduleStart; // build all the ScheduledDay objects for this schedule while (curTime.isBefore(scheduleEnd) || curTime.equals(scheduleEnd)) { if (scheduled.isDoNotScheduleWeekends()) { if (curTime.getDayOfWeek() <= DateTimeConstants.FRIDAY) { ScheduledDay sday = new ScheduledDay(); sday.setDay(curTime); scheduledDaysMap.put(curTime, sday); } } else { ScheduledDay sday = new ScheduledDay(); sday.setDay(curTime); scheduledDaysMap.put(curTime, sday); } curTime = curTime.plusDays(1); } // go ahead and set the ScheduledDay objects into the schedule scheduled.setScheduledDays(new ArrayList<ScheduledDay>(scheduledDaysMap.values())); // iterate through all the FacilityData objects we have // each FacilityData has a Facility and a List of FacilityAvailabilities // Need to create a ScheduledFacility for each Facility for each ScheduledDay, // The ScheduledFacility has a list of ScheduledTimeSlots that need to be generated based upon // the FacilityAvailability objects which state from and to time. Basically, we need to match the date of the // ScheduledDay to the from->to range to ensure that the date of the current ScheduledDay falls in there. for (Map.Entry<String, FacilityData> entry : facilityData.entrySet()) { FacilityData facilData = entry.getValue(); List<FacilityAvailability> availabilities = facilData.getAvailabilities(); Facility facility = facilData.getFacility(); // ensure that the seats are generated from the configurations facility.createSeatsFromConfiguration(); for (FacilityAvailability avail : availabilities) { DateTime from = avail.getFromDate(); DateTime to = avail.getToDate(); List<FacilityTimeSlot> facilityTimeSlots = avail.getFacilityTimes(); // iterate through ScheduledDays // if the day is in the range for the facility availability, then create a ScheduledFacility object // for that ScheduledDay for (DateTime schedDate : scheduledDaysMap.keySet()) { if ((from.isEqual(schedDate) || from.isBefore(schedDate)) && (to.isEqual(schedDate) || to.isAfter(schedDate))) { ScheduledFacility schedFacil = new ScheduledFacility(facility); // generate scheduled time slots for scheduledFacility for (FacilityTimeSlot slot : facilityTimeSlots) { slot.createSeatsFromConfiguration(); ScheduledTimeSlot schedSlot = new ScheduledTimeSlot(slot.getTimeSlot()); // create scheduled seats in slot for (SeatConfiguration seatConfig : slot.getSeatConfigurations()) { for (Seat seat : seatConfig.getSeats()) { schedSlot.addSeat(new ScheduledSeat(seat)); } } // modify the date on the ScheduledTimeSlot to have the correct date (from schedDate) to go // along with the specified time (from schedSlot) // This will allow for correct ordering of time slots DateTime newStartDate = new DateTime(schedDate.getYear(), schedDate.getMonthOfYear(), schedDate.getDayOfMonth(), schedSlot.getStartTime().getHourOfDay(), schedSlot.getStartTime().getMinuteOfHour()); DateTime newEndDate = new DateTime(schedDate.getYear(), schedDate.getMonthOfYear(), schedDate.getDayOfMonth(), schedSlot.getEndTime().getHourOfDay(), schedSlot.getEndTime().getMinuteOfHour()); schedSlot.setStartTime(newStartDate); schedSlot.setEndTime(newEndDate); schedFacil.addTimeSlot(schedSlot); } scheduledDaysMap.get(schedDate).addFacility(schedFacil); } } } } scheduled.generateOrderedTimeSlots(); return scheduled; }
From source file:org.openvpms.archetype.rules.workflow.FreeSlotIterator.java
License:Open Source License
/** * Returns a schedule start or end time, in milliseconds. * * @param date the date/time//from ww w. j a v a 2 s .com * @return the time, in milliseconds, or {@code -1} if the date is {@code null} or is 00:00 or 24:00 */ private long getScheduleTime(Date date) { long result = -1; if (date != null) { DateTime dateTime = new DateTime(date); if (dateTime.getDayOfMonth() < 2) { // 24 hour schedule represented as 1970-02-01 0:0:0 result = dateTime.getMillisOfDay(); if (result == 0) { result = -1; } } } return result; }