Changeset 19538 in josm
- Timestamp:
- 2026-02-20T12:50:19+01:00 (5 hours ago)
- File:
-
- 1 edited
-
trunk/scripts/SyncEditorLayerIndex.java (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/scripts/SyncEditorLayerIndex.java
r19449 r19538 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; … … 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"); … … 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)); … … 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) { … … 1400 1399 date = year + "-" + (month == null ? "01" : month) + "-" + (day == null ? "01" : day); 1401 1400 } 1402 SimpleDateFormatdf = 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
Note:
See TracChangeset
for help on using the changeset viewer.
