List of usage examples for org.joda.time DateTime getMonthOfYear
public int getMonthOfYear()
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 2s. c o 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 w w w . jav a2 s . co 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.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()); }//w ww. j a v a 2s . com 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 w w .jav a 2 s.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.web.workspace.workflow.appointment.repeat.RepeatOnDaysOfMonthEditor.java
License:Open Source License
/** * Returns the expression./*w w w . ja v a2s . c om*/ * * @return the expression, or {@code null} if the expression is invalid */ @Override public RepeatExpression getExpression() { List<Integer> list = new ArrayList<Integer>(); Date startTime = getStartTime(); if (startTime != null) { for (int i = 0; i < days.length; ++i) { boolean selected = days[i].isSelected(); if (selected) { list.add(i + 1); } } boolean last = lastDay.isSelected(); if (!list.isEmpty() || last) { DayOfMonth dayOfMonth = DayOfMonth.days(list, last); DateTime time = new DateTime(startTime); return new CronRepeatExpression(startTime, dayOfMonth, Month.every(time.getMonthOfYear(), interval.getInt())); } } return null; }
From source file:org.openvpms.web.workspace.workflow.appointment.repeat.RepeatOnNthDayEditor.java
License:Open Source License
/** * Returns the expression.//from w w w. j a v a2 s . c o m * * @return the expression, or {@code null} if the expression is invalid */ @Override public RepeatExpression getExpression() { Date startTime = getStartTime(); DayOfWeek dayOfWeek = getDayOfWeek(); if (startTime != null && dayOfWeek != null) { DateTime time = new DateTime(startTime); return new CronRepeatExpression(startTime, Month.every(time.getMonthOfYear(), getInterval()), dayOfWeek); } return null; }
From source file:org.patientview.service.impl.MessageManagerImpl.java
License:Open Source License
private String getFriendlyDateTime(Date date) { DateTime now = new DateTime(); DateTime dateTime = new DateTime(date); if (dateTime.getYear() == now.getYear() && dateTime.getMonthOfYear() == now.getMonthOfYear() && dateTime.getDayOfWeek() == now.getDayOfWeek()) { return SHORT_DAY_FORMAT.format(date); } else {/* w ww. j a v a2 s . c o m*/ return DATE_FORMAT.format(date); } }
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 //from w w w.jav a 2 s . 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.projectbuendia.client.ui.patientcreation.PatientCreationActivity.java
License:Apache License
@Override protected void onCreateImpl(Bundle savedInstanceState) { super.onCreateImpl(savedInstanceState); App.getInstance().inject(this); CrudEventBus crudEventBus = mCrudEventBusProvider.get(); mController = new PatientCreationController(new MyUi(), crudEventBus, mModel); mAlertDialog = new AlertDialog.Builder(this).setIcon(android.R.drawable.ic_dialog_info) .setTitle(R.string.title_add_patient_cancel) .setPositiveButton("Yes", new DialogInterface.OnClickListener() { @Override/*from ww w .jav a2 s . c om*/ public void onClick(DialogInterface dialog, int i) { finish(); } }).setNegativeButton("No", null).create(); setContentView(R.layout.activity_patient_creation); ButterKnife.inject(this); DateTime now = DateTime.now(); mAdmissionDateSetListener = new DateSetListener(mAdmissionDate, LocalDate.now()); mAdmissionDatePickerDialog = new DatePickerDialog(this, mAdmissionDateSetListener, now.getYear(), now.getMonthOfYear() - 1, now.getDayOfMonth()); mAdmissionDatePickerDialog.setTitle(R.string.admission_date_picker_title); mAdmissionDatePickerDialog.getDatePicker().setCalendarViewShown(false); mSymptomsOnsetDateSetListener = new DateSetListener(mSymptomsOnsetDate, null); mSymptomsOnsetDatePickerDialog = new DatePickerDialog(this, mSymptomsOnsetDateSetListener, now.getYear(), now.getMonthOfYear() - 1, now.getDayOfMonth()); mSymptomsOnsetDatePickerDialog.setTitle(R.string.symptoms_onset_date_picker_title); mSymptomsOnsetDatePickerDialog.getDatePicker().setCalendarViewShown(false); mLocationSelectedCallback = new AssignLocationDialog.LocationSelectedCallback() { @Override public boolean onNewTentSelected(String newTentUuid) { mLocationUuid = newTentUuid; updateLocationUi(); return true; } }; // Pre-populate admission date with today. mAdmissionDate.setText(Dates.toMediumString(DateTime.now().toLocalDate())); }
From source file:org.projectforge.web.address.BirthdayEventsProvider.java
License:Open Source License
/** * @see org.projectforge.web.calendar.MyFullCalendarEventsProvider#buildEvents(org.joda.time.DateTime, org.joda.time.DateTime) *//*from w ww. jav a 2s . c o m*/ @Override protected void buildEvents(final DateTime start, final DateTime end) { if (filter.isShowBirthdays() == false) { // Don't show birthdays. return; } DateTime from = start; if (start.getMonthOfYear() == Calendar.MARCH && start.getDayOfMonth() == 1) { from = start.minusDays(1); } final Set<BirthdayAddress> set = addressDao.getBirthdays(from.toDate(), end.toDate(), 1000, true); for (final BirthdayAddress birthdayAddress : set) { final AddressDO address = birthdayAddress.getAddress(); final int month = birthdayAddress.getMonth() + 1; final int dayOfMonth = birthdayAddress.getDayOfMonth(); DateTime date = getDate(from, end, month, dayOfMonth); // February, 29th fix: if (date == null && month == Calendar.FEBRUARY + 1 && dayOfMonth == 29) { date = getDate(from, end, month + 1, 1); } if (date == null && WebConfiguration.isDevelopmentMode() == true) { log.info("Date " + birthdayAddress.getDayOfMonth() + "/" + (birthdayAddress.getMonth() + 1) + " not found between " + from + " and " + end); continue; } else { if (dataProtection == false && date != null) { birthdayAddress.setAge(date.toDate()); } } final Event event = new Event().setAllDay(true); event.setClassName(EVENT_CLASS_NAME); final String id = "" + address.getId(); event.setId(id); event.setStart(date); final StringBuffer buf = new StringBuffer(); if (dataProtection == false) { // Birthday is not visible for all users (age == 0). buf.append(DateTimeFormatter.instance().getFormattedDate(address.getBirthday(), DateFormats.getFormatString(DateFormatType.DATE_SHORT))).append(" "); } buf.append(address.getFirstName()).append(" ").append(address.getName()); if (dataProtection == false && birthdayAddress.getAge() > 0) { // Birthday is not visible for all users (age == 0). buf.append(" (").append(birthdayAddress.getAge()).append(" ").append(getString("address.age.short")) .append(")"); } event.setTitle(buf.toString()); if (birthdayAddress.isFavorite() == true) { // Colors of events of birthdays of favorites (for default color see CalendarPanel): event.setBackgroundColor("#06790E"); event.setBorderColor("#06790E"); event.setTextColor("#FFFFFF"); } events.put(id, event); } }