Changeset 19538 in josm


Ignore:
Timestamp:
2026-02-20T12:50:19+01:00 (5 hours ago)
Author:
stoecker
Message:

fix one more PMD, see #24635, drop java.util.Date in SyncEditorLayerIndex

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/scripts/SyncEditorLayerIndex.java

    r19449 r19538  
    1616import java.text.DecimalFormat;
    1717import java.text.ParseException;
    18 import java.text.SimpleDateFormat;
     18import java.time.LocalDate;
     19import java.time.format.DateTimeFormatter;
     20import java.time.format.ResolverStyle;
    1921import java.util.ArrayList;
    2022import java.util.Arrays;
    21 import java.util.Calendar;
    2223import java.util.Collection;
    2324import java.util.Collections;
    24 import java.util.Date;
    2525import java.util.HashMap;
    2626import java.util.LinkedList;
     
    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");
     
    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));
     
    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) {
     
    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
Note: See TracChangeset for help on using the changeset viewer.