List of usage examples for org.joda.time Duration toPeriod
public Period toPeriod()
From source file:com.kopysoft.chronos.adapter.clock.PayPeriodAdapterList.java
License:Open Source License
@Override public View getView(int i, View view, ViewGroup viewGroup) { RowElement curr = new RowElement(gContext, 10, 15, 15, 10); TextView left = curr.left();//from ww w.ja va 2 s . c om TextView right = curr.right(); TextView center = curr.center(); //Reset current view center.setText(""); left.setText(""); Duration dur = getTime(getItem(i), true); if (enableLog) Log.d(TAG, "Dur Total: " + dur.getMillis()); DateTimeFormatter fmt = DateTimeFormat.forPattern("E, MMM d, yyyy"); String time = fmt.print(gPunchesByDay.getDays().get(i)); //String time = String.format("Hours %d:%02d ", dur.toPeriod().getHours(), dur.toPeriod().getMinutes()); left.setText(time); //center.setTypeface(null, Typeface.ITALIC); if (dur.getMillis() >= 0) { time = String.format("%02d:%02d ", dur.toPeriod().getHours(), dur.toPeriod().getMinutes()); right.setText(time); } else { right.setText("--:-- "); } return curr; }
From source file:com.kopysoft.chronos.lib.Email.java
License:Open Source License
public String getBriefView() { String retString = ""; List<DateTime> dates = punchTable.getDays(); Chronos chron = new Chronos(gContext); Duration totalDuration = new Duration(0); for (DateTime date : dates) { DateTimeFormatter fmt = DateTimeFormat.forPattern("E, MMM d, yyyy"); String time = fmt.print(date); Duration dur = PayPeriodAdapterList.getTime(punchTable.getPunchPair(date)); retString += time/*from www . j a v a 2 s . c o m*/ + String.format(" - %02d:%02d\n", dur.toPeriod().getHours(), dur.toPeriod().getMinutes()); totalDuration = totalDuration.plus(dur); Note note = chron.getNoteByDay(date); if (!note.getNote().equalsIgnoreCase("")) { retString += "\tNote: " + note.getNote() + "\n"; } } retString += String.format("Total time - %02d:%02d\n", totalDuration.getStandardHours(), totalDuration.getStandardMinutes() % 60); chron.close(); return retString; }
From source file:com.marand.thinkmed.medications.business.impl.TherapyDisplayProvider.java
License:Open Source License
String getTherapyDurationDisplay(final TherapyDto therapy, final Locale locale) { if (therapy.getStart() == null || therapy.getEnd() == null || (therapy.getDosingFrequency() != null && therapy.getDosingFrequency().getType() == DosingFrequencyTypeEnum.ONCE_THEN_EX)) { return ""; }//from w ww. j ava 2 s .co m final StringBuilder therapyDisplay = new StringBuilder(); therapyDisplay.append("<span class='TherapyDuration'>"); therapyDisplay.append(addLineBreak()); final String whiteSpace = " "; final Duration therapyDuration = new Duration( therapy.getEnd().getMillis() - therapy.getStart().getMillis()); final PeriodFormatter therapyDurationFormatter = new PeriodFormatterBuilder().appendWeeks() .appendSuffix(whiteSpace + Dictionary.getEntry("week.lc", locale), whiteSpace + Dictionary.getEntry("weeks", locale)) .appendSeparator(", ").appendDays() .appendSuffix(whiteSpace + Dictionary.getEntry("day.lc", locale), whiteSpace + Dictionary.getEntry("days", locale)) .appendSeparator(", ").appendHours() .appendSuffix(whiteSpace + Dictionary.getEntry("hour.lc", locale), whiteSpace + Dictionary.getEntry("hours.accusative", locale)) .appendSeparator(", ").appendMinutes() .appendSuffix(whiteSpace + Dictionary.getEntry("minute.short.lc", locale)).appendSeparator(", ") .toFormatter(); final String formattedTherapyDuration = therapyDurationFormatter .print(therapyDuration.toPeriod().normalizedStandard()); therapyDisplay.append(createSpannedValue(Dictionary.getEntry("duration", locale), "DurationLabel TextLabel MedicationLabel", true)); therapyDisplay.append(createSpannedValue(formattedTherapyDuration, "Duration TextData", true)); therapyDisplay.append("</span>"); return therapyDisplay.toString(); }
From source file:com.moosemorals.mediabrowser.ui.PVRFileTreeCellRenderer.java
License:Open Source License
@Override public Component getTreeCellRendererComponent(JTree tree, Object value, boolean isSelected, boolean isExpanded, boolean leaf, int row, boolean hasFocus) { PVRItem item = (PVRItem) value;//from w w w .ja va2 s . c om if (isSelected) { setBackground(UIManager.getColor("Tree.selectionBackground")); text.setForeground(UIManager.getColor("Tree.selectionForeground")); } else { setBackground(UIManager.getColor("Tree.textBackground")); text.setForeground(UIManager.getColor("Tree.textForeground")); } if (!(item.isDlnaScanned() && item.isFtpScanned())) { float[] colorComponents = text.getForeground().getRGBComponents(null); text.setForeground(new Color(colorComponents[0], colorComponents[1], colorComponents[2], 0.25f)); } if (item.isFile()) { PVRFile file = (PVRFile) item; if (file.isHighDef()) { text.setIcon(HD_ICON); } else { text.setIcon(leafIcon); } Duration length = new Duration(file.getStartTime(), file.getEndTime()); StringBuilder title = new StringBuilder().append(file.getTitle()).append(": ") .append(PVR.DISPLAY_DATE_AND_TIME.print(file.getStartTime())).append(" (") .append(PERIOD_FORMAT.print(length.toPeriod())).append(") ") .append(PVR.humanReadableSize(file.getSize())); if (file.isLocked()) { setIcon(lockIcon, LOCK_ICON); } else { setIcon(lockIcon, null); } text.setText(title.toString()); } else { PVRFolder folder = (PVRFolder) item; if (isExpanded) { text.setIcon(UIManager.getIcon("Tree.openIcon")); } else { text.setIcon(UIManager.getIcon("Tree.closedIcon")); } setIcon(lockIcon, null); StringBuilder title = new StringBuilder().append(folder.getRemoteFilename()).append(": ") .append(PVR.humanReadableSize(folder.getSize())).append(" (").append(folder.getChildCount()) .append(" item").append(folder.getChildCount() == 1 ? "" : "s").append(")"); text.setText(title.toString()); } Border padding = BorderFactory.createEmptyBorder(1, 0, 1, 0); Border select; if (hasFocus) { select = BorderFactory.createLineBorder(Color.black); } else { select = BorderFactory.createEmptyBorder(1, 1, 1, 1); } JTree.DropLocation dropLocation = tree.getDropLocation(); if (dropLocation != null && dropLocation.getChildIndex() == -1 && tree.getRowForPath(dropLocation.getPath()) == row) { select = BorderFactory.createLineBorder(Color.blue); } setBorder(BorderFactory.createCompoundBorder(padding, select)); Dimension preferredSize = getPreferredSize(); preferredSize.width = tree.getWidth(); setSize(preferredSize); return this; }
From source file:com.moosemorals.movieeditor.TimingPair.java
License:Open Source License
public static String format(Duration d) { return DURATION_FORMATTER.print(d.toPeriod()); }
From source file:com.mycollab.module.crm.view.activity.CallReadFormFieldFactory.java
License:Open Source License
@Override protected Field<?> onCreateField(Object propertyId) { SimpleCall call = attachForm.getBean(); if (propertyId.equals("assignuser")) { return new UserLinkViewField(call.getAssignuser(), call.getAssignUserAvatarId(), call.getAssignUserFullName()); } else if (propertyId.equals("type")) { return new RelatedReadItemField(call); } else if (CallWithBLOBs.Field.status.equalTo(propertyId)) { StringBuilder value = new StringBuilder(); if (call.getStatus() != null) { value.append(UserUIContext.getMessage(CallStatus.class, call.getStatus())).append(" "); }//from ww w .j a v a 2 s. c o m if (call.getCalltype() != null) { value.append(UserUIContext.getMessage(CallType.class, call.getCalltype())); } return new DefaultViewField(value.toString()).withStyleName(UIConstants.FIELD_NOTE); } else if (CallWithBLOBs.Field.durationinseconds.equalTo(propertyId)) { try { final long duration = Long.parseLong("" + call.getDurationinseconds() * 1000); Duration dur = new Duration(duration); PeriodFormatter formatter = new PeriodFormatterBuilder().appendDays().appendSuffix("d") .appendHours().appendSuffix("h").appendMinutes().appendSuffix("m").appendSeconds() .appendSuffix("s").toFormatter(); String formatted = formatter.print(dur.toPeriod()); return new DefaultViewField(formatted); } catch (NumberFormatException e) { return new DefaultViewField(""); } } else if (CallWithBLOBs.Field.startdate.equalTo(propertyId)) { return new DateTimeViewField(call.getStartdate()); } else if (CallWithBLOBs.Field.description.equalTo(propertyId)) { return new RichTextViewField(call.getDescription()); } return null; }
From source file:com.myMinistry.util.TimeUtils.java
License:Open Source License
public static String getTimeLength(Calendar start, Calendar end, String h, String m) { Duration dur = new Duration(new DateTime(start), new DateTime(end)); Period period = dur.toPeriod(); PeriodFormatter retVal = new PeriodFormatterBuilder().printZeroNever().appendHours().appendSuffix(h) .appendSeparator(" ").appendMinutes().appendSuffix(m).toFormatter(); return retVal.print(period); }
From source file:com.myMinistry.util.TimeUtils.java
License:Open Source License
public static String getTimeLength(Cursor cursor, String h, String m, boolean showMinutes) { SimpleDateFormat saveDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.getDefault()); Calendar start = Calendar.getInstance(Locale.getDefault()); Calendar end = Calendar.getInstance(Locale.getDefault()); Duration dur = new Duration(null, null); Duration durchange = new Duration(null, null); for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) { try {/*ww w . ja va 2 s . c om*/ start.setTime( saveDateFormat.parse(cursor.getString(cursor.getColumnIndex(UnionsNameAsRef.DATE_START)))); } catch (Exception e) { start = Calendar.getInstance(Locale.getDefault()); } try { end.setTime( saveDateFormat.parse(cursor.getString(cursor.getColumnIndex(UnionsNameAsRef.DATE_END)))); } catch (Exception e) { end = Calendar.getInstance(Locale.getDefault()); } durchange = new Duration(new DateTime(start), new DateTime(end)); dur = dur.withDurationAdded(durchange, 1); } cursor.close(); PeriodFormatter retVal; if (showMinutes) { retVal = new PeriodFormatterBuilder().printZeroRarelyFirst().appendHours().appendSuffix(h) .appendSeparator(" ").appendMinutes().appendSuffix(m).toFormatter(); } else { retVal = new PeriodFormatterBuilder().printZeroAlways().appendHours().appendSuffix(h).toFormatter(); } return retVal.print(dur.toPeriod()); }
From source file:com.nesscomputing.quartz.QuartzJobBinder.java
License:Apache License
private String printDuration(final Duration duration) { return PeriodFormat.getDefault().print(duration.toPeriod()); }
From source file:com.nubits.nubot.utils.Utils.java
License:Open Source License
public static String getDurationDate(DateTime from, DateTime to) { Duration duration = new Duration(from, to); Period period = duration.toPeriod(); Period normalizedPeriod = period.normalizedStandard(); PeriodFormatter minutesAndSeconds = new PeriodFormatterBuilder().appendDays().appendSuffix(" day", " days") .appendSeparator(" ").printZeroIfSupported() //.minimumPrintedDigits(2) .appendHours().appendSuffix(" hour", " hours").appendSeparator(" ").appendMinutes() .appendSuffix(" minute", " minutes").printZeroIfSupported() //.minimumPrintedDigits(2) .appendSeparator(" ").appendSeconds().appendSuffix(" second", " seconds") //.minimumPrintedDigits(2) .toFormatter();//from w w w . ja va2s .c om /* .printZeroAlways() .appendMinutes() .appendSeparator(":") .appendSeconds() .toFormatter();*/ String result = minutesAndSeconds.print(normalizedPeriod); return result; }