Skip to content

Commit 6285669

Browse files
author
stoecker
committed
fix one more PMD, see #24635, drop java.util.Date in SyncEditorLayerIndex
git-svn-id: https://josm.openstreetmap.de/svn/trunk@19538 0c6e7542-c601-0410-84e7-c038aed88b3b
1 parent 471f818 commit 6285669

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

scripts/SyncEditorLayerIndex.java

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@
1515
import java.nio.file.Paths;
1616
import java.text.DecimalFormat;
1717
import java.text.ParseException;
18-
import java.text.SimpleDateFormat;
18+
import java.time.LocalDate;
19+
import java.time.format.DateTimeFormatter;
20+
import java.time.format.ResolverStyle;
1921
import java.util.ArrayList;
2022
import java.util.Arrays;
21-
import java.util.Calendar;
2223
import java.util.Collection;
2324
import java.util.Collections;
24-
import java.util.Date;
2525
import java.util.HashMap;
2626
import java.util.LinkedList;
2727
import java.util.List;
@@ -817,16 +817,15 @@ void doSameUrlButDifferentDates() {
817817
String ed2 = ed;
818818
Matcher m = pattern.matcher(ed);
819819
if (m.matches()) {
820-
Calendar cal = Calendar.getInstance();
821-
cal.set(Integer.parseInt(m.group(2)),
822-
m.group(4) == null ? 0 : Integer.parseInt(m.group(4))-1,
823-
m.group(6) == null ? 1 : Integer.parseInt(m.group(6)));
824-
cal.add(Calendar.DAY_OF_MONTH, -1);
825-
ed2 = m.group(1) + cal.get(Calendar.YEAR);
820+
int year = Integer.parseInt(m.group(2));
821+
int month = (m.group(4) == null) ? 1 : Integer.parseInt(m.group(4));
822+
int day = (m.group(6) == null) ? 1 : Integer.parseInt(m.group(6));
823+
LocalDate date = LocalDate.of(year, month, day).minusDays(1);
824+
ed2 = m.group(1) + date.getYear();
826825
if (m.group(4) != null)
827-
ed2 += "-" + String.format("%02d", cal.get(Calendar.MONTH)+1);
826+
ed2 += "-" + String.format("%02d", date.getMonthValue());
828827
if (m.group(6) != null)
829-
ed2 += "-" + String.format("%02d", cal.get(Calendar.DAY_OF_MONTH));
828+
ed2 += "-" + String.format("%02d", date.getDayOfMonth());
830829
}
831830
String ef2 = ed2.replaceAll("\\A-;", "").replaceAll(";-\\z", "").replaceAll("\\A([0-9-]+);\\1\\z", "$1");
832831
if (!ed.equals(jd) && !ef.equals(jd) && !ed2.equals(jd) && !ef2.equals(jd)) {
@@ -1305,8 +1304,8 @@ else if (80 == port || 443 == port) {
13051304
myprintln("~ JOSM-Date '"+d+"' is strange: "+getDescription(j));
13061305
} else {
13071306
try {
1308-
Date first = verifyDate(m.group(2), m.group(4), m.group(6));
1309-
Date second = verifyDate(m.group(9), m.group(11), m.group(13));
1307+
LocalDate first = verifyDate(m.group(2), m.group(4), m.group(6));
1308+
LocalDate second = verifyDate(m.group(9), m.group(11), m.group(13));
13101309
if (second.compareTo(first) < 0) {
13111310
myprintln("~ JOSM-Date '"+d+"' is strange (second earlier than first): "+getDescription(j));
13121311
}
@@ -1392,16 +1391,16 @@ else if (!end.isEmpty())
13921391
return "";
13931392
}
13941393

1395-
static Date verifyDate(String year, String month, String day) throws ParseException {
1394+
static LocalDate verifyDate(String year, String month, String day) throws ParseException {
13961395
String date;
13971396
if (year == null) {
13981397
date = "3000-01-01";
13991398
} else {
14001399
date = year + "-" + (month == null ? "01" : month) + "-" + (day == null ? "01" : day);
14011400
}
1402-
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
1403-
df.setLenient(false);
1404-
return df.parse(date);
1401+
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("uuuu-MM-dd").withResolverStyle(ResolverStyle.STRICT);
1402+
1403+
return LocalDate.parse(date, formatter);
14051404
}
14061405

14071406
static String getId(Object e) {

0 commit comments

Comments
 (0)