Changeset 31842 in osm


Ignore:
Timestamp:
2015-12-17T16:48:19+01:00 (9 years ago)
Author:
floscher
Message:

[mapillary] Use 24h time for parsing/formatting timestamps

The uppercase HH is used for SimpleDateFormat, because the lowercase hh is for 12h time, whereas the uppercase one is for 24h time.
See https://docs.oracle.com/javase/8/docs/api/java/text/SimpleDateFormat.html

Location:
applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/MapillaryImportedImage.java

    r31799 r31842  
    5959    this.file = file;
    6060    try {
    61       this.capturedAt = MapillaryUtils.getEpoch(datetimeOriginal,
    62           "yyyy:MM:dd hh:mm:ss");
     61      this.capturedAt = MapillaryUtils.getEpoch(datetimeOriginal, "yyyy:MM:dd HH:mm:ss");
    6362    } catch (ParseException e) {
    6463      try {
    65         this.capturedAt = MapillaryUtils.getEpoch(datetimeOriginal,
    66             "yyyy/MM/dd hh:mm:ss");
     64        this.capturedAt = MapillaryUtils.getEpoch(datetimeOriginal, "yyyy/MM/dd HH:mm:ss");
    6765      } catch (ParseException e1) {
    6866        this.capturedAt = MapillaryUtils.currentTime();
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/io/export/MapillaryExportWriterThread.java

    r31840 r31842  
    129129        if (mimg instanceof MapillaryImportedImage)
    130130          exifDirectory.add(ExifTagConstants.EXIF_TAG_DATE_TIME_ORIGINAL,
    131               ((MapillaryImportedImage) mimg).getDate("yyyy/MM/dd hh:mm:ss"));
     131              ((MapillaryImportedImage) mimg).getDate("yyyy/MM/dd HH:mm:ss"));
    132132        else if (mimg instanceof MapillaryImage)
    133133          exifDirectory.add(ExifTagConstants.EXIF_TAG_DATE_TIME_ORIGINAL,
    134               ((MapillaryImage) mimg).getDate("yyyy/MM/dd hh/mm/ss"));
     134              ((MapillaryImage) mimg).getDate("yyyy/MM/dd HH/mm/ss"));
    135135        outputSet.setGPSInDegrees(mimg.getLatLon().lon(), mimg.getLatLon().lat());
    136136        OutputStream os = new BufferedOutputStream(new FileOutputStream(finalPath + ".jpg"));
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/oauth/UploadUtils.java

    r31841 r31842  
    175175    exifDirectory.removeField(ExifTagConstants.EXIF_TAG_DATE_TIME_ORIGINAL);
    176176    exifDirectory.add(ExifTagConstants.EXIF_TAG_DATE_TIME_ORIGINAL,
    177         ((MapillaryImportedImage) image).getDate("yyyy/MM/dd hh:mm:ss"));
     177        ((MapillaryImportedImage) image).getDate("yyyy/MM/dd HH:mm:ss"));
    178178
    179179    // Removes the ImageDescription tag, that causes problems in the upload.
  • applications/editors/josm/plugins/mapillary/src/org/openstreetmap/josm/plugins/mapillary/utils/MapillaryUtils.java

    r31838 r31842  
    7474
    7575  /**
    76    * Returns the current date.
     76   * Returns the current date formatted as EXIF timestamp.
     77   * As timezone the default timezone of the JVM is used ({@link java.util.TimeZone#getDefault()}).
    7778   *
    7879   * @return A {@code String} object containing the current date.
    7980   */
    8081  public static String currentDate() {
    81     Calendar cal = Calendar.getInstance();
    82     SimpleDateFormat formatter = new SimpleDateFormat("yyyy:MM:dd hh:mm:ss");
    83     return formatter.format(cal.getTime());
    84   }
    85 
    86   /**
    87    * Returns current time in Epoch format
     82    return new SimpleDateFormat("yyyy:MM:dd HH:mm:ss", Locale.UK).format(Calendar.getInstance().getTime());
     83  }
     84
     85  /**
     86   * Returns current time in Epoch format (milliseconds since 1970-01-01T00:00:00+0000)
    8887   *
    8988   * @return The current date in Epoch format.
    9089   */
    9190  public static long currentTime() {
    92     Calendar cal = Calendar.getInstance();
    93     return cal.getTimeInMillis();
     91    return Calendar.getInstance().getTimeInMillis();
     92  }
     93
     94  /**
     95   * Parses a string with a given format and returns the Epoch time.
     96   * If no timezone information is given, the default timezone of the JVM is used
     97   * ({@link java.util.TimeZone#getDefault()}).
     98   *
     99   * @param date The string containing the date.
     100   * @param format The format of the date.
     101   * @return The date in Epoch format.
     102   * @throws ParseException
     103   */
     104  public static long getEpoch(String date, String format) throws ParseException {
     105    return new SimpleDateFormat(format, Locale.UK).parse(date).getTime();
    94106  }
    95107
     
    149161    }
    150162
    151     result = 360 * ((result + 180) / 360 - Math.floor((result + 180) / 360))
    152         - 180;
     163    result = 360 * ((result + 180) / 360 - Math.floor((result + 180) / 360)) - 180;
    153164    return result;
    154   }
    155 
    156   /**
    157    * Parses a string with a given format and returns the Epoch time.
    158    *
    159    * @param date
    160    *          The string containing the date.
    161    * @param format
    162    *          The format of the date.
    163    * @return The date in Epoch format.
    164    * @throws ParseException
    165    */
    166   public static long getEpoch(String date, String format) throws ParseException {
    167     SimpleDateFormat formatter = new SimpleDateFormat(format, Locale.UK);
    168     Date dateTime = formatter.parse(date);
    169     return dateTime.getTime();
    170165  }
    171166
Note: See TracChangeset for help on using the changeset viewer.