- Timestamp:
- 2021-03-24T00:15:51+01:00 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/tools/date/DateUtils.java
r17114 r17653 67 67 */ 68 68 public static long tsFromString(String str) { 69 return parseInstant(str).toEpochMilli(); 70 } 71 72 /** 73 * Parses the given date string quickly, regardless of current locale. 74 * @param str the date string 75 * @return the parsed instant 76 */ 77 public static Instant parseInstant(String str) { 69 78 // "2007-07-25T09:26:24{Z|{+|-}01[:00]}" 70 79 if (checkLayout(str, "xxxx-xx-xx") || … … 76 85 str.length() > 8 ? parsePart2(str, 8) : 1, 77 86 0, 0, 0, 0, ZoneOffset.UTC); 78 return local.toInstant() .toEpochMilli();87 return local.toInstant(); 79 88 } else if (checkLayout(str, "xxxx-xx-xxTxx:xx:xxZ") || 80 89 checkLayout(str, "xxxx-xx-xxTxx:xx:xx") || … … 98 107 if (str.length() == 22 || str.length() == 25) { 99 108 final int plusHr = parsePart2(str, 20); 100 return local.plusHours(str.charAt(19) == '+' ? -plusHr : plusHr).toInstant() .toEpochMilli();109 return local.plusHours(str.charAt(19) == '+' ? -plusHr : plusHr).toInstant(); 101 110 } 102 return local.toInstant() .toEpochMilli();111 return local.toInstant(); 103 112 } else if (checkLayout(str, "xxxx-xx-xxTxx:xx:xx.xxxZ") || 104 113 checkLayout(str, "xxxx-xx-xxTxx:xx:xx.xxx") || … … 118 127 if (str.length() == 29) { 119 128 final int plusHr = parsePart2(str, 24); 120 return local.plusHours(str.charAt(23) == '+' ? -plusHr : plusHr).toInstant() .toEpochMilli();129 return local.plusHours(str.charAt(23) == '+' ? -plusHr : plusHr).toInstant(); 121 130 } 122 return local.toInstant() .toEpochMilli();131 return local.toInstant(); 123 132 } else { 124 133 // example date format "18-AUG-08 13:33:03" … … 126 135 Date d = f.parse(str, new ParsePosition(0)); 127 136 if (d != null) 128 return d. getTime();137 return d.toInstant(); 129 138 } 130 139 131 140 try { 132 141 // slow path for fractional seconds different from millisecond precision 133 return ZonedDateTime.parse(str).toInstant() .toEpochMilli();142 return ZonedDateTime.parse(str).toInstant(); 134 143 } catch (IllegalArgumentException | DateTimeParseException ex) { 135 144 throw new UncheckedParseException("The date string (" + str + ") could not be parsed.", ex);
Note:
See TracChangeset
for help on using the changeset viewer.