/** * Serialize time to general dateTime text. This method is provided for backward compatibility. * It generates the dateTime text without the trailing 'Z' to indicate UTC. * * @param time time to be converted, as milliseconds from January 1, 1970 * @return converted dateTime text * @throws IllegalArgumentException on conversion error */ public static String serializeDateTime(long time) throws IllegalArgumentException { return serializeDateTime(time, false); }
/** * Serialize date to general dateTime text. Date values are formatted in W3C XML Schema standard * format as CCYY-MM-DDThh:mm:ss, with optional leading sign and trailing seconds decimal, as * necessary. * * @param date date to be converted * @return converted dateTime text * @throws IllegalArgumentException on conversion error */ public static String serializeDateTime(Date date) throws IllegalArgumentException { long time = date.getTime(); time += TimeZone.getDefault().getOffset(time); return serializeDateTime(time, false); }
return serializeDateTime(stamp.getTime(), false) + '.' + digits + 'Z'; } else { return serializeDateTime(stamp.getTime(), true);
public void testJavaUtilDate() { Calendar cal = Calendar.getInstance(); cal.clear(); cal.set(2007, 3, 1, 1, 15); Date time = cal.getTime(); String dateTime = DateUtil.serializeDateTime(time); assertEquals("2007-04-01T01:15:00", dateTime); String date = DateUtil.serializeDate(time); assertEquals("2007-04-01", date); }
else if (value instanceof java.sql.Time) text = DateUtil.serializeSqlTime((java.sql.Time) value); else text = DateUtil.serializeDateTime((Date) value); contentHandler.characters(text.toCharArray(), 0, text.length()); } else {
@Override public String format(Object att) { return prepCSVField(DateUtil.serializeDateTime((Date) att)); } }
/** * Serialize time to general dateTime text. This method is provided for * backward compatibility. It generates the dateTime text without the * trailing 'Z' to indicate UTC. * * @param time time to be converted, as milliseconds from January 1, 1970 * * @return converted dateTime text * * @throws IllegalArgumentException on conversion error */ public static String serializeDateTime(long time) throws IllegalArgumentException { return serializeDateTime(time, false); }
/** * Serialize time to general dateTime text. This method is provided for * backward compatibility. It generates the dateTime text without the * trailing 'Z' to indicate UTC. * * @param time time to be converted, as milliseconds from January 1, 1970 * * @return converted dateTime text * * @throws IllegalArgumentException on conversion error */ public static String serializeDateTime(long time) throws IllegalArgumentException { return serializeDateTime(time, false); }
/** * Serialize date to general dateTime text. Date values are formatted in * W3C XML Schema standard format as CCYY-MM-DDThh:mm:ss, with optional * leading sign and trailing seconds decimal, as necessary. * * @param date date to be converted * * @return converted dateTime text * * @throws IllegalArgumentException on conversion error */ public static String serializeDateTime(Date date) throws IllegalArgumentException { long time = date.getTime(); time += TimeZone.getDefault().getOffset(time); return serializeDateTime(time, false); }
/** * Serialize date to general dateTime text. Date values are formatted in * W3C XML Schema standard format as CCYY-MM-DDThh:mm:ss, with optional * leading sign and trailing seconds decimal, as necessary. * * @param date date to be converted * * @return converted dateTime text * * @throws IllegalArgumentException on conversion error */ public static String serializeDateTime(Date date) throws IllegalArgumentException { long time = date.getTime(); time += TimeZone.getDefault().getOffset(time); return serializeDateTime(time, false); }
return serializeDateTime(stamp.getTime(), false) + '.' + digits + 'Z'; } else { return serializeDateTime(stamp.getTime(), true);
return serializeDateTime(stamp.getTime(), false) + '.' + digits + 'Z'; } else { return serializeDateTime(stamp.getTime(), true);
private String formatToString(Object att, NumberFormat coordFormatter) { String value; if (att instanceof Number) { // don't allow scientific notation in the output, as OpenOffice won't // recognize that as a number value = coordFormatter.format(att); } else if (att instanceof Date) { // serialize dates in ISO format if (att instanceof java.sql.Date) value = DateUtil.serializeSqlDate((java.sql.Date) att); else if (att instanceof java.sql.Time) value = DateUtil.serializeSqlTime((java.sql.Time) att); else value = DateUtil.serializeDateTime((Date) att); } else { // everything else we just "toString" value = att.toString(); } return value; }
@Override /** * Formats the dimension default value for the capabilities file as ISO 8601 DateTime for TIME * and as a number for ELEVATION. Assumes that getDefaultValue returns a single value, classes * handling ranges have to override this method */ public String getCapabilitiesRepresentation( ResourceInfo resource, String dimensionName, DimensionInfo dimensionInfo) { String retval = null; if (dimensionName.equals(ResourceInfo.TIME)) { Date dateValue = (Date) getDefaultValue(resource, dimensionName, dimensionInfo, Date.class); if (dateValue == null) { return DimensionDefaultValueSetting.TIME_CURRENT; } retval = DateUtil.serializeDateTime(dateValue.getTime(), true); } else if (dimensionName.equals(ResourceInfo.ELEVATION)) { Number numberValue = (Number) getDefaultValue(resource, dimensionName, dimensionInfo, Number.class); if (numberValue == null) { return "0"; } retval = numberValue.toString(); } else { Object value = getDefaultValue(resource, dimensionName, dimensionInfo, Object.class); retval = value.toString(); } return retval; } }
@Override protected Component getComponentForProperty( final String id, @SuppressWarnings("rawtypes") IModel<LogEvent> itemModel, Property<LogEvent> property) { LogEvent item = (LogEvent) itemModel.getObject(); if (property == LogEventProvider.SEVERITY) { Severity severity = item.getSeverity(); PackageResourceReference iconRef = SEVERITY_ICONS.get(severity); return new Icon(id, iconRef); } if (property == LogEventProvider.REPOSITORY) { return repositoryLink(id, item); } if (property == LogEventProvider.TIMESTAMP) { return new Label(id, DateUtil.serializeDateTime(item.getTimestamp())); } if (property == LogEventProvider.MESSAGE) { return messageLink(id, item); } return new Label(id, String.valueOf(property.getPropertyValue(item))); }
public void testGetAllCSVQuery() throws Exception { RequestResource.CSVFormat format = new RequestResource.CSVFormat( new String[]{"id", "path", "startTime"}, monitor); ByteArrayOutputStream out = new ByteArrayOutputStream(); format.toRepresentation(new Query()).write(out); BufferedReader in = new BufferedReader(new InputStreamReader( new ByteArrayInputStream(out.toByteArray()))); String line = in.readLine(); assertEquals("id,path,startTime", line); Iterator<RequestData> it = monitor.getDAO().getRequests().iterator(); while((line = in.readLine()) != null) { assertTrue(it.hasNext()); RequestData data = it.next(); String expected = data.getId() + "," + data.getPath() + "," + DateUtil.serializeDateTime(data.getStartTime()); assertEquals(expected, line); } assertFalse(it.hasNext()); }
@Test public void testGetAllCSV() throws Exception { RequestResource.CSVFormat format = new RequestResource.CSVFormat( new String[]{"id", "path", "startTime"}, monitor); ByteArrayOutputStream out = new ByteArrayOutputStream(); format.toRepresentation(monitor.getDAO().getRequests()).write(out); BufferedReader in = new BufferedReader(new InputStreamReader( new ByteArrayInputStream(out.toByteArray()))); String line = in.readLine(); assertEquals("id,path,startTime", line); Iterator<RequestData> it = monitor.getDAO().getRequests().iterator(); while((line = in.readLine()) != null) { assertTrue(it.hasNext()); RequestData data = it.next(); String expected = data.getId() + "," + data.getPath() + "," + DateUtil.serializeDateTime(data.getStartTime()); assertEquals(expected, line); } assertFalse(it.hasNext()); }
@Test public void testGetAllCSV() throws Exception { MockHttpServletResponse response = getAsServletResponse( RestBaseController.ROOT_PATH + "/monitor/requests.csv?fields=id;path;startTime"); assertEquals(200, response.getStatus()); // System.out.println(response.getContentAsString()); BufferedReader in = new BufferedReader( new InputStreamReader( new ByteArrayInputStream(response.getContentAsByteArray()))); String line = in.readLine(); assertEquals("id,path,startTime", line); Iterator<RequestData> it = monitor.getDAO().getRequests().iterator(); while ((line = in.readLine()) != null) { assertTrue(it.hasNext()); RequestData data = it.next(); String expected = data.getId() + "," + data.getPath() + "," + DateUtil.serializeDateTime(data.getStartTime()); assertEquals(expected, line); } assertFalse(it.hasNext()); }
requests = true; String expected = "id,path,startTime\n12345,/foo," + DateUtil.serializeDateTime(startTime); assertEquals(expected, readEntry(zin));
"id,path,startTime\n12345,/foo," + DateUtil.serializeDateTime(startTime); assertEquals(expected, readEntry(zin)); } else if ("body.txt".equals(entry.getName())) {