Changeset 17717 in josm


Ignore:
Timestamp:
2021-04-09T00:19:53+02:00 (4 years ago)
Author:
simon04
Message:

see #14176 - Migrate Changeset to Instant

Location:
trunk
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/osm/Changeset.java

    r16628 r17717  
    44import static org.openstreetmap.josm.tools.I18n.tr;
    55
     6import java.time.Instant;
    67import java.util.ArrayList;
    78import java.util.Collection;
    89import java.util.Collections;
    9 import java.util.Date;
    1010import java.util.HashMap;
    1111import java.util.List;
     
    1717import org.openstreetmap.josm.data.coor.LatLon;
    1818import org.openstreetmap.josm.tools.CheckParameterUtil;
    19 import org.openstreetmap.josm.tools.date.DateUtils;
    2019
    2120/**
     
    3433    private User user;
    3534    /** date this changeset was created at */
    36     private Date createdAt;
     35    private Instant createdAt;
    3736    /** the date this changeset was closed at*/
    38     private Date closedAt;
     37    private Instant closedAt;
    3938    /** indicates whether this changeset is still open or not */
    4039    private boolean open;
     
    104103        final Changeset changeset = new Changeset(primitive.getChangesetId());
    105104        changeset.setUser(primitive.getUser());
    106         changeset.setCreatedAt(primitive.getTimestamp()); // not accurate in all cases
     105        changeset.setCreatedAt(primitive.getTimestamp().toInstant()); // not accurate in all cases
    107106        return changeset;
    108107    }
     
    174173     * @return the changeset creation date
    175174     */
    176     public Date getCreatedAt() {
    177         return DateUtils.cloneDate(createdAt);
     175    public Instant getCreatedAt() {
     176        return createdAt;
    178177    }
    179178
     
    182181     * @param createdAt changeset creation date
    183182     */
    184     public void setCreatedAt(Date createdAt) {
    185         this.createdAt = DateUtils.cloneDate(createdAt);
     183    public void setCreatedAt(Instant createdAt) {
     184        this.createdAt = createdAt;
    186185    }
    187186
     
    190189     * @return the changeset closure date
    191190     */
    192     public Date getClosedAt() {
    193         return DateUtils.cloneDate(closedAt);
     191    public Instant getClosedAt() {
     192        return closedAt;
    194193    }
    195194
     
    198197     * @param closedAt changeset closure date
    199198     */
    200     public void setClosedAt(Date closedAt) {
    201         this.closedAt = DateUtils.cloneDate(closedAt);
     199    public void setClosedAt(Instant closedAt) {
     200        this.closedAt = closedAt;
    202201    }
    203202
     
    427426            return;
    428427        this.user = other.user;
    429         this.createdAt = DateUtils.cloneDate(other.createdAt);
    430         this.closedAt = DateUtils.cloneDate(other.closedAt);
     428        this.createdAt = other.createdAt;
     429        this.closedAt = other.closedAt;
    431430        this.open = other.open;
    432431        this.min = other.min;
  • trunk/src/org/openstreetmap/josm/gui/dialogs/changeset/AbstractCellRenderer.java

    r7937 r17717  
    55
    66import java.awt.Font;
    7 import java.text.DateFormat;
    8 import java.util.Date;
     7import java.time.Instant;
     8import java.time.format.FormatStyle;
    99
    1010import javax.swing.JComponent;
     
    6666    }
    6767
    68     protected void renderDate(Date d) {
     68    protected void renderInstant(Instant d) {
    6969        if (d == null) {
    7070            setText("");
    7171        } else {
    72             setText(DateUtils.formatDateTime(d, DateFormat.SHORT, DateFormat.SHORT));
     72            setText(DateUtils.getDateTimeFormatter(FormatStyle.SHORT, FormatStyle.SHORT).format(d));
    7373        }
    7474        setToolTipText(null);
  • trunk/src/org/openstreetmap/josm/gui/dialogs/changeset/ChangesetCacheTableCellRenderer.java

    r14231 r17717  
    6262        case 2: /* open/closed */ renderOpen(cs); break;
    6363        case 3: /* user */ renderUser(cs.getUser()); break;
    64         case 4: /* created at */ renderDate(cs.getCreatedAt()); break;
    65         case 5: /* closed at */ renderDate(cs.getClosedAt()); break;
     64        case 4: /* created at */ renderInstant(cs.getCreatedAt()); break;
     65        case 5: /* closed at */ renderInstant(cs.getClosedAt()); break;
    6666        case 6: /* changes */ renderChanges(cs); break;
    6767        case 7: /* discussions */ renderDiscussions(cs); break;
  • trunk/src/org/openstreetmap/josm/gui/dialogs/changeset/ChangesetDetailPanel.java

    r16436 r17717  
    1313import java.beans.PropertyChangeEvent;
    1414import java.beans.PropertyChangeListener;
    15 import java.text.DateFormat;
     15import java.time.Instant;
     16import java.time.format.DateTimeFormatter;
     17import java.time.format.FormatStyle;
    1618import java.util.Collections;
    17 import java.util.Date;
    1819import java.util.Set;
    1920import java.util.stream.Collectors;
     
    228229        }
    229230        tfUser.setText(msg);
    230         DateFormat sdf = DateUtils.getDateTimeFormat(DateFormat.SHORT, DateFormat.SHORT);
    231 
    232         Date createdDate = cs.getCreatedAt();
    233         Date closedDate = cs.getClosedAt();
     231        DateTimeFormatter sdf = DateUtils.getDateTimeFormatter(FormatStyle.SHORT, FormatStyle.SHORT);
     232
     233        Instant createdDate = cs.getCreatedAt();
     234        Instant closedDate = cs.getClosedAt();
    234235        tfCreatedOn.setText(createdDate == null ? "" : sdf.format(createdDate));
    235236        tfClosedOn.setText(closedDate == null ? "" : sdf.format(closedDate));
  • trunk/src/org/openstreetmap/josm/gui/dialogs/changeset/ChangesetDiscussionTableCellRenderer.java

    r17333 r17717  
    33
    44import java.awt.Component;
    5 import java.util.Date;
     5import java.time.Instant;
    66
    77import javax.swing.JComponent;
     
    2727        switch(column) {
    2828        case 0:
    29             renderDate((Date) value);
     29            renderInstant((Instant) value);
    3030            break;
    3131        case 1:
  • trunk/src/org/openstreetmap/josm/gui/io/ChangesetCellRenderer.java

    r13761 r17717  
    55
    66import java.awt.Component;
    7 import java.text.DateFormat;
    8 import java.util.Date;
     7import java.time.Instant;
     8import java.time.format.FormatStyle;
    99
    1010import javax.swing.ImageIcon;
     
    3838        StringBuilder sb = new StringBuilder(64);
    3939        sb.append("<html><strong>").append(tr("Changeset id:")).append("</strong>").append(cs.getId()).append("<br>");
    40         Date createdDate = cs.getCreatedAt();
     40        Instant createdDate = cs.getCreatedAt();
    4141        if (createdDate != null) {
    4242            sb.append("<strong>").append(tr("Created at:")).append("</strong>").append(
    43                     DateUtils.formatDateTime(createdDate, DateFormat.SHORT, DateFormat.SHORT)).append("<br>");
     43                    DateUtils.getDateTimeFormatter(FormatStyle.SHORT, FormatStyle.SHORT).format(createdDate)).append("<br>");
    4444        }
    4545        String comment = cs.getComment();
  • trunk/src/org/openstreetmap/josm/io/ChangesetUpdater.java

    r14326 r17717  
    5757        List<Long> changesetIds = ChangesetCache.getInstance().getOpenChangesets().stream()
    5858            .filter(x -> x.getCreatedAt() != null
    59                 && now - x.getCreatedAt().getTime() > TimeUnit.HOURS.toMillis(1))
     59                && now - x.getCreatedAt().toEpochMilli() > TimeUnit.HOURS.toMillis(1))
    6060            .map(Changeset::getId)
    6161            .map(Integer::longValue)
  • trunk/src/org/openstreetmap/josm/io/DiffResultProcessor.java

    r14044 r17717  
    66import java.io.IOException;
    77import java.io.StringReader;
     8import java.time.Instant;
    89import java.util.Collection;
    910import java.util.Collections;
     
    151152                    p.setUser(cs.getUser());
    152153                    // TODO is there a way to obtain the timestamp for non-closed changesets?
    153                     p.setTimestamp(Utils.firstNonNull(cs.getClosedAt(), new Date()));
     154                    Instant instant = Utils.firstNonNull(cs.getClosedAt(), Instant.now());
     155                    p.setTimestamp(Date.from(instant));
    154156                }
    155157            }
  • trunk/src/org/openstreetmap/josm/io/OsmChangesetParser.java

    r16630 r17717  
    9696                current.setCreatedAt(null);
    9797            } else {
    98                 current.setCreatedAt(DateUtils.fromString(value));
     98                current.setCreatedAt(DateUtils.parseInstant(value));
    9999            }
    100100
     
    104104                current.setClosedAt(null);
    105105            } else {
    106                 current.setClosedAt(DateUtils.fromString(value));
     106                current.setClosedAt(DateUtils.parseInstant(value));
    107107            }
    108108
  • trunk/src/org/openstreetmap/josm/io/OsmWriter.java

    r17333 r17717  
    55
    66import java.io.PrintWriter;
     7import java.time.Instant;
    78import java.util.ArrayList;
    89import java.util.Collection;
    910import java.util.Comparator;
    10 import java.util.Date;
    1111import java.util.List;
    1212import java.util.Map.Entry;
     
    299299            out.print(" uid='"+cs.getUser().getId() +'\'');
    300300        }
    301         Date createdDate = cs.getCreatedAt();
     301        Instant createdDate = cs.getCreatedAt();
    302302        if (createdDate != null) {
    303             out.print(" created_at='"+DateUtils.fromDate(createdDate) +'\'');
    304         }
    305         Date closedDate = cs.getClosedAt();
     303            out.print(" created_at='"+ createdDate +'\'');
     304        }
     305        Instant closedDate = cs.getClosedAt();
    306306        if (closedDate != null) {
    307             out.print(" closed_at='"+DateUtils.fromDate(closedDate) +'\'');
     307            out.print(" closed_at='"+ closedDate +'\'');
    308308        }
    309309        out.print(" open='"+ (cs.isOpen() ? "true" : "false") +'\'');
  • trunk/test/unit/org/openstreetmap/josm/data/osm/ChangesetTest.java

    r17275 r17717  
    88import static org.openstreetmap.josm.data.osm.Changeset.MAX_CHANGESET_TAG_LENGTH;
    99
    10 import java.util.Calendar;
     10import java.time.Duration;
     11import java.time.Instant;
    1112import java.util.Collection;
    12 import java.util.Date;
    1313import java.util.HashMap;
    1414import java.util.Map;
     
    138138    }
    139139
    140     private static Date yesterday() {
    141         final Calendar cal = Calendar.getInstance();
    142         cal.add(Calendar.DATE, -1);
    143         return cal.getTime();
    144     }
    145 
    146140    /**
    147141     * Unit test of method {@link Changeset#hasEqualSemanticAttributes}.
     
    149143    @Test
    150144    void testHasEqualSemanticAttributes() {
    151         Date today = new Date();
     145        Instant today = Instant.now();
     146        Instant yesterday = today.minus(Duration.ofDays(1));
    152147        Changeset cs1 = new Changeset();
    153148        Changeset cs2 = new Changeset();
     
    158153        cs2.setClosedAt(today);
    159154        assertFalse(cs1.hasEqualSemanticAttributes(cs2));
    160         cs1.setClosedAt(yesterday());
     155        cs1.setClosedAt(yesterday);
    161156        cs2.setClosedAt(today);
    162157        assertFalse(cs1.hasEqualSemanticAttributes(cs2));
     
    168163        cs2.setCreatedAt(today);
    169164        assertFalse(cs1.hasEqualSemanticAttributes(cs2));
    170         cs1.setCreatedAt(yesterday());
     165        cs1.setCreatedAt(yesterday);
    171166        cs2.setCreatedAt(today);
    172167        assertFalse(cs1.hasEqualSemanticAttributes(cs2));
  • trunk/test/unit/org/openstreetmap/josm/gui/io/ChangesetCellRendererTest.java

    r17275 r17717  
    1212
    1313import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
     14
     15import java.time.Instant;
    1416
    1517/**
     
    3133        JList<Changeset> list = new JList<>();
    3234        Changeset cs = new Changeset();
     35        cs.setCreatedAt(Instant.EPOCH);
    3336        ChangesetCellRenderer c = new ChangesetCellRenderer();
    3437        assertEquals(c, c.getListCellRendererComponent(list, cs, 0, false, false));
  • trunk/test/unit/org/openstreetmap/josm/io/OsmWriterTest.java

    r17275 r17717  
    1111import java.io.StringWriter;
    1212import java.nio.charset.StandardCharsets;
     13import java.time.Instant;
    1314import java.util.ArrayList;
    1415import java.util.Arrays;
     
    1617import java.util.List;
    1718
     19import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
    1820import org.junit.jupiter.api.Test;
     21import org.junit.jupiter.api.extension.RegisterExtension;
    1922import org.openstreetmap.josm.data.coor.LatLon;
    2023import org.openstreetmap.josm.data.osm.Changeset;
     
    2427import org.openstreetmap.josm.data.osm.UploadPolicy;
    2528import org.openstreetmap.josm.data.osm.User;
     29import org.openstreetmap.josm.testutils.JOSMTestRules;
    2630
    2731/**
     
    2933 */
    3034class OsmWriterTest {
     35
     36    /**
     37     * Setup rule
     38     */
     39    @RegisterExtension
     40    @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
     41    public JOSMTestRules test = new JOSMTestRules();
    3142
    3243    /**
     
    107118        cs.setMin(new LatLon(12., 34.));
    108119        cs.setMax(new LatLon(56., 78.));
     120        cs.setCreatedAt(Instant.EPOCH);
    109121        try (StringWriter stringWriter = new StringWriter();
    110122             OsmWriter osmWriter = OsmWriterFactory.createOsmWriter(new PrintWriter(stringWriter), true, OsmWriter.DEFAULT_API_VERSION)) {
    111123            osmWriter.visit(cs);
    112             assertEquals("  <changeset id='38038262' user='&lt;anonymous&gt;' uid='-1' open='false' " +
     124            assertEquals("  <changeset id='38038262' user='&lt;anonymous&gt;' uid='-1' created_at='1970-01-01T00:00:00Z' open='false' " +
    113125                            "min_lon='34.0' min_lat='12.0' max_lon='78.0' max_lat='56.0'>\n  </changeset>\n",
    114126                    stringWriter.toString().replace("\r", ""));
Note: See TracChangeset for help on using the changeset viewer.