Changeset 17843 in josm for trunk/src/org


Ignore:
Timestamp:
2021-05-01T13:29:36+02:00 (4 years ago)
Author:
simon04
Message:

see #14176 - Migrate ChangesetQuery to Instant

Location:
trunk/src/org/openstreetmap/josm
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/dialogs/changeset/query/TimeRestrictionPanel.java

    r16075 r17843  
    1010import java.awt.event.ItemEvent;
    1111import java.awt.event.ItemListener;
     12import java.time.Instant;
    1213import java.time.LocalDate;
    1314import java.time.LocalTime;
    1415import java.time.ZoneId;
    15 import java.util.Date;
    1616
    1717import javax.swing.BorderFactory;
     
    231231            LocalDate d1 = valClosedAfterDate1.getDate();
    232232            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();
    234234            query.closedAfter(d3);
    235235        } else if (rbClosedAfterAndCreatedBefore.isSelected()) {
    236236            LocalDate d1 = valClosedAfterDate2.getDate();
    237237            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();
    239239
    240240            d1 = valCreatedBeforeDate.getDate();
    241241            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();
    243243
    244244            query.closedAfterAndCreatedBefore(d3, d4);
  • trunk/src/org/openstreetmap/josm/io/ChangesetQuery.java

    r17333 r17843  
    44import static org.openstreetmap.josm.tools.I18n.tr;
    55
    6 import java.text.DateFormat;
    76import java.text.MessageFormat;
    8 import java.text.ParseException;
     7import java.time.Instant;
    98import java.util.ArrayList;
    109import java.util.Collection;
    1110import java.util.Collections;
    12 import java.util.Date;
    1311import java.util.HashMap;
    1412import java.util.Map;
     
    2220import org.openstreetmap.josm.tools.CheckParameterUtil;
    2321import org.openstreetmap.josm.tools.Logging;
     22import org.openstreetmap.josm.tools.UncheckedParseException;
    2423import org.openstreetmap.josm.tools.Utils;
    2524import org.openstreetmap.josm.tools.date.DateUtils;
     
    4544    private Bounds bounds;
    4645    /** the date after which changesets have been closed this query is restricted to. null, if no restriction to closure date applies */
    47     private Date closedAfter;
     46    private Instant closedAfter;
    4847    /** the date before which changesets have been created this query is restricted to. null, if no restriction to creation date applies */
    49     private Date createdBefore;
     48    private Instant createdBefore;
    5049    /** indicates whether only open changesets are queried. null, if no restrictions regarding open changesets apply */
    5150    private Boolean open;
     
    155154     * @since 14039
    156155     */
    157     public Date getClosedAfter() {
    158         return DateUtils.cloneDate(closedAfter);
     156    public Instant getClosedAfter() {
     157        return closedAfter;
    159158    }
    160159
     
    166165     * @since 14039
    167166     */
    168     public Date getCreatedBefore() {
    169         return DateUtils.cloneDate(createdBefore);
     167    public Instant getCreatedBefore() {
     168        return createdBefore;
    170169    }
    171170
     
    270269     * @throws IllegalArgumentException if d is null
    271270     */
    272     public ChangesetQuery closedAfter(Date d) {
     271    public ChangesetQuery closedAfter(Instant d) {
    273272        CheckParameterUtil.ensureParameterNotNull(d, "d");
    274         this.closedAfter = DateUtils.cloneDate(d);
     273        this.closedAfter = d;
    275274        return this;
    276275    }
     
    287286     * @throws IllegalArgumentException if createdBefore is null
    288287     */
    289     public ChangesetQuery closedAfterAndCreatedBefore(Date closedAfter, Date createdBefore) {
     288    public ChangesetQuery closedAfterAndCreatedBefore(Instant closedAfter, Instant createdBefore) {
    290289        CheckParameterUtil.ensureParameterNotNull(closedAfter, "closedAfter");
    291290        CheckParameterUtil.ensureParameterNotNull(createdBefore, "createdBefore");
    292         this.closedAfter = DateUtils.cloneDate(closedAfter);
    293         this.createdBefore = DateUtils.cloneDate(createdBefore);
     291        this.closedAfter = closedAfter;
     292        this.createdBefore = createdBefore;
    294293        return this;
    295294    }
     
    357356                sb.append('&');
    358357            }
    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);
    362360        } else if (closedAfter != null) {
    363361            if (sb.length() > 0) {
    364362                sb.append('&');
    365363            }
    366             DateFormat df = DateUtils.newIsoDateTimeFormat();
    367             sb.append("time=").append(df.format(closedAfter));
     364            sb.append("time=").append(closedAfter);
    368365        }
    369366
     
    466463        }
    467464
    468         protected Date parseDate(String value, String parameter) throws ChangesetQueryUrlException {
     465        protected Instant parseDate(String value, String parameter) throws ChangesetQueryUrlException {
    469466            if (value == null || value.trim().isEmpty())
    470467                throw new ChangesetQueryUrlException(
    471468                        tr("Unexpected value for ''{0}'' in changeset query url, got {1}", parameter, value));
    472             DateFormat formatter = DateUtils.newIsoDateTimeFormat();
    473469            try {
    474                 return formatter.parse(value);
    475             } catch (ParseException e) {
     470                return DateUtils.parseInstant(value);
     471            } catch (UncheckedParseException e) {
    476472                throw new ChangesetQueryUrlException(
    477473                        tr("Unexpected value for ''{0}'' in changeset query url, got {1}", parameter, value), e);
     
    479475        }
    480476
    481         protected Date[] parseTime(String value) throws ChangesetQueryUrlException {
     477        protected Instant[] parseTime(String value) throws ChangesetQueryUrlException {
    482478            String[] dates = value.split(",", -1);
    483479            if (dates.length == 0 || dates.length > 2)
     
    485481                        tr("Unexpected value for ''{0}'' in changeset query url, got {1}", "time", value));
    486482            if (dates.length == 1)
    487                 return new Date[]{parseDate(dates[0], "time")};
     483                return new Instant[]{parseDate(dates[0], "time")};
    488484            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[]{};
    491487        }
    492488
     
    524520                    break;
    525521                case "time":
    526                     Date[] dates = parseTime(entry.getValue());
     522                    Instant[] dates = parseTime(entry.getValue());
    527523                    switch(dates.length) {
    528524                    case 1:
Note: See TracChangeset for help on using the changeset viewer.