|
15 | 15 | import java.nio.file.Paths; |
16 | 16 | import java.text.DecimalFormat; |
17 | 17 | 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; |
19 | 21 | import java.util.ArrayList; |
20 | 22 | import java.util.Arrays; |
21 | | -import java.util.Calendar; |
22 | 23 | import java.util.Collection; |
23 | 24 | import java.util.Collections; |
24 | | -import java.util.Date; |
25 | 25 | import java.util.HashMap; |
26 | 26 | import java.util.LinkedList; |
27 | 27 | import java.util.List; |
@@ -817,16 +817,15 @@ void doSameUrlButDifferentDates() { |
817 | 817 | String ed2 = ed; |
818 | 818 | Matcher m = pattern.matcher(ed); |
819 | 819 | 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(); |
826 | 825 | if (m.group(4) != null) |
827 | | - ed2 += "-" + String.format("%02d", cal.get(Calendar.MONTH)+1); |
| 826 | + ed2 += "-" + String.format("%02d", date.getMonthValue()); |
828 | 827 | if (m.group(6) != null) |
829 | | - ed2 += "-" + String.format("%02d", cal.get(Calendar.DAY_OF_MONTH)); |
| 828 | + ed2 += "-" + String.format("%02d", date.getDayOfMonth()); |
830 | 829 | } |
831 | 830 | String ef2 = ed2.replaceAll("\\A-;", "").replaceAll(";-\\z", "").replaceAll("\\A([0-9-]+);\\1\\z", "$1"); |
832 | 831 | if (!ed.equals(jd) && !ef.equals(jd) && !ed2.equals(jd) && !ef2.equals(jd)) { |
@@ -1305,8 +1304,8 @@ else if (80 == port || 443 == port) { |
1305 | 1304 | myprintln("~ JOSM-Date '"+d+"' is strange: "+getDescription(j)); |
1306 | 1305 | } else { |
1307 | 1306 | 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)); |
1310 | 1309 | if (second.compareTo(first) < 0) { |
1311 | 1310 | myprintln("~ JOSM-Date '"+d+"' is strange (second earlier than first): "+getDescription(j)); |
1312 | 1311 | } |
@@ -1392,16 +1391,16 @@ else if (!end.isEmpty()) |
1392 | 1391 | return ""; |
1393 | 1392 | } |
1394 | 1393 |
|
1395 | | - static Date verifyDate(String year, String month, String day) throws ParseException { |
| 1394 | + static LocalDate verifyDate(String year, String month, String day) throws ParseException { |
1396 | 1395 | String date; |
1397 | 1396 | if (year == null) { |
1398 | 1397 | date = "3000-01-01"; |
1399 | 1398 | } else { |
1400 | 1399 | date = year + "-" + (month == null ? "01" : month) + "-" + (day == null ? "01" : day); |
1401 | 1400 | } |
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); |
1405 | 1404 | } |
1406 | 1405 |
|
1407 | 1406 | static String getId(Object e) { |
|
0 commit comments