|
21 | 21 | import java.util.HashMap; |
22 | 22 | import java.util.List; |
23 | 23 | import java.util.Map; |
| 24 | +import java.util.TimeZone; |
| 25 | +import java.util.Date; |
24 | 26 |
|
25 | 27 | import com.cloud.bridge.service.exception.EC2ServiceException; |
26 | | -import com.cloud.bridge.util.DateHelper; |
27 | 28 | import com.cloud.bridge.util.EC2RestAuth; |
28 | 29 |
|
29 | 30 |
|
@@ -123,8 +124,14 @@ else if (filterName.equalsIgnoreCase( "status" )) |
123 | 124 | return containsString(vol.getState(), valueSet ); |
124 | 125 | else if (filterName.equalsIgnoreCase( "volume-id" )) |
125 | 126 | return containsString(vol.getId().toString(), valueSet ); |
126 | | - else if (filterName.equalsIgnoreCase( "attachment.attach-time" )) |
127 | | - return containsTime(vol.getAttached(), valueSet ); |
| 127 | + else if (filterName.equalsIgnoreCase( "attachment.attach-time" )) { |
| 128 | + if (vol.getAttached() != null) |
| 129 | + return containsTime(vol.getAttached(), valueSet ); |
| 130 | + else if (vol.getInstanceId() != null) |
| 131 | + return containsTime(vol.getCreated(), valueSet); |
| 132 | + else |
| 133 | + return false; |
| 134 | + } |
128 | 135 | else if (filterName.equalsIgnoreCase( "attachment.device" )) |
129 | 136 | return containsDevice(vol.getDeviceId(), valueSet ); |
130 | 137 | else if (filterName.equalsIgnoreCase( "attachment.instance-id" )) |
@@ -155,14 +162,17 @@ private boolean containsLong( long lookingFor, String[] set ) |
155 | 162 |
|
156 | 163 | private boolean containsTime(String lookingForDate, String[] set ) throws ParseException |
157 | 164 | { |
158 | | - Calendar lookingFor = EC2RestAuth.parseDateString(lookingForDate); |
159 | | - for (String s : set) { |
160 | | - Calendar toMatch = Calendar.getInstance(); |
161 | | - toMatch.setTime( DateHelper.parseISO8601DateString( s )); |
162 | | - if (0 == lookingFor.compareTo( toMatch )) return true; |
163 | | - } |
164 | | - return false; |
165 | | - } |
| 165 | + Calendar lookingFor = EC2RestAuth.parseDateString(lookingForDate); |
| 166 | + lookingFor.setTimeZone(TimeZone.getTimeZone("GMT")); |
| 167 | + Date lookForDate = lookingFor.getTime(); |
| 168 | + for (String s : set) { |
| 169 | + Calendar toMatch = EC2RestAuth.parseDateString(s); |
| 170 | + toMatch.setTimeZone(TimeZone.getTimeZone("GMT")); |
| 171 | + Date toMatchDate = toMatch.getTime(); |
| 172 | + if ( 0 == lookForDate.compareTo(toMatchDate)) return true; |
| 173 | + } |
| 174 | + return false; |
| 175 | + } |
166 | 176 |
|
167 | 177 |
|
168 | 178 | private boolean containsDevice(String deviceId, String[] set ) |
|
0 commit comments