Ticket #17576: 17576-timezones.diff
| File 17576-timezones.diff, 9.2 KB (added by , 7 years ago) |
|---|
-
src/org/openstreetmap/josm/gui/layer/geoimage/CorrelateGpxWithImages.java
36 36 import java.util.Hashtable; 37 37 import java.util.List; 38 38 import java.util.Objects; 39 import java.util.Optional;40 39 import java.util.TimeZone; 41 40 import java.util.concurrent.TimeUnit; 42 41 … … 540 539 * 541 540 */ 542 541 private class SetOffsetActionListener implements ActionListener { 542 JCheckBox ckDst; 543 543 544 class TimeZoneItem implements Comparable<TimeZoneItem> { 545 private TimeZone tz; 546 private String rawString; 547 private String dstString; 548 549 public TimeZoneItem(TimeZone tz) { 550 this.tz = tz; 551 } 552 553 public String getFormattedString() { 554 if (ckDst.isSelected()) { 555 return getDstString(); 556 } else { 557 return getRawString(); 558 } 559 } 560 561 public String getDstString() { 562 if (dstString == null) { 563 dstString = formatTimezone(tz.getRawOffset() + tz.getDSTSavings()); 564 } 565 return dstString; 566 } 567 568 public String getRawString() { 569 if (rawString == null) { 570 rawString = formatTimezone(tz.getRawOffset()); 571 } 572 return rawString; 573 } 574 575 public String getID() { 576 return tz.getID(); 577 } 578 579 @Override 580 public String toString() { 581 return getID() + " (" + getFormattedString() + ")"; 582 } 583 584 @Override 585 public int compareTo(TimeZoneItem o) { 586 return getID().compareTo(o.getID()); 587 } 588 589 private String formatTimezone(int offset) { 590 return new GpxTimezone((double) offset / TimeUnit.HOURS.toMillis(1)).formatTimezone(); 591 } 592 } 593 544 594 @Override 545 595 public void actionPerformed(ActionEvent arg0) { 546 596 SimpleDateFormat dateFormat = (SimpleDateFormat) DateUtils.getDateTimeFormat(DateFormat.SHORT, DateFormat.MEDIUM); … … 598 648 gc.weightx = gc.weighty = 0.0; 599 649 gc.fill = GridBagConstraints.NONE; 600 650 gc.anchor = GridBagConstraints.WEST; 601 panelTf.add(new JLabel(tr(" I amin the timezone of: ")), gc);651 panelTf.add(new JLabel(tr("Photo taken in the timezone of: ")), gc); 602 652 653 ckDst = new JCheckBox(tr("Use daylight saving time (where applicable)"), Config.getPref().getBoolean("geoimage.timezoneid.dst")); 654 603 655 String[] tmp = TimeZone.getAvailableIDs(); 604 List< String> vtTimezones = new ArrayList<>(tmp.length);656 List<TimeZoneItem> vtTimezones = new ArrayList<>(tmp.length); 605 657 658 String defTzStr = Config.getPref().get("geoimage.timezoneid", ""); 659 if (defTzStr.isEmpty()) { 660 defTzStr = TimeZone.getDefault().getID(); 661 } 662 TimeZoneItem defTzItem = null; 663 606 664 for (String tzStr : tmp) { 607 TimeZone tz = TimeZone.getTimeZone(tzStr); 608 609 String tzDesc = tzStr + " (" + 610 new GpxTimezone(((double) tz.getRawOffset()) / TimeUnit.HOURS.toMillis(1)).formatTimezone() + 611 ')'; 612 vtTimezones.add(tzDesc); 665 TimeZoneItem tz = new TimeZoneItem(TimeZone.getTimeZone(tzStr)); 666 vtTimezones.add(tz); 667 if (defTzStr.equals(tzStr)) { 668 defTzItem = tz; 669 } 613 670 } 614 671 615 672 Collections.sort(vtTimezones); 616 673 617 JosmComboBox< String> cbTimezones = new JosmComboBox<>(vtTimezones.toArray(new String[0]));674 JosmComboBox<TimeZoneItem> cbTimezones = new JosmComboBox<>(vtTimezones.toArray(new TimeZoneItem[0])); 618 675 619 String tzId = Config.getPref().get("geoimage.timezoneid", ""); 620 TimeZone defaultTz; 621 if (tzId.isEmpty()) { 622 defaultTz = TimeZone.getDefault(); 623 } else { 624 defaultTz = TimeZone.getTimeZone(tzId); 676 if (defTzItem != null) { 677 cbTimezones.setSelectedItem(defTzItem); 625 678 } 626 679 627 cbTimezones.setSelectedItem(defaultTz.getID() + " (" +628 new GpxTimezone(((double) defaultTz.getRawOffset()) / TimeUnit.HOURS.toMillis(1)).formatTimezone() +629 ')');630 631 680 gc.gridx = 1; 632 681 gc.weightx = 1.0; 633 682 gc.gridwidth = 2; … … 634 683 gc.fill = GridBagConstraints.HORIZONTAL; 635 684 panelTf.add(cbTimezones, gc); 636 685 686 gc.gridy = 3; 687 panelTf.add(ckDst, gc); 688 689 ckDst.addActionListener(l -> { 690 cbTimezones.repaint(); 691 }); 692 637 693 panel.add(panelTf, BorderLayout.SOUTH); 638 694 639 695 JPanel panelLst = new JPanel(new BorderLayout()); … … 710 766 711 767 try { 712 768 delta = dateFormat.parse(lbExifTime.getText()).getTime() 713 - dateFormat.parse(tfGpsTime.getText()).getTime();769 - dateFormat.parse(tfGpsTime.getText()).getTime(); 714 770 } catch (ParseException e) { 715 771 JOptionPane.showMessageDialog(MainApplication.getMainFrame(), tr("Error while parsing the date.\n" 716 772 + "Please use the requested format"), … … 718 774 continue; 719 775 } 720 776 721 String selectedTz = (String) cbTimezones.getSelectedItem(); 722 int pos = selectedTz.lastIndexOf('('); 723 tzId = selectedTz.substring(0, pos - 1); 724 String tzValue = selectedTz.substring(pos + 1, selectedTz.length() - 1); 777 TimeZoneItem selectedTz = (TimeZoneItem) cbTimezones.getSelectedItem(); 725 778 726 Config.getPref().put("geoimage.timezoneid", tzId); 779 Config.getPref().put("geoimage.timezoneid", selectedTz.getID()); 780 Config.getPref().putBoolean("geoimage.timezoneid.dst", ckDst.isSelected()); 727 781 tfOffset.setText(GpxTimeOffset.milliseconds(delta).formatOffset()); 728 tfTimezone.setText( tzValue);782 tfTimezone.setText(selectedTz.getFormattedString()); 729 783 730 784 isOk = true; 731 785 … … 817 871 JPanel panelTf = new JPanel(new GridBagLayout()); 818 872 819 873 try { 820 timezone = GpxTimezone.parseTimezone(Optional.ofNullable(Config.getPref().get("geoimage.timezone", "0:00")).orElse("0:00")); 874 String tz = Config.getPref().get("geoimage.timezone"); 875 if (!tz.isEmpty()) { 876 timezone = GpxTimezone.parseTimezone(tz); 877 } else { 878 timezone = new GpxTimezone(TimeUnit.MILLISECONDS.toMinutes(TimeZone.getDefault().getRawOffset()) / 60.); //hours is double 879 } 821 880 } catch (ParseException e) { 822 881 timezone = GpxTimezone.ZERO; 823 882 Logging.trace(e); … … 1054 1113 if (selGpx == null) 1055 1114 return tr("No gpx selected"); 1056 1115 1057 final long offsetMs = ((long) (timezone.getHours() * TimeUnit.HOURS.toMillis( -1))) + delta.getMilliseconds(); // in milliseconds1116 final long offsetMs = ((long) (timezone.getHours() * TimeUnit.HOURS.toMillis(1))) + delta.getMilliseconds(); // in milliseconds 1058 1117 lastNumMatched = GpxImageCorrelation.matchGpxTrack(dateImgLst, selGpx.data, offsetMs, forceTags); 1059 1118 1060 1119 return trn("<html>Matched <b>{0}</b> of <b>{1}</b> photo to GPX track.</html>", -
src/org/openstreetmap/josm/tools/date/DateUtils.java
6 6 import java.text.SimpleDateFormat; 7 7 import java.time.DateTimeException; 8 8 import java.time.Instant; 9 import java.time.ZoneId;10 9 import java.time.ZoneOffset; 11 10 import java.time.ZonedDateTime; 12 11 import java.time.format.DateTimeFormatter; … … 100 99 parsePart2(str, 14), 101 100 parsePart2(str, 17), 102 101 0, 103 // consider EXIF date in default timezone 104 checkLayout(str, "xxxx:xx:xx xx:xx:xx") ? ZoneId.systemDefault() : ZoneOffset.UTC 102 ZoneOffset.UTC 105 103 ); 106 104 if (str.length() == 22 || str.length() == 25) { 107 105 final int plusHr = parsePart2(str, 20); … … 122 120 parsePart2(str, 14), 123 121 parsePart2(str, 17), 124 122 parsePart3(str, 20) * 1_000_000, 125 // consider EXIF date in default timezone 126 checkLayout(str, "xxxx:xx:xx xx:xx:xx.xxx") ? ZoneId.systemDefault() : ZoneOffset.UTC 123 ZoneOffset.UTC 127 124 ); 128 125 if (str.length() == 29) { 129 126 final int plusHr = parsePart2(str, 24);
