Changeset 11035 in josm for trunk/src/org/openstreetmap/josm/gui
- Timestamp:
- 2016-09-20T22:46:47+02:00 (8 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/dialogs/changeset/query/AdvancedChangesetQueryPanel.java
r10626 r11035 11 11 import java.awt.event.ItemEvent; 12 12 import java.awt.event.ItemListener; 13 import java.text.DateFormat; 14 import java.text.ParseException; 13 import java.time.LocalDate; 14 import java.time.LocalTime; 15 import java.time.ZoneId; 16 import java.time.ZonedDateTime; 17 import java.time.format.DateTimeFormatter; 18 import java.time.format.DateTimeParseException; 19 import java.time.format.FormatStyle; 15 20 import java.util.Date; 16 import java.util.GregorianCalendar;17 import java.util.Locale;18 21 19 22 import javax.swing.BorderFactory; … … 842 845 throw new IllegalStateException(tr("Cannot build changeset query with time based restrictions. Input is not valid.")); 843 846 if (rbClosedAfter.isSelected()) { 844 GregorianCalendar cal = new GregorianCalendar(); 845 Date d1 = valClosedAfterDate1.getDate(); 846 Date d2 = valClosedAfterTime1.getDate(); 847 cal.setTimeInMillis(d1.getTime() + (d2 == null ? 0 : d2.getTime())); 848 query.closedAfter(cal.getTime()); 847 LocalDate d1 = valClosedAfterDate1.getDate(); 848 LocalTime d2 = valClosedAfterTime1.getDate(); 849 final Date d3 = new Date(d1.atTime(d2).atZone(ZoneId.systemDefault()).toInstant().toEpochMilli()); 850 query.closedAfter(d3); 849 851 } else if (rbClosedAfterAndCreatedBefore.isSelected()) { 850 GregorianCalendar cal = new GregorianCalendar(); 851 Date d1 = valClosedAfterDate2.getDate(); 852 Date d2 = valClosedAfterTime2.getDate(); 853 cal.setTimeInMillis(d1.getTime() + (d2 == null ? 0 : d2.getTime())); 854 Date d3 = cal.getTime(); 852 LocalDate d1 = valClosedAfterDate2.getDate(); 853 LocalTime d2 = valClosedAfterTime2.getDate(); 854 Date d3 = new Date(d1.atTime(d2).atZone(ZoneId.systemDefault()).toInstant().toEpochMilli()); 855 855 856 856 d1 = valCreatedBeforeDate.getDate(); 857 857 d2 = valCreatedBeforeTime.getDate(); 858 cal.setTimeInMillis(d1.getTime() + (d2 == null ? 0 : d2.getTime())); 859 Date d4 = cal.getTime(); 858 Date d4 = new Date(d1.atTime(d2).atZone(ZoneId.systemDefault()).toInstant().toEpochMilli()); 860 859 861 860 query.closedAfterAndCreatedBefore(d3, d4); … … 1042 1041 1043 1042 public String getStandardTooltipText() { 1044 Date date = new Date();1043 final ZonedDateTime now = ZonedDateTime.now(); 1045 1044 return tr( 1046 1045 "Please enter a date in the usual format for your locale.<br>" … … 1049 1048 + "Example: {2}<br>" 1050 1049 + "Example: {3}<br>", 1051 Date Format.getDateInstance(DateFormat.SHORT, Locale.getDefault()).format(date),1052 Date Format.getDateInstance(DateFormat.MEDIUM, Locale.getDefault()).format(date),1053 Date Format.getDateInstance(DateFormat.LONG, Locale.getDefault()).format(date),1054 Date Format.getDateInstance(DateFormat.FULL, Locale.getDefault()).format(date)1050 DateTimeFormatter.ofLocalizedDate(FormatStyle.SHORT).format(now), 1051 DateTimeFormatter.ofLocalizedDate(FormatStyle.MEDIUM).format(now), 1052 DateTimeFormatter.ofLocalizedDate(FormatStyle.LONG).format(now), 1053 DateTimeFormatter.ofLocalizedDate(FormatStyle.FULL).format(now) 1055 1054 ); 1056 1055 } … … 1068 1067 } 1069 1068 1070 public Date getDate() {1071 for ( int format: new int[] {DateFormat.SHORT, DateFormat.MEDIUM, DateFormat.LONG, DateFormat.FULL}) {1072 Date Format df = DateFormat.getDateInstance(format);1069 public LocalDate getDate() { 1070 for (final FormatStyle format: FormatStyle.values()) { 1071 DateTimeFormatter df = DateTimeFormatter.ofLocalizedDate(format); 1073 1072 try { 1074 return df.parse(getComponent().getText());1075 } catch ( ParseException e) {1073 return LocalDate.parse(getComponent().getText(), df); 1074 } catch (DateTimeParseException e) { 1076 1075 // Try next format 1077 1076 Main.trace(e); … … 1109 1108 1110 1109 public String getStandardTooltipText() { 1111 Date date = new Date();1110 final ZonedDateTime now = ZonedDateTime.now(); 1112 1111 return tr( 1113 1112 "Please enter a valid time in the usual format for your locale.<br>" … … 1116 1115 + "Example: {2}<br>" 1117 1116 + "Example: {3}<br>", 1118 Date Format.getTimeInstance(DateFormat.SHORT, Locale.getDefault()).format(date),1119 Date Format.getTimeInstance(DateFormat.MEDIUM, Locale.getDefault()).format(date),1120 Date Format.getTimeInstance(DateFormat.LONG, Locale.getDefault()).format(date),1121 Date Format.getTimeInstance(DateFormat.FULL, Locale.getDefault()).format(date)1117 DateTimeFormatter.ofLocalizedTime(FormatStyle.SHORT).format(now), 1118 DateTimeFormatter.ofLocalizedTime(FormatStyle.MEDIUM).format(now), 1119 DateTimeFormatter.ofLocalizedTime(FormatStyle.LONG).format(now), 1120 DateTimeFormatter.ofLocalizedTime(FormatStyle.FULL).format(now) 1122 1121 ); 1123 1122 } … … 1135 1134 } 1136 1135 1137 public Date getDate() {1136 public LocalTime getDate() { 1138 1137 if (getComponent().getText().trim().isEmpty()) 1139 return null; 1140 1141 for (int style : new int[]{DateFormat.SHORT, DateFormat.MEDIUM, DateFormat.LONG, DateFormat.FULL}) { 1138 return LocalTime.MIDNIGHT; 1139 1140 for (final FormatStyle format: FormatStyle.values()) { 1141 DateTimeFormatter df = DateTimeFormatter.ofLocalizedTime(format); 1142 1142 try { 1143 return DateFormat.getTimeInstance(style, Locale.getDefault()).parse(getComponent().getText()); 1144 } catch (ParseException e) { 1145 continue; 1143 return LocalTime.parse(getComponent().getText(), df); 1144 } catch (DateTimeParseException e) { 1145 // Try next format 1146 Main.trace(e); 1146 1147 } 1147 1148 } 1148 return null;1149 return LocalTime.MIDNIGHT; 1149 1150 } 1150 1151 } -
trunk/src/org/openstreetmap/josm/gui/layer/gpx/DateFilterPanel.java
r10611 r11035 7 7 import java.awt.GridBagLayout; 8 8 import java.awt.event.ActionListener; 9 import java.time.ZoneId; 10 import java.time.ZonedDateTime; 9 11 import java.util.Date; 10 import java.util.GregorianCalendar;11 12 12 13 import javax.swing.JCheckBox; … … 49 50 final Date startTime, endTime; 50 51 Date[] bounds = layer.data.getMinMaxTimeForAllTracks(); 51 startTime = (bounds.length == 0) ? new GregorianCalendar(2000, 1, 1).getTime() : bounds[0];52 startTime = (bounds.length == 0) ? Date.from(ZonedDateTime.of(2000, 1, 1, 0, 0, 0, 0, ZoneId.systemDefault()).toInstant()) : bounds[0]; 52 53 endTime = (bounds.length == 0) ? new Date() : bounds[1]; 53 54
Note:
See TracChangeset
for help on using the changeset viewer.