List of usage examples for org.apache.commons.lang.time DurationFormatUtils formatPeriodISO
public static String formatPeriodISO(long startMillis, long endMillis)
Formats the time gap as a string.
The format used is the ISO8601 period format.
From source file:org.eclipse.skalli.core.rest.admin.StatisticsConverter.java
@SuppressWarnings("nls") @Override//from w ww . ja va 2 s .c o m protected void marshal(Statistics statistics) throws IOException { long from = Math.max(statistics.getStartDate(), query.getFrom() > 0 ? query.getFrom() : statistics.getStartupTime()); long to = query.getTo() > 0 ? query.getTo() : System.currentTimeMillis(); writer.object(); namespaces(); apiVersion(); writer.pair("instance-start", FormatUtils.formatUTCWithMillis(statistics.getStartupTime())) .pair("instance-uptime", DurationFormatUtils.formatPeriodISO( //$NON-NLS-1$ statistics.getStartupTime(), System.currentTimeMillis())) .pair("from", FormatUtils.formatUTCWithMillis(from)).pair("to", FormatUtils.formatUTCWithMillis(to)) .pair("period", DurationFormatUtils.formatPeriodISO(from, to)); ProjectService projectService = ((ProjectService) EntityServices.getByEntityClass(Project.class)); List<UUID> uuids = new ArrayList<UUID>(projectService.keySet()); if (query.showSection("projects")) { marshalProjectsSection(projectService, uuids, from, to); } if (query.showSection("members")) { marshalMembersSection(projectService, uuids); } if (query.showSection("users")) { marshalUsersSection(statistics, from, to); } if (query.showSection("departments")) { marshalDepartmentsSection(statistics, from, to); } if (query.showSection("locations")) { marshalLocationsSection(statistics, from, to); } if (query.showSection("searches")) { marshalSearchesSection(statistics, from, to); } if (query.showSection("browsers")) { marshalBrowsersSection(statistics, from, to); } if (query.showSection("referers")) { marshalReferersSection(statistics, from, to); } if (query.showSection("requests")) { marshalRequestsSection(statistics, from, to); } if (query.showSection("tracks")) { marshalTracksSection(statistics, from, to); } writer.end(); }
From source file:org.eclipse.skalli.core.rest.admin.StatisticsConverter.java
@Deprecated @SuppressWarnings("nls") @Override/* w ww . j a va2 s . c om*/ public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context) { Statistics statistics = (Statistics) source; marshalNSAttributes(writer); marshalApiVersion(writer); writeNode(writer, "instance-start", FormatUtils.formatUTCWithMillis(statistics.getStartupTime())); writeNode(writer, "instance-uptime", DurationFormatUtils.formatPeriodISO( //$NON-NLS-1$ statistics.getStartupTime(), System.currentTimeMillis())); long from = Math.max(statistics.getStartDate(), query.getFrom() > 0 ? query.getFrom() : statistics.getStartupTime()); long to = query.getTo() > 0 ? query.getTo() : System.currentTimeMillis(); writeNode(writer, "from", FormatUtils.formatUTCWithMillis(from)); writeNode(writer, "to", FormatUtils.formatUTCWithMillis(to)); writeNode(writer, "period", DurationFormatUtils.formatPeriodISO(from, to)); ProjectService projectService = ((ProjectService) EntityServices.getByEntityClass(Project.class)); List<UUID> uuids = new ArrayList<UUID>(projectService.keySet()); if (query.showSection("projects")) { marshalProjectsSection(writer, projectService, uuids, from, to); } if (query.showSection("members")) { marshalMembersSection(writer, projectService, uuids); } if (query.showSection("users")) { marshalUsersSection(writer, statistics, from, to); } if (query.showSection("departments")) { marshalDepartmentsSection(writer, statistics, from, to); } if (query.showSection("locations")) { marshalLocationsSection(writer, statistics, from, to); } if (query.showSection("searches")) { marshalSearchesSection(writer, statistics, from, to); } if (query.showSection("browsers")) { marshalBrowsersSection(writer, statistics, from, to); } if (query.showSection("referers")) { marshalReferersSection(writer, statistics, from, to); } if (query.showSection("requests")) { marshalRequestsSection(writer, statistics, from, to); } if (query.showSection("tracks")) { marshalTracksSection(writer, statistics, from, to); } }