Index: samigo-app/src/java/org/sakaiproject/tool/assessment/ui/bean/delivery/SectionContentsBean.java =================================================================== --- samigo-app/src/java/org/sakaiproject/tool/assessment/ui/bean/delivery/SectionContentsBean.java (revision 314508) +++ samigo-app/src/java/org/sakaiproject/tool/assessment/ui/bean/delivery/SectionContentsBean.java (working copy) @@ -432,23 +432,49 @@ String randomDrawDate = section.getSectionMetaDataByLabel(SectionDataIfc.QUESTIONS_RANDOM_DRAW_DATE); if(randomDrawDate != null && !"".equals(randomDrawDate)){ - - try{ - - // bjones86 - SAM-1604 - DateTime drawDate; - DateTimeFormatter fmt = ISODateTimeFormat.dateTime(); //The Date Time is in ISO format - try { - drawDate = fmt.parseDateTime(randomDrawDate); - } catch(Exception ex) { - DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZZ"); - Date date = df.parse(randomDrawDate); - if(date == null) { - throw new IllegalArgumentException(); + + DateTime drawDate = null; + DateTimeFormatter fmt = ISODateTimeFormat.dateTime(); // The Date Time is in ISO format + try + { + drawDate = fmt.parseDateTime( randomDrawDate ); } - drawDate = new DateTime(date); + catch( Exception ex ) + { + try + { + // Old code produced dates that appeard like java.util.Date.toString() in the database + // This means it's possible that the database contains dates in multiple formats + // We'll try parsing Date.toString()'s format first. + // Date.toString is locale independent. So this SimpleDateFormat using Locale.US should guarantee that this works on all machines: + DateFormat df = new SimpleDateFormat( "EEE MMM dd HH:mm:ss zzz yyyy", Locale.US ); + Date date = df.parse( randomDrawDate ); + if( date != null ) + { + drawDate = new DateTime( date ); } + } + catch( Exception ex2 ) + { + DateFormat df = new SimpleDateFormat( "yyyy-MM-dd'T'HH:mm:ss.SSSZZ" ); + try + { + Date date = df.parse( randomDrawDate ); + if( date != null ) + { + drawDate = new DateTime( date ); + } + } + catch( Exception ex3 ) + { + log.error( "Unable to parse date text: " + randomDrawDate, ex3 ); + throw new IllegalArgumentException("Unable to parse date " + randomDrawDate + " with DateFormat: " + df); + } + } + } + if( drawDate != null ) + { //We need the locale to localize the output string Locale loc = new ResourceLoader().getLocale(); String drawDateString = DateTimeFormat.fullDate().withLocale(loc).print(drawDate); @@ -455,13 +481,10 @@ String drawTimeString = DateTimeFormat.fullTime().withLocale(loc).print(drawDate); setRandomQuestionsDrawDate(drawDateString); setRandomQuestionsDrawTime(drawTimeString); - - }catch(Exception e){ - log.error("Unable to parse date text: " + randomDrawDate, e); - } } } } + } } else