List of usage examples for org.joda.time MutablePeriod toPeriod
public Period toPeriod()
Period
object. From source file:de.tshw.worktracker.view.TimeEntriesTableModel.java
License:MIT License
public String update(WorkTracker workTracker) { int oldProjectCount = elapsedTimes.size(); HashMap<Project, MutablePeriod> newTimes = new HashMap<>(); for (Project p : workTracker.getProjects()) { newTimes.put(p, new MutablePeriod()); }/* w w w . j a v a2 s . co m*/ MutablePeriod totalTimeToday = new MutablePeriod(); for (WorkLogEntry entry : workTracker.getTodaysWorkLogEntries()) { if (!newTimes.containsKey(entry.getProject())) { newTimes.put(entry.getProject(), new MutablePeriod()); } if (entry.getStartTime().toLocalDate().toDateTimeAtStartOfDay() .equals(LocalDate.now().toDateTimeAtStartOfDay())) { newTimes.get(entry.getProject()).add(entry.getTimeElapsed()); if (!entry.getProject().equals(workTracker.getPauseProject())) { totalTimeToday.add(entry.getTimeElapsed()); } } } WorkLogEntry entry = workTracker.getCurrentLogEntry(); Period period = new Period(entry.getStartTime(), LocalDateTime.now()); newTimes.get(entry.getProject()).add(period); if (!entry.getProject().equals(workTracker.getPauseProject())) { totalTimeToday.add(period); } for (Project p : newTimes.keySet()) { elapsedTimes.put(p, newTimes.get(p).toPeriod()); } this.totalTimeElapsedToday = totalTimeToday.toPeriod(); if (oldProjectCount == elapsedTimes.size()) { this.fireTableRowsUpdated(0, elapsedTimes.size()); } else { this.fireTableDataChanged(); } return periodFormatter.print(this.totalTimeElapsedToday.normalizedStandard()); }
From source file:org.apache.tamaya.jodatime.PeriodConverter.java
License:Apache License
@Override public Period convert(String value, ConversionContext context) { String trimmed = Objects.requireNonNull(value).trim(); context.addSupportedFormats(PeriodConverter.class, "PyYmMwWdDThHmMsS"); context.addSupportedFormats(PeriodConverter.class, "Pyyyy-mm-ddThh:mm:ss"); MutablePeriod result = null; PeriodParser format = null;//from w w w. ja v a 2s . co m if (isISOFormat(trimmed)) { format = ISO_FORMAT; } else if (isAlternativeFormat(trimmed)) { format = ALTERNATIVE_FORMAT; } if (format != null) { result = new MutablePeriod(); int parseResult = format.parseInto(result, trimmed, 0, Locale.ENGLISH); if (parseResult < 0) { result = null; } } return result != null ? result.toPeriod() : null; }
From source file:org.openehr.rm.datatypes.quantity.datetime.DvDuration.java
License:LGPL
/** * Helper method to negate a copy of period * // w w w .j ava2s .c o m * @param mPeriod * @return a negated copy of period */ static Period negatePeriod(Period period) { MutablePeriod mPeriod = period.toMutablePeriod(); mPeriod.setYears(-mPeriod.getYears()); mPeriod.setMonths(-mPeriod.getMonths()); mPeriod.setWeeks(-mPeriod.getWeeks()); mPeriod.setDays(-mPeriod.getDays()); mPeriod.setHours(-mPeriod.getHours()); mPeriod.setMinutes(-mPeriod.getMinutes()); mPeriod.setSeconds(-mPeriod.getSeconds()); mPeriod.setMillis(-mPeriod.getMillis()); return mPeriod.toPeriod(); }
From source file:org.phenotips.data.internal.controller.MedicationController.java
License:Open Source License
@Override public PatientData<Medication> load(Patient patient) { try {/*from w w w .j av a 2 s . com*/ XWikiDocument doc = (XWikiDocument) this.documentAccessBridge.getDocument(patient.getDocument()); List<BaseObject> data = doc.getXObjects(Medication.CLASS_REFERENCE); if (data == null || data.isEmpty()) { this.logger.debug("No medication data for patient [{}]", patient.getDocument()); return null; } List<Medication> result = new LinkedList<>(); for (BaseObject medication : data) { if (medication == null) { continue; } MutablePeriod p = new MutablePeriod(); p.setYears(medication.getIntValue(DURATION_YEARS)); p.setMonths(medication.getIntValue(DURATION_MONTHS)); result.add(new Medication(medication.getStringValue(Medication.NAME), medication.getStringValue(Medication.GENERIC_NAME), medication.getStringValue(Medication.DOSE), medication.getStringValue(Medication.FREQUENCY), p.toPeriod(), medication.getStringValue(Medication.EFFECT), medication.getLargeStringValue(Medication.NOTES))); } if (!result.isEmpty()) { return new IndexedPatientData<Medication>(DATA_NAME, result); } } catch (Exception ex) { this.logger.error("Could not find requested document or some unforeseen" + " error has occurred during controller loading ", ex.getMessage()); } return null; }