private void updateFavouriteNodes(String userName, Type type, Map<PersonFavouriteKey, PersonFavourite> favouriteNodes) { PrefKeys prefKeys = getPrefKeys(type); Map<String, Serializable> preferences = new HashMap<String, Serializable>(1); StringBuilder values = new StringBuilder(); for(PersonFavourite node : favouriteNodes.values()) { NodeRef nodeRef = node.getNodeRef(); values.append(nodeRef.toString()); values.append(","); // ISO8601 string format: PreferenceService works with strings only for dates it seems StringBuilder sb = new StringBuilder(prefKeys.getAlfrescoPrefKey()); sb.append(nodeRef.toString()); sb.append(".createdAt"); String createdAtKey = sb.toString(); Date createdAt = node.getCreatedAt(); if(createdAt != null) { String createdAtStr = ISO8601DateFormat.format(createdAt); preferences.put(createdAtKey, createdAtStr); } } if(values.length() > 1) { values.delete(values.length() - 1, values.length()); } preferences.put(prefKeys.getSharePrefKey(), values.toString()); preferenceService.setPreferences(userName, preferences); }
dateObj.put("iso8601", JSONObject.escape(ISO8601DateFormat.format((Date)value))); return dateObj;
dateObj.put("iso8601", JSONObject.escape(ISO8601DateFormat.format((Date)value))); return dateObj;
private void updateFavouriteNodes(String userName, Type type, Map<PersonFavouriteKey, PersonFavourite> favouriteNodes) { PrefKeys prefKeys = getPrefKeys(type); Map<String, Serializable> preferences = new HashMap<String, Serializable>(1); StringBuilder values = new StringBuilder(); for(PersonFavourite node : favouriteNodes.values()) { NodeRef nodeRef = node.getNodeRef(); values.append(nodeRef.toString()); values.append(","); // ISO8601 string format: PreferenceService works with strings only for dates it seems StringBuilder sb = new StringBuilder(prefKeys.getAlfrescoPrefKey()); sb.append(nodeRef.toString()); sb.append(".createdAt"); String createdAtKey = sb.toString(); Date createdAt = node.getCreatedAt(); if(createdAt != null) { String createdAtStr = ISO8601DateFormat.format(createdAt); preferences.put(createdAtKey, createdAtStr); } } if(values.length() > 1) { values.delete(values.length() - 1, values.length()); } preferences.put(prefKeys.getSharePrefKey(), values.toString()); preferenceService.setPreferences(userName, preferences); }
value = ISO8601DateFormat.format(date);
value = ISO8601DateFormat.format(date);
for (Object date : list) isoDates.add(ISO8601DateFormat.format((Date)date));
value = ISO8601DateFormat.format((Date)value); nodeProperties.put(longQName, value);
for (Object date : list) isoDates.add(ISO8601DateFormat.format((Date)date));
value = ISO8601DateFormat.format((Date)value); nodeProperties.put(longQName, value);
String convertedDate = ISO8601DateFormat.format(dateToConvert); execution.setVariable(targetVarName, convertedDate);
String convertedDate = ISO8601DateFormat.format(dateToConvert); execution.setVariable(targetVarName, convertedDate);
String createdAtStr = ISO8601DateFormat.format(createdAt); preferences.put(siteCreatedAtKey, createdAtStr);
public void testTimezones() { TimeZone.setDefault(TimeZone.getTimeZone("GMT")); Date date = null; TimeZone tz = TimeZone.getTimeZone("Australia/Sydney"); String testSydney = "2011-02-04T16:13:14"; String testUTC = "2011-02-04T05:13:14.000Z"; //Sydney date = ISO8601DateFormat.parse(testSydney, tz); assertEquals(testUTC, ISO8601DateFormat.format(date)); // Check with ms too date = ISO8601DateFormat.parse(testSydney + ".000", tz); assertEquals(testUTC, ISO8601DateFormat.format(date)); //Sydney with an offset and timezone date = ISO8601DateFormat.parse(testSydney+"+11:00", tz); assertEquals(testUTC, ISO8601DateFormat.format(date)); // Check with ms too date = ISO8601DateFormat.parse(testSydney + ".000"+"+11:00", tz); assertEquals(testUTC, ISO8601DateFormat.format(date)); }
String createdAtStr = ISO8601DateFormat.format(createdAt); preferences.put(siteCreatedAtKey, createdAtStr);
try isoDate = ISO8601DateFormat.format(new Date(Files.getLastModifiedTime(file, LinkOption.NOFOLLOW_LINKS).toMillis())); ISO8601DateFormat.parse(isoDate);
public void testConversion() { TimeZone.setDefault(TimeZone.getTimeZone("GMT")); String test = "2005-09-16T17:01:03.456+01:00"; String test2 = "1801-09-16T17:01:03.456+01:00"; // convert to a date Date date = ISO8601DateFormat.parse(test); Date date2 = ISO8601DateFormat.parse(test2); // get the string form String strDate = ISO8601DateFormat.format(date); String strDate2 = ISO8601DateFormat.format(date2); // convert back to a date from the converted string Date dateAfter = ISO8601DateFormat.parse(strDate); Date dateAfter2 = ISO8601DateFormat.parse(strDate2); // make sure the date objects match, test this instead of the // string as the string form will be different in different // locales assertEquals(date, dateAfter); assertEquals(date2, dateAfter2); }
@Test public void testQueryTemplateFunctionsUnescapingMnt11598() throws Exception { // Set the query to 2 days ago Calendar calendar = GregorianCalendar.getInstance(); calendar.setTimeInMillis(System.currentTimeMillis()); calendar.add(Calendar.DAY_OF_YEAR, AMOUNT_OF_DAYS_BEFORE + 2); String isoDate = ISO8601DateFormat.format(calendar.getTime()); String queryTemplate = String.format(MNT_11598_QUERY_TEMPLATE, isoDate); scheduler.setQueryTemplate(queryTemplate); Set<NodeRef> actualNodes = new HashSet<NodeRef>(scheduler.getNodes()); assertNotNull("Result set must not be null!", actualNodes); assertFalse("Result set must not be empty!", actualNodes.isEmpty()); assertTrue(("Result set must contain at least " + TEST_DOCUMENTS_AMOUNT + " nodes!"), actualNodes.size() >= yesterdayNodes.size()); for (FileInfo fileInfo : freshNodes) { assertFalse("No one of the nodes created \"today\" is expected in result set!", actualNodes.contains(fileInfo.getNodeRef())); } for (FileInfo fileInfo : yesterdayNodes) { assertTrue("One of the nodes created \"yesteday\" is missing in result set!", actualNodes.contains(fileInfo.getNodeRef())); } } }
public void testDateParser() { TimeZone.setDefault(TimeZone.getTimeZone("GMT")); String test = "2005-09-16T17:01:03.456+01:00"; String test2 = "1801-09-16T17:01:03.456+01:00"; String isoFormattedDate = "2005-09-16T16:01:03.456Z"; String isoFormattedDate2 = "1801-09-16T16:01:03.456Z"; Date testDate = getDateValue(2005, 9, 16, 17, 1, 3, 456, 60); Date testDate2 = getDateValue(1801, 9, 16, 17, 1, 3, 456, 60); // convert to a date Date date = ISO8601DateFormat.parse(test); Date date2 = ISO8601DateFormat.parse(test2); // check converted to date value assertEquals(testDate, date); assertEquals(testDate2, date2); // get the string form String strDate = ISO8601DateFormat.format(date); String strDate2 = ISO8601DateFormat.format(date2); // check the date converted to sting assertEquals(isoFormattedDate, strDate); assertEquals(isoFormattedDate2, strDate2); }