Changeset 257 for trunk/grails-app/domain
- Timestamp:
- Mar 11, 2010, 2:23:53 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/domain/dbnp/studycapturing/TemplateEntity.groovy
r247 r257 90 90 } 91 91 else { 92 TemplateField field = this.template.fields.find { it.name == fieldName} 92 TemplateField field = this.template.fields.find { it.name == fieldName} 93 93 if (field == null) { 94 94 throw new NoSuchFieldException("Field ${fieldName} not found in class properties or template fields") … … 99 99 value = field.listEntries.find { it.name == value } 100 100 } 101 102 // handle string values for date fields 103 if (field.type == TemplateFieldType.DATE && value.class == String) { 104 // a string was given, attempt to transform it into a date instance 105 // and -for now- assume the dd/mm/yyyy format 106 def dateMatch = value =~ /^([0-9]{1,})([^0-9]{1,})([0-9]{1,})([^0-9]{1,})([0-9]{1,})((([^0-9]{1,})([0-9]{1,2}):([0-9]{1,2})){0,})/ 107 if (dateMatch.matches()) { 108 // create limited 'autosensing' datetime parser 109 // assume dd mm yyyy or dd mm yy 110 def parser = 'd' + dateMatch[0][2] + 'M' + dateMatch[0][4] + (((dateMatch[0][5] as int) > 999) ? 'yyyy' : 'yy') 111 112 // add time as well? 113 if (dateMatch[0][7] != null) { 114 parser += dateMatch[0][6] + 'HH:mm' 115 } 116 117 value = new Date().parse(parser, value) 118 } 119 } 120 101 121 // Caution: this assumes that all template...Field Maps are already initialized 102 122 // Otherwise, the results are pretty much unpredictable!
Note: See TracChangeset
for help on using the changeset viewer.