Changeset 17840 in josm
- Timestamp:
- 2021-05-01T12:37:44+02:00 (4 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/io/ChangesetClosedException.java
r13207 r17840 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.text.ParseException; 7 import java.util.Date; 6 import java.time.Instant; 8 7 import java.util.regex.Matcher; 9 8 import java.util.regex.Pattern; 10 9 11 10 import org.openstreetmap.josm.tools.Logging; 11 import org.openstreetmap.josm.tools.UncheckedParseException; 12 12 import org.openstreetmap.josm.tools.date.DateUtils; 13 13 … … 66 66 private long changesetId; 67 67 /** the date on which the changeset was closed */ 68 private DateclosedOn;68 private Instant closedOn; 69 69 /** the source */ 70 70 private Source source; … … 76 76 changesetId = Long.parseLong(m.group(1)); 77 77 try { 78 closedOn = DateUtils. newOsmApiDateTimeFormat().parse(m.group(2));79 } catch ( ParseException ex) {78 closedOn = DateUtils.parseInstant(m.group(2)); 79 } catch (UncheckedParseException ex) { 80 80 Logging.error(tr("Failed to parse date ''{0}'' replied by server.", m.group(2))); 81 81 Logging.error(ex); … … 129 129 * @param source the source for the exception 130 130 */ 131 public ChangesetClosedException(long changesetId, DateclosedOn, Source source) {131 public ChangesetClosedException(long changesetId, Instant closedOn, Source source) { 132 132 super(""); 133 133 this.source = source == null ? Source.UNSPECIFIED : source; 134 134 this.changesetId = changesetId; 135 this.closedOn = DateUtils.cloneDate(closedOn);135 this.closedOn = closedOn; 136 136 } 137 137 … … 150 150 * @return the date the changeset was closed. May be null if the date isn't known. 151 151 */ 152 public DategetClosedOn() {153 return DateUtils.cloneDate(closedOn);152 public Instant getClosedOn() { 153 return closedOn; 154 154 } 155 155 -
trunk/src/org/openstreetmap/josm/tools/ExceptionUtil.java
r16643 r17840 11 11 import java.net.URL; 12 12 import java.net.UnknownHostException; 13 import java.text.DateFormat; 14 import java.text.ParseException; 13 import java.time.Instant; 14 import java.time.ZoneId; 15 import java.time.format.FormatStyle; 15 16 import java.util.Arrays; 16 17 import java.util.Collection; 17 import java.util.Date;18 18 import java.util.List; 19 19 import java.util.Objects; … … 398 398 if (m.matches()) { 399 399 long changesetId = Long.parseLong(m.group(1)); 400 DatecloseDate = null;400 Instant closeDate = null; 401 401 try { 402 closeDate = DateUtils. newOsmApiDateTimeFormat().parse(m.group(2));403 } catch ( ParseException ex) {402 closeDate = DateUtils.parseInstant(m.group(2)); 403 } catch (UncheckedParseException ex) { 404 404 Logging.error(tr("Failed to parse date ''{0}'' replied by server.", m.group(2))); 405 405 Logging.error(ex); … … 415 415 +" because it has already been closed on {1}.", 416 416 changesetId, 417 DateUtils.formatDateTime(closeDate, DateFormat.DEFAULT, DateFormat.DEFAULT)417 formatClosedOn(closeDate) 418 418 ); 419 419 } … … 445 445 +"because it has already been closed on {1}.", 446 446 e.getChangesetId(), 447 e.getClosedOn() == null ? "?" : DateUtils.formatDateTime(e.getClosedOn(), DateFormat.DEFAULT, DateFormat.DEFAULT)447 e.getClosedOn() == null ? "?" : formatClosedOn(e.getClosedOn()) 448 448 ); 449 } 450 451 private static String formatClosedOn(Instant closedOn) { 452 return DateUtils.getDateTimeFormatter(FormatStyle.SHORT, FormatStyle.SHORT).format(closedOn.atZone(ZoneId.systemDefault())); 449 453 } 450 454 -
trunk/src/org/openstreetmap/josm/tools/date/DateUtils.java
r17839 r17840 11 11 import java.time.ZonedDateTime; 12 12 import java.time.format.DateTimeFormatter; 13 import java.time.format.DateTimeFormatterBuilder; 13 14 import java.time.format.DateTimeParseException; 14 15 import java.time.format.FormatStyle; … … 76 77 * @param str the date string 77 78 * @return the parsed instant 79 * @throws UncheckedParseException if the date does not match any of the supported date formats 78 80 */ 79 81 public static Instant parseInstant(String str) { … … 249 251 250 252 /** 251 * Returns a new {@code SimpleDateFormat} for date and time, according to format used in OSM API errors.252 * @return a new date format, for date and time, to use for OSM API error handling.253 * @since 7299254 */255 public static SimpleDateFormat newOsmApiDateTimeFormat() {256 // Example: "2010-09-07 14:39:41 UTC".257 // Always parsed with US locale regardless of the current locale in JOSM258 return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z", Locale.US);259 }260 261 /**262 253 * Returns the date format to be used for current user, based on user preferences. 263 254 * @param dateStyle The date style as described in {@link DateFormat#getDateInstance}. Ignored if "ISO dates" option is set … … 367 358 368 359 /** 360 * Differs from {@link DateTimeFormatter#ISO_LOCAL_DATE_TIME} by using ' ' instead of 'T' to separate date/time. 361 */ 362 private static final DateTimeFormatter ISO_LOCAL_DATE_TIME = new DateTimeFormatterBuilder() 363 .parseCaseInsensitive() 364 .append(DateTimeFormatter.ISO_LOCAL_DATE) 365 .appendLiteral(' ') 366 .append(DateTimeFormatter.ISO_LOCAL_TIME) 367 .toFormatter(); 368 369 /** 369 370 * Returns the date/time formatter to be used for current user, based on user preferences. 370 371 * @param dateStyle The date style. Ignored if "ISO dates" option is set. … … 374 375 public static DateTimeFormatter getDateTimeFormatter(FormatStyle dateStyle, FormatStyle timeStyle) { 375 376 DateTimeFormatter formatter = PROP_ISO_DATES.get() 376 ? DateTimeFormatter.ISO_LOCAL_DATE_TIME377 ? ISO_LOCAL_DATE_TIME 377 378 : DateTimeFormatter.ofLocalizedDateTime(dateStyle, timeStyle); 378 379 return formatter.withZone(ZoneId.systemDefault()); -
trunk/test/unit/org/openstreetmap/josm/tools/ExceptionUtilTest.java
r17275 r17840 110 110 111 111 assertEquals("<html>Failed to upload to changeset <strong>1</strong><br>because it has already been closed on 2016-01-01 00:00:00.", 112 ExceptionUtil.explainChangesetClosedException(new ChangesetClosedException(1, DateUtils. fromString("2016-01-01"), null)));112 ExceptionUtil.explainChangesetClosedException(new ChangesetClosedException(1, DateUtils.parseInstant("2016-01-01"), null))); 113 113 } 114 114
Note:
See TracChangeset
for help on using the changeset viewer.