Ignore:
Timestamp:
2016-11-20T17:33:33+01:00 (7 years ago)
Author:
simon04
Message:

see #13376 - Use TimeUnit instead of combinations of 1000/60/60/24

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/layer/geoimage/CorrelateGpxWithImages.java

    r11017 r11288  
    3838import java.util.Objects;
    3939import java.util.TimeZone;
     40import java.util.concurrent.TimeUnit;
    4041import java.util.zip.GZIPInputStream;
    4142
     
    408409                TimeZone tz = TimeZone.getTimeZone(tzStr);
    409410
    410                 String tzDesc = new StringBuilder(tzStr).append(" (")
    411                 .append(new Timezone(tz.getRawOffset() / 3600000.0).formatTimezone())
    412                 .append(')').toString();
     411                String tzDesc = tzStr + " (" +
     412                        new Timezone(((double) tz.getRawOffset()) / TimeUnit.HOURS.toMillis(1)).formatTimezone() +
     413                        ')';
    413414                vtTimezones.add(tzDesc);
    414415            }
     
    426427            }
    427428
    428             cbTimezones.setSelectedItem(new StringBuilder(defaultTz.getID()).append(" (")
    429                     .append(new Timezone(defaultTz.getRawOffset() / 3600000.0).formatTimezone())
    430                     .append(')').toString());
     429            cbTimezones.setSelectedItem(defaultTz.getID() + " (" +
     430                    new Timezone(((double) defaultTz.getRawOffset()) / TimeUnit.HOURS.toMillis(1)).formatTimezone() +
     431                    ')');
    431432
    432433            gc.gridx = 1;
     
    815816                return tr("No gpx selected");
    816817
    817             final long offsetMs = ((long) (timezone.getHours() * 3600 * 1000)) + delta.getMilliseconds(); // in milliseconds
     818            final long offsetMs = ((long) (timezone.getHours() * TimeUnit.HOURS.toMillis(1))) + delta.getMilliseconds(); // in milliseconds
    818819            lastNumMatched = matchGpxTrack(dateImgLst, selGpx.data, offsetMs);
    819820
     
    846847
    847848            final Offset offset = Offset.milliseconds(
    848                     delta.getMilliseconds() + Math.round(timezone.getHours() * 60 * 60 * 1000));
     849                    delta.getMilliseconds() + Math.round(timezone.getHours() * TimeUnit.HOURS.toMillis(1)));
    849850            final int dayOffset = offset.getDayOffset();
    850851            final Pair<Timezone, Offset> timezoneOffsetPair = offset.withoutDayOffset().splitOutTimezone();
     
    897898
    898899                    delta = Offset.milliseconds(100L * sldSeconds.getValue()
    899                             + 1000L * 60 * sldMinutes.getValue()
    900                             + 1000L * 60 * 60 * 24 * dayOffset);
     900                            + TimeUnit.MINUTES.toMillis(sldMinutes.getValue())
     901                            + TimeUnit.DAYS.toMillis(dayOffset));
    901902
    902903                    tfTimezone.getDocument().removeDocumentListener(statusBarUpdater);
     
    11461147        // Time between the track point and the previous one, 5 sec if first point, i.e. photos take
    11471148        // 5 sec before the first track point can be assumed to be take at the starting position
    1148         long interval = prevWpTime > 0 ? Math.abs(curWpTime - prevWpTime) : 5*1000;
     1149        long interval = prevWpTime > 0 ? Math.abs(curWpTime - prevWpTime) : TimeUnit.SECONDS.toMillis(5);
    11491150        int ret = 0;
    11501151
     
    14321433
    14331434        int getDayOffset() {
    1434             final double diffInH = getMilliseconds() / 1000. / 60 / 60; // hours
    1435 
    14361435            // Find day difference
    1437             return (int) Math.round(diffInH / 24);
     1436            return (int) Math.round(((double) getMilliseconds()) / TimeUnit.DAYS.toMillis(1));
    14381437        }
    14391438
    14401439        Offset withoutDayOffset() {
    1441             return milliseconds(getMilliseconds() - getDayOffset() * 24L * 60L * 60L * 1000L);
     1440            return milliseconds(getMilliseconds() - TimeUnit.DAYS.toMillis(getDayOffset()));
    14421441        }
    14431442
    14441443        Pair<Timezone, Offset> splitOutTimezone() {
    14451444            // In hours
    1446             double tz = withoutDayOffset().getSeconds() / 3600.0;
     1445            final double tz = ((double) withoutDayOffset().getSeconds()) / TimeUnit.HOURS.toSeconds(1);
    14471446
    14481447            // Due to imprecise clocks we might get a "+3:28" timezone, which should obviously be 3:30 with
    14491448            // -2 minutes offset. This determines the real timezone and finds offset.
    14501449            final double timezone = (double) Math.round(tz * 2) / 2; // hours, rounded to one decimal place
    1451             final long delta = Math.round(getMilliseconds() - timezone * 60 * 60 * 1000); // milliseconds
     1450            final long delta = Math.round(getMilliseconds() - timezone * TimeUnit.HOURS.toMillis(1));
    14521451            return Pair.create(new Timezone(timezone), Offset.milliseconds(delta));
    14531452        }
Note: See TracChangeset for help on using the changeset viewer.