4
4
import java .time .LocalDateTime ;
5
5
import java .time .ZoneOffset ;
6
6
import java .time .format .DateTimeFormatter ;
7
+ import java .time .format .DateTimeParseException ;
7
8
import java .util .*;
8
9
9
10
import javax .enterprise .context .ApplicationScoped ;
@@ -164,12 +165,22 @@ private String migrateEngagement(Engagement engagement) {
164
165
try {
165
166
use .setCreated (convertDateTime (use .getCreated ()));
166
167
use .setUpdated (convertDateTime (use .getUpdated ()));
167
- } catch (Exception ex ) {
168
+ } catch (RuntimeException ex ) {
168
169
LOGGER .error ("dtf exception {}" , use .getCreated (), ex );
169
170
}
170
171
}));
171
172
}
172
173
174
+ if (copy .getLaunch () != null ) {
175
+ try {
176
+ Instant .parse (copy .getLaunch ().getLaunchedDateTime ());
177
+ } catch (DateTimeParseException ex ) {
178
+ LOGGER .error ("No standard launch date {}" , copy .getLaunch ().getLaunchedDateTime ());
179
+ copy .getLaunch ().setLaunchedDateTime (convertDateTime (copy .getLaunch ().getLaunchedDateTime ()));
180
+ }
181
+ }
182
+
183
+
173
184
copy .setHostingEnvironments (null );
174
185
copy .setEngagementUsers (null );
175
186
copy .setCommits (null );
@@ -183,8 +194,31 @@ private <T> T clone(T toClone, Class<T> clazz) {
183
194
}
184
195
185
196
private String convertDateTime (String oldDateTime ) {
197
+ String [] patterns = {"yyyy-MM-dd'T'HH:mm:ss.SSSSSS" , "yyyy-MM-dd'T'HH:mm:ss.SSS" };
198
+
199
+ String date = null ;
200
+
201
+ for (int i =0 ; i <patterns .length ; i ++) {
202
+ try {
203
+ date = convertDateTime (oldDateTime , patterns [i ]);
204
+ break ;
205
+ } catch (DateTimeParseException ex ) {
206
+ LOGGER .error ("No standard date {}, pattern {}" , oldDateTime , patterns [i ]);
207
+ }
208
+ }
209
+
210
+ if (date == null ) {
211
+ throw new RuntimeException ("Unable to parse date " + oldDateTime );
212
+ }
213
+
214
+ LOGGER .trace ("date converted={}" , date );
215
+ return date ;
216
+ }
217
+
218
+ private String convertDateTime (String oldDateTime , String pattern ) {
186
219
LOGGER .trace ("Date In {}" , oldDateTime );
187
- DateTimeFormatter formatter = DateTimeFormatter .ofPattern ("yyyy-MM-dd'T'HH:mm:ss.SSSSSS" );
220
+
221
+ DateTimeFormatter formatter = DateTimeFormatter .ofPattern (pattern );
188
222
LocalDateTime expected = LocalDateTime .parse (oldDateTime , formatter );
189
223
Instant instant = expected .toInstant (ZoneOffset .UTC );
190
224
LOGGER .trace ("Date Out {}" , instant );
0 commit comments