Fixing bug in DateTimeWithPrecision that caused it to not accept days greater than 28. NIHVIVO-2016
This commit is contained in:
parent
616c74254c
commit
d6adc88ef8
2 changed files with 74 additions and 6 deletions
|
@ -499,29 +499,32 @@ public class DateTimeWithPrecision extends BaseEditElement {
|
||||||
if( second == null )
|
if( second == null )
|
||||||
second = 0;
|
second = 0;
|
||||||
|
|
||||||
DateTime dateTime = new DateTime();
|
//initialize to something so that we can be assured not to get
|
||||||
|
//system date dependent behavior
|
||||||
|
DateTime dateTime = new DateTime("1970-01-01T00:00:00Z");
|
||||||
|
|
||||||
try{
|
try{
|
||||||
dateTime.withYear(year);
|
dateTime = dateTime.withYear(year);
|
||||||
}catch(IllegalArgumentException iae){
|
}catch(IllegalArgumentException iae){
|
||||||
errors.put(fieldName+".year", iae.getLocalizedMessage());
|
errors.put(fieldName+".year", iae.getLocalizedMessage());
|
||||||
}
|
}
|
||||||
try{
|
try{
|
||||||
dateTime.withMonthOfYear(month);
|
dateTime = dateTime.withMonthOfYear(month);
|
||||||
}catch(IllegalArgumentException iae){
|
}catch(IllegalArgumentException iae){
|
||||||
errors.put(fieldName+".month", iae.getLocalizedMessage());
|
errors.put(fieldName+".month", iae.getLocalizedMessage());
|
||||||
}
|
}
|
||||||
try{
|
try{
|
||||||
dateTime.withDayOfMonth(day);
|
dateTime = dateTime.withDayOfMonth(day);
|
||||||
}catch(IllegalArgumentException iae){
|
}catch(IllegalArgumentException iae){
|
||||||
errors.put(fieldName+".day", iae.getLocalizedMessage());
|
errors.put(fieldName+".day", iae.getLocalizedMessage());
|
||||||
}
|
}
|
||||||
try{
|
try{
|
||||||
dateTime.withHourOfDay(hour);
|
dateTime = dateTime.withHourOfDay(hour);
|
||||||
}catch(IllegalArgumentException iae){
|
}catch(IllegalArgumentException iae){
|
||||||
errors.put(fieldName+".hour", iae.getLocalizedMessage());
|
errors.put(fieldName+".hour", iae.getLocalizedMessage());
|
||||||
}
|
}
|
||||||
try{
|
try{
|
||||||
dateTime.withSecondOfMinute(second);
|
dateTime = dateTime.withSecondOfMinute(second);
|
||||||
}catch(IllegalArgumentException iae){
|
}catch(IllegalArgumentException iae){
|
||||||
errors.put(fieldName+".second", iae.getLocalizedMessage());
|
errors.put(fieldName+".second", iae.getLocalizedMessage());
|
||||||
}
|
}
|
||||||
|
|
|
@ -268,4 +268,69 @@ public class DateTimeWithPrecisionTest {
|
||||||
Assert.assertEquals(XSDDateTime.class, obj.getClass());
|
Assert.assertEquals(XSDDateTime.class, obj.getClass());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void day30Test() throws Exception{
|
||||||
|
String FIELDNAME = "testfield";
|
||||||
|
Field field = new Field();
|
||||||
|
field.setName(FIELDNAME);
|
||||||
|
DateTimeWithPrecision dtwp = new DateTimeWithPrecision(field);
|
||||||
|
|
||||||
|
|
||||||
|
/* Check if it works with day number under 29 */
|
||||||
|
Map<String,String[]> queryParameters = new HashMap<String, String[]>();
|
||||||
|
queryParameters.put(FIELDNAME+".year", new String[]{"1999" });
|
||||||
|
queryParameters.put(FIELDNAME+".month", new String[]{"12"});
|
||||||
|
queryParameters.put(FIELDNAME+".day", new String[]{"28"});
|
||||||
|
|
||||||
|
Map<String,String> validationMsgs = dtwp.getValidationMessages("testfield", (EditConfiguration)null, queryParameters);
|
||||||
|
Assert.assertNotNull(validationMsgs);
|
||||||
|
Assert.assertTrue(validationMsgs.size() == 0 );
|
||||||
|
|
||||||
|
String precisionURI = dtwp.getSubmittedPrecision( queryParameters);
|
||||||
|
Assert.assertNotNull(precisionURI);
|
||||||
|
Assert.assertEquals(VitroVocabulary.Precision.DAY.uri(), precisionURI);
|
||||||
|
|
||||||
|
/* Check for days greater than 28 */
|
||||||
|
queryParameters = new HashMap<String, String[]>();
|
||||||
|
queryParameters.put(FIELDNAME+".year", new String[]{"1999" });
|
||||||
|
queryParameters.put(FIELDNAME+".month", new String[]{"12"});
|
||||||
|
queryParameters.put(FIELDNAME+".day", new String[]{"30"});
|
||||||
|
|
||||||
|
validationMsgs = dtwp.getValidationMessages("testfield", (EditConfiguration)null, queryParameters);
|
||||||
|
Assert.assertNotNull(validationMsgs);
|
||||||
|
Assert.assertTrue(validationMsgs.size() == 0 );
|
||||||
|
|
||||||
|
precisionURI = dtwp.getSubmittedPrecision( queryParameters);
|
||||||
|
Assert.assertNotNull(precisionURI);
|
||||||
|
Assert.assertEquals(VitroVocabulary.Precision.DAY.uri(), precisionURI);
|
||||||
|
|
||||||
|
/* Check for leap year */
|
||||||
|
queryParameters = new HashMap<String, String[]>();
|
||||||
|
queryParameters.put(FIELDNAME+".year", new String[]{"2000" });
|
||||||
|
queryParameters.put(FIELDNAME+".month", new String[]{"2"});
|
||||||
|
queryParameters.put(FIELDNAME+".day", new String[]{"29"});
|
||||||
|
|
||||||
|
validationMsgs = dtwp.getValidationMessages("testfield", (EditConfiguration)null, queryParameters);
|
||||||
|
Assert.assertNotNull(validationMsgs);
|
||||||
|
Assert.assertTrue(validationMsgs.size() == 0 );
|
||||||
|
|
||||||
|
precisionURI = dtwp.getSubmittedPrecision( queryParameters);
|
||||||
|
Assert.assertNotNull(precisionURI);
|
||||||
|
Assert.assertEquals(VitroVocabulary.Precision.DAY.uri(), precisionURI);
|
||||||
|
|
||||||
|
/* check for non leap year */
|
||||||
|
queryParameters = new HashMap<String, String[]>();
|
||||||
|
queryParameters.put(FIELDNAME+".year", new String[]{"1999" });
|
||||||
|
queryParameters.put(FIELDNAME+".month", new String[]{"2"});
|
||||||
|
queryParameters.put(FIELDNAME+".day", new String[]{"29"});
|
||||||
|
|
||||||
|
validationMsgs = dtwp.getValidationMessages("testfield", (EditConfiguration)null, queryParameters);
|
||||||
|
Assert.assertNotNull(validationMsgs);
|
||||||
|
Assert.assertTrue(validationMsgs.size() > 0 );
|
||||||
|
|
||||||
|
precisionURI = dtwp.getSubmittedPrecision( queryParameters);
|
||||||
|
Assert.assertNotNull(precisionURI);
|
||||||
|
Assert.assertEquals(VitroVocabulary.Precision.DAY.uri(), precisionURI);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue