List of usage examples for org.joda.time Seconds secondsBetween
public static Seconds secondsBetween(ReadablePartial start, ReadablePartial end)
Seconds
representing the number of whole seconds between the two specified partial datetimes. From source file:viability.LogFile.java
/** * Get all signal in the last 30 seconds with High Priority on list from statistics request DateTime * @param daterequest statistics request DateTime * @return /* ww w.j av a 2s . c o m*/ */ public void averageSignalMonthForDistrictHighPriority(DateTime daterequest, DateTime dateTimeCreationDB) { //WE ASSUME A MONTH = 120 SECONDS FOR DEMO LinkedList<String> listdistricts = getListDistrict(); Iterator iteratorDistricts = listdistricts.iterator(); //for each District on List while (iteratorDistricts.hasNext()) { double average = 0; int countDistrict = 0; String tempdistrict = (String) iteratorDistricts.next(); Iterator iterator = listSignal.iterator(); while (iterator.hasNext()) { Signal temp = (Signal) iterator.next(); if (temp.getDistrict().equalsIgnoreCase(tempdistrict) && temp.getPriority().equalsIgnoreCase("high")) { countDistrict++; } } //get weeks between DB creation date and statistics request date int seconds = Seconds.secondsBetween(dateTimeCreationDB, daterequest).getSeconds(); double countWeeks = seconds / 120; //calculate average for this District average = countDistrict / countWeeks; System.out.println("Average Signal Month for District " + tempdistrict + " is " + average); } }
From source file:za.co.argility.furnmart.entity.ExtractHistory.java
public String toHtml() { final String DATE_FORMAT = "dd MMMM yyyy HH:mm:ss"; SimpleDateFormat format = new SimpleDateFormat(DATE_FORMAT); String html = ""; ExtractProgress progress = null;/*from w w w . j a v a2s . co m*/ // Determine the current progress of the extract if (extractError == null && endTime != null) progress = ExtractProgress.Finished; else if (extractError != null && endTime == null) progress = ExtractProgress.ErrorOccured; else progress = ExtractProgress.InProgress; if (progress == ExtractProgress.Finished) html += "<img src=\"images/ok.png\" style=\"width:36px\" alt=\"ok\" />"; else if (progress == ExtractProgress.ErrorOccured) html += "<img src=\"images/error.png\" style=\"width:36px\" alt=\"error\" />"; else html += "<img src=\"images/in_progress.png\" style=\"width:36px\" alt=\"in progress\" />"; html += "<p>"; if (progress == ExtractProgress.InProgress) html += "<span>" + "<b>STARTED:</b> " + format.format(startTime) + "</span><br/>"; else if (progress == ExtractProgress.ErrorOccured) html += "<span>" + "<b>ABORTED:</b> " + format.format(startTime) + "</span><br/>"; else html += "<span>" + "<b>FINISHED:</b> " + format.format(endTime) + "</span><br/>"; if (endTime != null) { int total = Seconds.secondsBetween(new DateTime(startTime), new DateTime(endTime)).getSeconds(); int seconds = total % 60; int minutes = (int) (total / 60); String duration = ""; if (minutes == 0 && seconds > 0) { duration = seconds + " sec"; } else if (minutes > 0 && seconds == 0) { duration = minutes + " min"; } else if (minutes == 0 && seconds == 0) { duration = "under a second"; } else { duration = minutes + " min, " + seconds + " sec"; } html += "<span><b>DURATION: </b>" + duration + "</span>"; } return html + "</p>"; }