-
- /**
- * Constructor
- * @param inString String containing timestamp
- */
- public Timestamp(String inString)
- {
- // TODO: Does it really help to store timestamps in seconds rather than ms?
- if (inString != null && !inString.equals(""))
- {
- // Try to parse into a long
- try
- {
- long rawValue = Long.parseLong(inString.trim());
- _seconds = getSeconds(rawValue);
- _valid = true;
- }
- catch (NumberFormatException nfe)
- {
- // String is not a long, so try a date/time string instead
- // try each of the date formatters in turn
- Date date = null;
- for (int i=0; i<ALL_DATE_FORMATS.length && !_valid; i++)
- {
- try
- {
- date = ALL_DATE_FORMATS[i].parse(inString);
- CALENDAR.setTime(date);
- _seconds = CALENDAR.getTimeInMillis() / 1000L;
- _valid = true;
- }
- catch (ParseException e) {}
- }
- if (!_valid && inString.length() == 19)
- {
- final Matcher matcher = GENERAL_TIMESTAMP_PATTERN.matcher(inString);
- if (matcher.matches())
- {
- try {
- _seconds = getSeconds(Integer.parseInt(matcher.group(1)),
- Integer.parseInt(matcher.group(2)),
- Integer.parseInt(matcher.group(3)),
- Integer.parseInt(matcher.group(4)),
- Integer.parseInt(matcher.group(5)),
- Integer.parseInt(matcher.group(6)));
- _valid = true;
- }
- catch (NumberFormatException nfe2) {} // parse shouldn't fail if matcher matched
- }
- }
- }
- }
- }