Ignore:
Timestamp:
2015-07-04T18:31:20+02:00 (10 years ago)
Author:
Don-vip
Message:

fix #11650 - performance: avoid creation of Date objects when it is not needed (patch by shinigami, modified slightly)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/tools/date/DateUtils.java

    r8564 r8565  
    119119    }
    120120
     121    private static String toXmlFormat(GregorianCalendar cal) {
     122        XMLGregorianCalendar xgc = XML_DATE.newXMLGregorianCalendar(cal);
     123        if (cal.get(Calendar.MILLISECOND) == 0) {
     124            xgc.setFractionalSecond(null);
     125        }
     126        return xgc.toXMLFormat();
     127    }
     128
     129    /**
     130     * Formats a date to the XML UTC format regardless of current locale.
     131     * @param timestamp number of seconds since the epoch
     132     * @return The formatted date
     133     */
     134    public static synchronized String fromTimestamp(int timestamp) {
     135        calendar.setTimeInMillis(timestamp * 1000L);
     136        return toXmlFormat(calendar);
     137    }
     138
    121139    /**
    122140     * Formats a date to the XML UTC format regardless of current locale.
     
    126144    public static synchronized String fromDate(Date date) {
    127145        calendar.setTime(date);
    128         XMLGregorianCalendar xgc = XML_DATE.newXMLGregorianCalendar(calendar);
    129         if (calendar.get(Calendar.MILLISECOND) == 0) xgc.setFractionalSecond(null);
    130         return xgc.toXMLFormat();
     146        return toXmlFormat(calendar);
    131147    }
    132148
Note: See TracChangeset for help on using the changeset viewer.