@Test public void testFormatManySecondFractions() throws Exception { final String testValue = "2015-03-19T22:54:15.841473+00:00"; final Date result = xmppDateTimeFormat.parseString(testValue); long expected = 1426805655841L; assertEquals( expected, result.getTime() ); }
public Date parseString(String dateString) throws ParseException { Matcher xep82WoMillisMatcher = xep80DateTimeWoMillisPattern.matcher(dateString); Matcher xep82Matcher = xep80DateTimePattern.matcher(dateString); if (xep82WoMillisMatcher.matches() || xep82Matcher.matches()) { String rfc822Date; if (dateString.charAt(dateString.length() - 1) == 'Z') { rfc822Date = dateString.replace("Z", "+0000"); } else { int lastColon = dateString.lastIndexOf(':'); rfc822Date = dateString.substring(0, lastColon) + dateString.substring(lastColon + 1); } if (xep82WoMillisMatcher.matches()) { synchronized (dateTimeFormatWoMillies) { return dateTimeFormatWoMillies.parse(rfc822Date); } } else { rfc822Date = rfc822Date.replaceAll("(\\.[0-9]{3})[0-9]*", "$1"); synchronized (dateTimeFormat) { return dateTimeFormat.parse(rfc822Date); } } } throw new ParseException("Date String could not be parsed", 0); }
XMPPDateTimeFormat { public Date parseString(String dateString) throws ParseException { Matcher xep82WoMillisMatcher = xep80DateTimeWoMillisPattern.matcher(dateString); Matcher xep82Matcher = xep80DateTimePattern.matcher(dateString); if (xep82WoMillisMatcher.matches() || xep82Matcher.matches()) { String rfc822Date; if (dateString.charAt(dateString.length() - 1) == 'Z') { rfc822Date = dateString.replace("Z", "+0000"); } else { int lastColon = dateString.lastIndexOf(':'); rfc822Date = dateString.substring(0, lastColon) + dateString.substring(lastColon + 1); } if (xep82WoMillisMatcher.matches()) { synchronized (dateTimeFormatWoMillies) { return dateTimeFormatWoMillies.parse(rfc822Date); } } else { rfc822Date = rfc822Date.replaceAll("(\\.[0-9]{3})[0-9]*", "$1"); synchronized (dateTimeFormat) { return dateTimeFormat.parse(rfc822Date); } } } throw new ParseException("Date String could not be parsed", 0); } }
XMPPDateTimeFormat { public Date parseString(String dateString) throws ParseException { Matcher xep82WoMillisMatcher = xep80DateTimeWoMillisPattern.matcher(dateString); Matcher xep82Matcher = xep80DateTimePattern.matcher(dateString); if (xep82WoMillisMatcher.matches() || xep82Matcher.matches()) { String rfc822Date; if (dateString.charAt(dateString.length() - 1) == 'Z') { rfc822Date = dateString.replace("Z", "+0000"); } else { int lastColon = dateString.lastIndexOf(':'); rfc822Date = dateString.substring(0, lastColon) + dateString.substring(lastColon + 1); } if (xep82WoMillisMatcher.matches()) { synchronized (dateTimeFormatWoMillies) { return dateTimeFormatWoMillies.parse(rfc822Date); } } else { rfc822Date = rfc822Date.replaceAll("(\\.[0-9]{3})[0-9]*", "$1"); synchronized (dateTimeFormat) { return dateTimeFormat.parse(rfc822Date); } } } throw new ParseException("Date String could not be parsed", 0); } XMPPDateTimeFormat(); }
XMPPDateTimeFormat { public Date parseString(String dateString) throws ParseException { Matcher xep82WoMillisMatcher = xep80DateTimeWoMillisPattern.matcher(dateString); Matcher xep82Matcher = xep80DateTimePattern.matcher(dateString); if (xep82WoMillisMatcher.matches() || xep82Matcher.matches()) { String rfc822Date; if (dateString.charAt(dateString.length() - 1) == 'Z') { rfc822Date = dateString.replace("Z", "+0000"); } else { int lastColon = dateString.lastIndexOf(':'); rfc822Date = dateString.substring(0, lastColon) + dateString.substring(lastColon + 1); } if (xep82WoMillisMatcher.matches()) { synchronized (dateTimeFormatWoMillies) { return dateTimeFormatWoMillies.parse(rfc822Date); } } else { rfc822Date = rfc822Date.replaceAll("(\\.[0-9]{3})[0-9]*", "$1"); synchronized (dateTimeFormat) { return dateTimeFormat.parse(rfc822Date); } } } throw new ParseException("Date String could not be parsed", 0); } XMPPDateTimeFormat(); Date parseString(String dateString); static String format(Date date); }
XMPPDateTimeFormat { public Date parseString(String dateString) throws ParseException { Matcher xep82WoMillisMatcher = xep80DateTimeWoMillisPattern.matcher(dateString); Matcher xep82Matcher = xep80DateTimePattern.matcher(dateString); if (xep82WoMillisMatcher.matches() || xep82Matcher.matches()) { String rfc822Date; if (dateString.charAt(dateString.length() - 1) == 'Z') { rfc822Date = dateString.replace("Z", "+0000"); } else { int lastColon = dateString.lastIndexOf(':'); rfc822Date = dateString.substring(0, lastColon) + dateString.substring(lastColon + 1); } if (xep82WoMillisMatcher.matches()) { synchronized (dateTimeFormatWoMillies) { return dateTimeFormatWoMillies.parse(rfc822Date); } } else { rfc822Date = rfc822Date.replaceAll("(\\.[0-9]{3})[0-9]*", "$1"); synchronized (dateTimeFormat) { return dateTimeFormat.parse(rfc822Date); } } } throw new ParseException("Date String could not be parsed", 0); } XMPPDateTimeFormat(); Date parseString(String dateString); static String format(Date date); static final String XMPP_DATETIME_FORMAT; static final String XMPP_DATETIME_FORMAT_WO_TIMEZONE; static final String XMPP_DATETIME_FORMAT_WO_MILLIS_WO_TIMEZONE; static final String XMPP_DATE_FORMAT; static final String XMPP_TIME_FORMAT; static final String XMPP_TIME_FORMAT_WO_MILLIS; static final String XMPP_DELAY_DATETIME_FORMAT; }