List of usage examples for org.joda.time DateTime withSecondOfMinute
public DateTime withSecondOfMinute(int second)
From source file:com.arpnetworking.kairosdb.aggregators.MovingWindowAggregator.java
License:Apache License
/** * For YEARS, MONTHS, WEEKS, DAYS: Computes the timestamp of the first * millisecond of the day of the timestamp. For HOURS, Computes the timestamp of * the first millisecond of the hour of the timestamp. For MINUTES, Computes the * timestamp of the first millisecond of the minute of the timestamp. For * SECONDS, Computes the timestamp of the first millisecond of the second of the * timestamp. For MILLISECONDS, returns the timestamp * * @param timestamp Timestamp in milliseconds to use as a basis for range alignment * @return timestamp aligned to the configured sampling unit */// w w w .j ava 2s . c om @SuppressWarnings("fallthrough") @SuppressFBWarnings("SF_SWITCH_FALLTHROUGH") private long alignRangeBoundary(final long timestamp) { DateTime dt = new DateTime(timestamp, _timeZone); final TimeUnit tu = m_sampling.getUnit(); switch (tu) { case YEARS: dt = dt.withDayOfYear(1).withMillisOfDay(0); break; case MONTHS: dt = dt.withDayOfMonth(1).withMillisOfDay(0); break; case WEEKS: dt = dt.withDayOfWeek(1).withMillisOfDay(0); break; case DAYS: dt = dt.withHourOfDay(0); case HOURS: dt = dt.withMinuteOfHour(0); case MINUTES: dt = dt.withSecondOfMinute(0); case SECONDS: default: dt = dt.withMillisOfSecond(0); break; } return dt.getMillis(); }
From source file:com.boha.monitor.utilx.ListUtil.java
public static ResponseDTO getProjectStatusData(EntityManager em, Integer projectID, int days) throws DataException { long s = System.currentTimeMillis(); if (days == 0) { days = 30;/*from w w w .j a v a 2 s . c om*/ } ResponseDTO resp = new ResponseDTO(); try { Project p = em.find(Project.class, projectID); ProjectDTO project = new ProjectDTO(p); DateTime now = new DateTime(); DateTime then = now.minusDays(days); then = then.withHourOfDay(0); then = then.withMinuteOfHour(0); then = then.withSecondOfMinute(0); project.setProjectTaskList( ListUtil.getProjectStatus(em, projectID, then.toDate(), now.toDate()).getProjectTaskList()); project.setPhotoUploadList( getPhotosByProject(em, projectID, then.toDate(), now.toDate()).getPhotoUploadList()); resp.setProjectList(new ArrayList<>()); resp.getProjectList().add(project); long e = System.currentTimeMillis(); log.log(Level.INFO, "############---------- project data retrieved: {0} seconds", Elapsed.getElapsed(s, e)); } catch (OutOfMemoryError e) { log.log(Level.SEVERE, "Failed", e); throw new DataException("Failed to get project data: OUT OF MEMORY!\n"); } return resp; }
From source file:com.github.dbourdette.otto.source.TimeFrame.java
License:Apache License
private DateTime thirtySeconds(DateTime dateTime) { dateTime = dateTime.withMillisOfSecond(0); if (dateTime.getSecondOfMinute() < 30) { return dateTime.withSecondOfMinute(0); } else {/*from w w w . j av a 2s.c om*/ return dateTime.withSecondOfMinute(30); } }
From source file:com.github.dbourdette.otto.source.TimeFrame.java
License:Apache License
private DateTime oneMinute(DateTime dateTime) { dateTime = dateTime.withMillisOfSecond(0); return dateTime.withSecondOfMinute(0); }
From source file:com.github.dbourdette.otto.source.TimeFrame.java
License:Apache License
private DateTime fiveMinutes(DateTime dateTime) { dateTime = dateTime.withMillisOfSecond(0); dateTime = dateTime.withSecondOfMinute(0); int minutes = dateTime.getMinuteOfHour(); return dateTime.withMinuteOfHour(minutes / 5 * 5); }
From source file:com.github.dbourdette.otto.source.TimeFrame.java
License:Apache License
private DateTime thirtyMinutes(DateTime dateTime) { dateTime = dateTime.withMillisOfSecond(0); dateTime = dateTime.withSecondOfMinute(0); if (dateTime.getMinuteOfHour() < 30) { return dateTime.withMinuteOfHour(0); } else {/* w w w .j a v a2s.co m*/ return dateTime.withMinuteOfHour(30); } }
From source file:com.github.dbourdette.otto.source.TimeFrame.java
License:Apache License
private DateTime oneHour(DateTime dateTime) { dateTime = dateTime.withMillisOfSecond(0); dateTime = dateTime.withSecondOfMinute(0); return dateTime.withMinuteOfHour(0); }
From source file:com.github.dbourdette.otto.source.TimeFrame.java
License:Apache License
private DateTime twelveHours(DateTime dateTime) { dateTime = dateTime.withMillisOfSecond(0); dateTime = dateTime.withSecondOfMinute(0); dateTime = dateTime.withMinuteOfHour(0); if (dateTime.getHourOfDay() < 12) { return dateTime.withHourOfDay(0); } else {/*w w w. j a va2s . c o m*/ return dateTime.withHourOfDay(12); } }
From source file:com.github.dbourdette.otto.source.TimeFrame.java
License:Apache License
private DateTime oneDay(DateTime dateTime) { dateTime = dateTime.withMillisOfSecond(0); dateTime = dateTime.withSecondOfMinute(0); dateTime = dateTime.withMinuteOfHour(0); return dateTime.withHourOfDay(0); }
From source file:com.marand.thinkmed.medications.therapy.impl.TherapyUpdaterImpl.java
License:Open Source License
private <M extends TherapyDto> Pair<MedicationOrderComposition, MedicationInstructionInstruction> modifyTherapy( final String patientId, final M therapy, final TherapyChangeReasonDto changeReason, final String centralCaseId, @Nullable final String careProviderId, final NamedExternalDto prescriber, final boolean therapyAlreadyStarted, final boolean significantChange, final DateTime when, final Locale locale) { final DateTime updateTime = new DateTime(when.withSecondOfMinute(0).withMillisOfSecond(0)); therapyDisplayProvider.fillDisplayValues(therapy, true, true, locale); final MedicationOrderComposition oldComposition = medicationsOpenEhrDao .loadMedicationOrderComposition(patientId, therapy.getCompositionUid()); final MedicationInstructionInstruction oldInstruction = MedicationsEhrUtils .getMedicationInstructionByEhrName(oldComposition, therapy.getEhrOrderName()); final DateTime oldTherapyStart = DataValueUtils .getDateTime(oldInstruction.getOrder().get(0).getMedicationTiming().getStartDate()); //noinspection unchecked final MedicationToEhrConverter<M> converter = (MedicationToEhrConverter<M>) MedicationConverterSelector .getConverter(therapy);/*ww w . ja v a 2s.c om*/ final Pair<MedicationOrderComposition, MedicationInstructionInstruction> savedTherapy; if (therapyAlreadyStarted && significantChange) { //create new instruction final MedicationOrderComposition newComposition = MedicationsEhrUtils .createEmptyMedicationOrderComposition(); final MedicationInstructionInstruction newInstruction = converter.createInstructionFromTherapy(therapy); newComposition.getMedicationDetail().getMedicationInstruction().add(newInstruction); //link new instruction to old instruction final Link linkToExisting = OpenEhrRefUtils.getLinkToTdoTarget("update", EhrLinkType.UPDATE.getName(), oldComposition, oldInstruction); newInstruction.getLinks().add(linkToExisting); //link new instruction to first instruction linkToOriginInstruction(oldComposition, oldInstruction, newInstruction); //new therapy must keep FOLLOW links from old therapy final List<Link> followLinks = MedicationsEhrUtils.getLinksOfType(oldInstruction, EhrLinkType.FOLLOW); newInstruction.getLinks().addAll(followLinks); //new therapy must keep links to medication on ADMISSION final List<Link> admissionLinks = MedicationsEhrUtils.getLinksOfType(oldInstruction, EhrLinkType.MEDICATION_ON_ADMISSION); newInstruction.getLinks().addAll(admissionLinks); rewriteSelfAdministeringType(newInstruction, oldInstruction); //add SCHEDULE and START actions final DateTime therapyStart = therapy.getStart().isAfter(when) ? therapy.getStart() : when; MedicationsEhrUtils.addMedicationActionTo(newComposition, MedicationActionEnum.SCHEDULE, prescriber, when); MedicationsEhrUtils.addMedicationActionTo(newComposition, MedicationActionEnum.START, prescriber, therapyStart); addMedicationOrderCompositionEventContext(newComposition, prescriber, centralCaseId, careProviderId, when); final String newCompositionUid = medicationsOpenEhrDao .saveNewMedicationOrderComposition(patientId, newComposition).getUid().getValue(); newComposition.setUid(OpenEhrRefUtils.getObjectVersionId(newCompositionUid)); newInstruction.setName(DataValueUtils.getText("Medication instruction")); //fix FOLLOW links that point to this therapy fixLinksToTherapy(patientId, oldComposition, oldInstruction, newComposition, newInstruction, EhrLinkType.FOLLOW); //old composition final DateTime oldCompositionStopDate = updateTime.isBefore(therapy.getStart()) ? updateTime : therapy.getStart(); if (therapy.getStart().isBefore(oldTherapyStart)) { throw new UserWarning("Cannot edit therapy in the past."); } for (final MedicationInstructionInstruction.OrderActivity orderActivity : oldInstruction.getOrder()) { orderActivity.getMedicationTiming().setStopDate(DataValueUtils.getDateTime(oldCompositionStopDate)); } //only when client time is not synced if (oldCompositionStopDate.isBefore(oldTherapyStart)) { for (final MedicationInstructionInstruction.OrderActivity orderActivity : oldInstruction .getOrder()) { orderActivity.getMedicationTiming() .setStartDate(orderActivity.getMedicationTiming().getStopDate()); } } MedicationsEhrUtils.addMedicationActionTo(oldComposition, MedicationActionEnum.COMPLETE, prescriber, changeReason, when); medicationsOpenEhrDao.modifyMedicationOrderComposition(patientId, oldComposition); savedTherapy = Pair.of(newComposition, newInstruction); } else { converter.fillInstructionFromTherapy(oldInstruction, therapy); if (therapyAlreadyStarted) // and insignificantChange { oldInstruction.getOrder().forEach( o -> o.getMedicationTiming().setStartDate(DataValueUtils.getDateTime(oldTherapyStart))); } else // fix start { final MedicationActionAction startAction = medicationsBo.getInstructionAction(oldComposition, oldInstruction, MedicationActionEnum.START, null); startAction.setTime(DataValueUtils.getDateTime(updateTime)); } final boolean therapySuspended = medicationsBo.isTherapySuspended(oldComposition, oldInstruction); if (therapySuspended) { MedicationsEhrUtils.addMedicationActionTo(oldComposition, MedicationActionEnum.REISSUE, prescriber, when); } MedicationsEhrUtils.addMedicationActionTo(oldComposition, MedicationActionEnum.MODIFY_EXISTING, prescriber, changeReason, when); MedicationsEhrUtils.visitEhrBean(oldInstruction, prescriber, when); medicationsOpenEhrDao.modifyMedicationOrderComposition(patientId, oldComposition); savedTherapy = Pair.of(oldComposition, oldInstruction); } handleTherapyTasksOnModify(patientId, therapy, savedTherapy.getSecond(), TherapyIdUtils.createTherapyId(savedTherapy.getFirst(), savedTherapy.getSecond()), when); return savedTherapy; }