Changeset 17717 in josm
- Timestamp:
- 2021-04-09T00:19:53+02:00 (4 years ago)
- Location:
- trunk
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/Changeset.java
r16628 r17717 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.time.Instant; 6 7 import java.util.ArrayList; 7 8 import java.util.Collection; 8 9 import java.util.Collections; 9 import java.util.Date;10 10 import java.util.HashMap; 11 11 import java.util.List; … … 17 17 import org.openstreetmap.josm.data.coor.LatLon; 18 18 import org.openstreetmap.josm.tools.CheckParameterUtil; 19 import org.openstreetmap.josm.tools.date.DateUtils;20 19 21 20 /** … … 34 33 private User user; 35 34 /** date this changeset was created at */ 36 private DatecreatedAt;35 private Instant createdAt; 37 36 /** the date this changeset was closed at*/ 38 private DateclosedAt;37 private Instant closedAt; 39 38 /** indicates whether this changeset is still open or not */ 40 39 private boolean open; … … 104 103 final Changeset changeset = new Changeset(primitive.getChangesetId()); 105 104 changeset.setUser(primitive.getUser()); 106 changeset.setCreatedAt(primitive.getTimestamp() ); // not accurate in all cases105 changeset.setCreatedAt(primitive.getTimestamp().toInstant()); // not accurate in all cases 107 106 return changeset; 108 107 } … … 174 173 * @return the changeset creation date 175 174 */ 176 public DategetCreatedAt() {177 return DateUtils.cloneDate(createdAt);175 public Instant getCreatedAt() { 176 return createdAt; 178 177 } 179 178 … … 182 181 * @param createdAt changeset creation date 183 182 */ 184 public void setCreatedAt( DatecreatedAt) {185 this.createdAt = DateUtils.cloneDate(createdAt);183 public void setCreatedAt(Instant createdAt) { 184 this.createdAt = createdAt; 186 185 } 187 186 … … 190 189 * @return the changeset closure date 191 190 */ 192 public DategetClosedAt() {193 return DateUtils.cloneDate(closedAt);191 public Instant getClosedAt() { 192 return closedAt; 194 193 } 195 194 … … 198 197 * @param closedAt changeset closure date 199 198 */ 200 public void setClosedAt( DateclosedAt) {201 this.closedAt = DateUtils.cloneDate(closedAt);199 public void setClosedAt(Instant closedAt) { 200 this.closedAt = closedAt; 202 201 } 203 202 … … 427 426 return; 428 427 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; 431 430 this.open = other.open; 432 431 this.min = other.min; -
trunk/src/org/openstreetmap/josm/gui/dialogs/changeset/AbstractCellRenderer.java
r7937 r17717 5 5 6 6 import java.awt.Font; 7 import java.t ext.DateFormat;8 import java. util.Date;7 import java.time.Instant; 8 import java.time.format.FormatStyle; 9 9 10 10 import javax.swing.JComponent; … … 66 66 } 67 67 68 protected void render Date(Dated) {68 protected void renderInstant(Instant d) { 69 69 if (d == null) { 70 70 setText(""); 71 71 } else { 72 setText(DateUtils. formatDateTime(d, DateFormat.SHORT, DateFormat.SHORT));72 setText(DateUtils.getDateTimeFormatter(FormatStyle.SHORT, FormatStyle.SHORT).format(d)); 73 73 } 74 74 setToolTipText(null); -
trunk/src/org/openstreetmap/josm/gui/dialogs/changeset/ChangesetCacheTableCellRenderer.java
r14231 r17717 62 62 case 2: /* open/closed */ renderOpen(cs); break; 63 63 case 3: /* user */ renderUser(cs.getUser()); break; 64 case 4: /* created at */ render Date(cs.getCreatedAt()); break;65 case 5: /* closed at */ render Date(cs.getClosedAt()); break;64 case 4: /* created at */ renderInstant(cs.getCreatedAt()); break; 65 case 5: /* closed at */ renderInstant(cs.getClosedAt()); break; 66 66 case 6: /* changes */ renderChanges(cs); break; 67 67 case 7: /* discussions */ renderDiscussions(cs); break; -
trunk/src/org/openstreetmap/josm/gui/dialogs/changeset/ChangesetDetailPanel.java
r16436 r17717 13 13 import java.beans.PropertyChangeEvent; 14 14 import java.beans.PropertyChangeListener; 15 import java.text.DateFormat; 15 import java.time.Instant; 16 import java.time.format.DateTimeFormatter; 17 import java.time.format.FormatStyle; 16 18 import java.util.Collections; 17 import java.util.Date;18 19 import java.util.Set; 19 20 import java.util.stream.Collectors; … … 228 229 } 229 230 tfUser.setText(msg); 230 Date Format sdf = DateUtils.getDateTimeFormat(DateFormat.SHORT, DateFormat.SHORT);231 232 DatecreatedDate = cs.getCreatedAt();233 DateclosedDate = cs.getClosedAt();231 DateTimeFormatter sdf = DateUtils.getDateTimeFormatter(FormatStyle.SHORT, FormatStyle.SHORT); 232 233 Instant createdDate = cs.getCreatedAt(); 234 Instant closedDate = cs.getClosedAt(); 234 235 tfCreatedOn.setText(createdDate == null ? "" : sdf.format(createdDate)); 235 236 tfClosedOn.setText(closedDate == null ? "" : sdf.format(closedDate)); -
trunk/src/org/openstreetmap/josm/gui/dialogs/changeset/ChangesetDiscussionTableCellRenderer.java
r17333 r17717 3 3 4 4 import java.awt.Component; 5 import java. util.Date;5 import java.time.Instant; 6 6 7 7 import javax.swing.JComponent; … … 27 27 switch(column) { 28 28 case 0: 29 render Date((Date) value);29 renderInstant((Instant) value); 30 30 break; 31 31 case 1: -
trunk/src/org/openstreetmap/josm/gui/io/ChangesetCellRenderer.java
r13761 r17717 5 5 6 6 import java.awt.Component; 7 import java.t ext.DateFormat;8 import java. util.Date;7 import java.time.Instant; 8 import java.time.format.FormatStyle; 9 9 10 10 import javax.swing.ImageIcon; … … 38 38 StringBuilder sb = new StringBuilder(64); 39 39 sb.append("<html><strong>").append(tr("Changeset id:")).append("</strong>").append(cs.getId()).append("<br>"); 40 DatecreatedDate = cs.getCreatedAt();40 Instant createdDate = cs.getCreatedAt(); 41 41 if (createdDate != null) { 42 42 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>"); 44 44 } 45 45 String comment = cs.getComment(); -
trunk/src/org/openstreetmap/josm/io/ChangesetUpdater.java
r14326 r17717 57 57 List<Long> changesetIds = ChangesetCache.getInstance().getOpenChangesets().stream() 58 58 .filter(x -> x.getCreatedAt() != null 59 && now - x.getCreatedAt(). getTime() > TimeUnit.HOURS.toMillis(1))59 && now - x.getCreatedAt().toEpochMilli() > TimeUnit.HOURS.toMillis(1)) 60 60 .map(Changeset::getId) 61 61 .map(Integer::longValue) -
trunk/src/org/openstreetmap/josm/io/DiffResultProcessor.java
r14044 r17717 6 6 import java.io.IOException; 7 7 import java.io.StringReader; 8 import java.time.Instant; 8 9 import java.util.Collection; 9 10 import java.util.Collections; … … 151 152 p.setUser(cs.getUser()); 152 153 // 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)); 154 156 } 155 157 } -
trunk/src/org/openstreetmap/josm/io/OsmChangesetParser.java
r16630 r17717 96 96 current.setCreatedAt(null); 97 97 } else { 98 current.setCreatedAt(DateUtils. fromString(value));98 current.setCreatedAt(DateUtils.parseInstant(value)); 99 99 } 100 100 … … 104 104 current.setClosedAt(null); 105 105 } else { 106 current.setClosedAt(DateUtils. fromString(value));106 current.setClosedAt(DateUtils.parseInstant(value)); 107 107 } 108 108 -
trunk/src/org/openstreetmap/josm/io/OsmWriter.java
r17333 r17717 5 5 6 6 import java.io.PrintWriter; 7 import java.time.Instant; 7 8 import java.util.ArrayList; 8 9 import java.util.Collection; 9 10 import java.util.Comparator; 10 import java.util.Date;11 11 import java.util.List; 12 12 import java.util.Map.Entry; … … 299 299 out.print(" uid='"+cs.getUser().getId() +'\''); 300 300 } 301 DatecreatedDate = cs.getCreatedAt();301 Instant createdDate = cs.getCreatedAt(); 302 302 if (createdDate != null) { 303 out.print(" created_at='"+ DateUtils.fromDate(createdDate)+'\'');304 } 305 DateclosedDate = cs.getClosedAt();303 out.print(" created_at='"+ createdDate +'\''); 304 } 305 Instant closedDate = cs.getClosedAt(); 306 306 if (closedDate != null) { 307 out.print(" closed_at='"+ DateUtils.fromDate(closedDate)+'\'');307 out.print(" closed_at='"+ closedDate +'\''); 308 308 } 309 309 out.print(" open='"+ (cs.isOpen() ? "true" : "false") +'\''); -
trunk/test/unit/org/openstreetmap/josm/data/osm/ChangesetTest.java
r17275 r17717 8 8 import static org.openstreetmap.josm.data.osm.Changeset.MAX_CHANGESET_TAG_LENGTH; 9 9 10 import java.util.Calendar; 10 import java.time.Duration; 11 import java.time.Instant; 11 12 import java.util.Collection; 12 import java.util.Date;13 13 import java.util.HashMap; 14 14 import java.util.Map; … … 138 138 } 139 139 140 private static Date yesterday() {141 final Calendar cal = Calendar.getInstance();142 cal.add(Calendar.DATE, -1);143 return cal.getTime();144 }145 146 140 /** 147 141 * Unit test of method {@link Changeset#hasEqualSemanticAttributes}. … … 149 143 @Test 150 144 void testHasEqualSemanticAttributes() { 151 Date today = new Date(); 145 Instant today = Instant.now(); 146 Instant yesterday = today.minus(Duration.ofDays(1)); 152 147 Changeset cs1 = new Changeset(); 153 148 Changeset cs2 = new Changeset(); … … 158 153 cs2.setClosedAt(today); 159 154 assertFalse(cs1.hasEqualSemanticAttributes(cs2)); 160 cs1.setClosedAt(yesterday ());155 cs1.setClosedAt(yesterday); 161 156 cs2.setClosedAt(today); 162 157 assertFalse(cs1.hasEqualSemanticAttributes(cs2)); … … 168 163 cs2.setCreatedAt(today); 169 164 assertFalse(cs1.hasEqualSemanticAttributes(cs2)); 170 cs1.setCreatedAt(yesterday ());165 cs1.setCreatedAt(yesterday); 171 166 cs2.setCreatedAt(today); 172 167 assertFalse(cs1.hasEqualSemanticAttributes(cs2)); -
trunk/test/unit/org/openstreetmap/josm/gui/io/ChangesetCellRendererTest.java
r17275 r17717 12 12 13 13 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 14 15 import java.time.Instant; 14 16 15 17 /** … … 31 33 JList<Changeset> list = new JList<>(); 32 34 Changeset cs = new Changeset(); 35 cs.setCreatedAt(Instant.EPOCH); 33 36 ChangesetCellRenderer c = new ChangesetCellRenderer(); 34 37 assertEquals(c, c.getListCellRendererComponent(list, cs, 0, false, false)); -
trunk/test/unit/org/openstreetmap/josm/io/OsmWriterTest.java
r17275 r17717 11 11 import java.io.StringWriter; 12 12 import java.nio.charset.StandardCharsets; 13 import java.time.Instant; 13 14 import java.util.ArrayList; 14 15 import java.util.Arrays; … … 16 17 import java.util.List; 17 18 19 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 18 20 import org.junit.jupiter.api.Test; 21 import org.junit.jupiter.api.extension.RegisterExtension; 19 22 import org.openstreetmap.josm.data.coor.LatLon; 20 23 import org.openstreetmap.josm.data.osm.Changeset; … … 24 27 import org.openstreetmap.josm.data.osm.UploadPolicy; 25 28 import org.openstreetmap.josm.data.osm.User; 29 import org.openstreetmap.josm.testutils.JOSMTestRules; 26 30 27 31 /** … … 29 33 */ 30 34 class OsmWriterTest { 35 36 /** 37 * Setup rule 38 */ 39 @RegisterExtension 40 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") 41 public JOSMTestRules test = new JOSMTestRules(); 31 42 32 43 /** … … 107 118 cs.setMin(new LatLon(12., 34.)); 108 119 cs.setMax(new LatLon(56., 78.)); 120 cs.setCreatedAt(Instant.EPOCH); 109 121 try (StringWriter stringWriter = new StringWriter(); 110 122 OsmWriter osmWriter = OsmWriterFactory.createOsmWriter(new PrintWriter(stringWriter), true, OsmWriter.DEFAULT_API_VERSION)) { 111 123 osmWriter.visit(cs); 112 assertEquals(" <changeset id='38038262' user='<anonymous>' uid='-1' open='false' " +124 assertEquals(" <changeset id='38038262' user='<anonymous>' uid='-1' created_at='1970-01-01T00:00:00Z' open='false' " + 113 125 "min_lon='34.0' min_lat='12.0' max_lon='78.0' max_lat='56.0'>\n </changeset>\n", 114 126 stringWriter.toString().replace("\r", ""));
Note:
See TracChangeset
for help on using the changeset viewer.