protected void toValue() throws IOException { String dateStr = new String(getBytes(), StandardCharsets.US_ASCII); SimpleDateFormat sdf; String fixedDateStr = dateStr; boolean withZ = dateStr.endsWith("Z"); String timeZonePart = getTimeZonePart(dateStr); boolean withZone = timeZonePart != null; String millSecs = getMillSeconds(dateStr); fixedDateStr = dateStr.substring(0, 14) + millSecs; if (withZ) { sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS"); sdf.setTimeZone(new SimpleTimeZone(0, "Z")); } else if (withZone) { fixedDateStr += timeZonePart; sdf = new SimpleDateFormat("yyyyMMddHHmmssSSSz"); sdf.setTimeZone(new SimpleTimeZone(0, "Z")); } else { sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS"); sdf.setTimeZone(new SimpleTimeZone(0, TimeZone.getDefault().getID())); } try { setValue(sdf.parse(fixedDateStr)); } catch (ParseException e) { throw new IOException("Failed to parse as generalized time string " + dateStr); } }
protected void toValue() throws IOException { String dateStr = new String(getBytes(), StandardCharsets.US_ASCII); SimpleDateFormat sdf; String fixedDateStr = dateStr; boolean withZ = dateStr.endsWith("Z"); String timeZonePart = getTimeZonePart(dateStr); boolean withZone = timeZonePart != null; String millSecs = getMillSeconds(dateStr); fixedDateStr = dateStr.substring(0, 14) + millSecs; if (withZ) { sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS"); sdf.setTimeZone(new SimpleTimeZone(0, "Z")); } else if (withZone) { fixedDateStr += timeZonePart; sdf = new SimpleDateFormat("yyyyMMddHHmmssSSSz"); sdf.setTimeZone(new SimpleTimeZone(0, "Z")); } else { sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS"); sdf.setTimeZone(new SimpleTimeZone(0, TimeZone.getDefault().getID())); } try { setValue(sdf.parse(fixedDateStr)); } catch (ParseException e) { throw new IOException("Failed to parse as generalized time string " + dateStr); } }