Changeset 17843 in josm
- Timestamp:
- 2021-05-01T13:29:36+02:00 (4 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/dialogs/changeset/query/TimeRestrictionPanel.java
r16075 r17843 10 10 import java.awt.event.ItemEvent; 11 11 import java.awt.event.ItemListener; 12 import java.time.Instant; 12 13 import java.time.LocalDate; 13 14 import java.time.LocalTime; 14 15 import java.time.ZoneId; 15 import java.util.Date;16 16 17 17 import javax.swing.BorderFactory; … … 231 231 LocalDate d1 = valClosedAfterDate1.getDate(); 232 232 LocalTime d2 = valClosedAfterTime1.getTime(); 233 final Date d3 = new Date(d1.atTime(d2).atZone(ZoneId.systemDefault()).toInstant().toEpochMilli());233 final Instant d3 = d1.atTime(d2).atZone(ZoneId.systemDefault()).toInstant(); 234 234 query.closedAfter(d3); 235 235 } else if (rbClosedAfterAndCreatedBefore.isSelected()) { 236 236 LocalDate d1 = valClosedAfterDate2.getDate(); 237 237 LocalTime d2 = valClosedAfterTime2.getTime(); 238 Date d3 = new Date(d1.atTime(d2).atZone(ZoneId.systemDefault()).toInstant().toEpochMilli());238 Instant d3 = d1.atTime(d2).atZone(ZoneId.systemDefault()).toInstant(); 239 239 240 240 d1 = valCreatedBeforeDate.getDate(); 241 241 d2 = valCreatedBeforeTime.getTime(); 242 Date d4 = new Date(d1.atTime(d2).atZone(ZoneId.systemDefault()).toInstant().toEpochMilli());242 Instant d4 = d1.atTime(d2).atZone(ZoneId.systemDefault()).toInstant(); 243 243 244 244 query.closedAfterAndCreatedBefore(d3, d4); -
trunk/src/org/openstreetmap/josm/io/ChangesetQuery.java
r17333 r17843 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.text.DateFormat;7 6 import java.text.MessageFormat; 8 import java.t ext.ParseException;7 import java.time.Instant; 9 8 import java.util.ArrayList; 10 9 import java.util.Collection; 11 10 import java.util.Collections; 12 import java.util.Date;13 11 import java.util.HashMap; 14 12 import java.util.Map; … … 22 20 import org.openstreetmap.josm.tools.CheckParameterUtil; 23 21 import org.openstreetmap.josm.tools.Logging; 22 import org.openstreetmap.josm.tools.UncheckedParseException; 24 23 import org.openstreetmap.josm.tools.Utils; 25 24 import org.openstreetmap.josm.tools.date.DateUtils; … … 45 44 private Bounds bounds; 46 45 /** the date after which changesets have been closed this query is restricted to. null, if no restriction to closure date applies */ 47 private DateclosedAfter;46 private Instant closedAfter; 48 47 /** the date before which changesets have been created this query is restricted to. null, if no restriction to creation date applies */ 49 private DatecreatedBefore;48 private Instant createdBefore; 50 49 /** indicates whether only open changesets are queried. null, if no restrictions regarding open changesets apply */ 51 50 private Boolean open; … … 155 154 * @since 14039 156 155 */ 157 public DategetClosedAfter() {158 return DateUtils.cloneDate(closedAfter);156 public Instant getClosedAfter() { 157 return closedAfter; 159 158 } 160 159 … … 166 165 * @since 14039 167 166 */ 168 public DategetCreatedBefore() {169 return DateUtils.cloneDate(createdBefore);167 public Instant getCreatedBefore() { 168 return createdBefore; 170 169 } 171 170 … … 270 269 * @throws IllegalArgumentException if d is null 271 270 */ 272 public ChangesetQuery closedAfter( Dated) {271 public ChangesetQuery closedAfter(Instant d) { 273 272 CheckParameterUtil.ensureParameterNotNull(d, "d"); 274 this.closedAfter = DateUtils.cloneDate(d);273 this.closedAfter = d; 275 274 return this; 276 275 } … … 287 286 * @throws IllegalArgumentException if createdBefore is null 288 287 */ 289 public ChangesetQuery closedAfterAndCreatedBefore( Date closedAfter, DatecreatedBefore) {288 public ChangesetQuery closedAfterAndCreatedBefore(Instant closedAfter, Instant createdBefore) { 290 289 CheckParameterUtil.ensureParameterNotNull(closedAfter, "closedAfter"); 291 290 CheckParameterUtil.ensureParameterNotNull(createdBefore, "createdBefore"); 292 this.closedAfter = DateUtils.cloneDate(closedAfter);293 this.createdBefore = DateUtils.cloneDate(createdBefore);291 this.closedAfter = closedAfter; 292 this.createdBefore = createdBefore; 294 293 return this; 295 294 } … … 357 356 sb.append('&'); 358 357 } 359 DateFormat df = DateUtils.newIsoDateTimeFormat(); 360 sb.append("time=").append(df.format(closedAfter)); 361 sb.append(',').append(df.format(createdBefore)); 358 sb.append("time=").append(closedAfter); 359 sb.append(',').append(createdBefore); 362 360 } else if (closedAfter != null) { 363 361 if (sb.length() > 0) { 364 362 sb.append('&'); 365 363 } 366 DateFormat df = DateUtils.newIsoDateTimeFormat(); 367 sb.append("time=").append(df.format(closedAfter)); 364 sb.append("time=").append(closedAfter); 368 365 } 369 366 … … 466 463 } 467 464 468 protected DateparseDate(String value, String parameter) throws ChangesetQueryUrlException {465 protected Instant parseDate(String value, String parameter) throws ChangesetQueryUrlException { 469 466 if (value == null || value.trim().isEmpty()) 470 467 throw new ChangesetQueryUrlException( 471 468 tr("Unexpected value for ''{0}'' in changeset query url, got {1}", parameter, value)); 472 DateFormat formatter = DateUtils.newIsoDateTimeFormat();473 469 try { 474 return formatter.parse(value);475 } catch ( ParseException e) {470 return DateUtils.parseInstant(value); 471 } catch (UncheckedParseException e) { 476 472 throw new ChangesetQueryUrlException( 477 473 tr("Unexpected value for ''{0}'' in changeset query url, got {1}", parameter, value), e); … … 479 475 } 480 476 481 protected Date[] parseTime(String value) throws ChangesetQueryUrlException {477 protected Instant[] parseTime(String value) throws ChangesetQueryUrlException { 482 478 String[] dates = value.split(",", -1); 483 479 if (dates.length == 0 || dates.length > 2) … … 485 481 tr("Unexpected value for ''{0}'' in changeset query url, got {1}", "time", value)); 486 482 if (dates.length == 1) 487 return new Date[]{parseDate(dates[0], "time")};483 return new Instant[]{parseDate(dates[0], "time")}; 488 484 else if (dates.length == 2) 489 return new Date[]{parseDate(dates[0], "time"), parseDate(dates[1], "time")};490 return new Date[]{};485 return new Instant[]{parseDate(dates[0], "time"), parseDate(dates[1], "time")}; 486 return new Instant[]{}; 491 487 } 492 488 … … 524 520 break; 525 521 case "time": 526 Date[] dates = parseTime(entry.getValue());522 Instant[] dates = parseTime(entry.getValue()); 527 523 switch(dates.length) { 528 524 case 1: -
trunk/test/unit/org/openstreetmap/josm/io/ChangesetQueryUrlParserTest.java
r17275 r17843 151 151 assertNotNull(q); 152 152 assertNotNull(q.getClosedAfter()); 153 OffsetDateTime cal = q.getClosedAfter().toInstant().atOffset(ZoneOffset.UTC); 154 assertEquals(OffsetDateTime.of(2009, 12, 25, 10, 0, 0, 0, ZoneOffset.UTC), cal); 153 assertEquals(OffsetDateTime.of(2009, 12, 25, 10, 0, 0, 0, ZoneOffset.UTC).toInstant(), q.getClosedAfter()); 155 154 156 155 // OK
Note:
See TracChangeset
for help on using the changeset viewer.