Working on dateTime with precision NIHVIVO-295
This commit is contained in:
parent
e418533759
commit
c4774272eb
2 changed files with 41 additions and 1 deletions
|
@ -153,6 +153,11 @@ public class DateTimeWithPrecision extends BaseEditElement {
|
|||
|
||||
protected Literal getDateTime( Map<String, String[]> queryParameters ) {
|
||||
Integer year = parseToInt(fieldName+".year", queryParameters);
|
||||
|
||||
//this is the case where date has not been filled out at all.
|
||||
if( year == null )
|
||||
return null;
|
||||
|
||||
Integer month = parseToInt(fieldName+".month", queryParameters);
|
||||
if( month == null || month == 0 )
|
||||
month = 1;
|
||||
|
@ -232,6 +237,10 @@ public class DateTimeWithPrecision extends BaseEditElement {
|
|||
}
|
||||
}
|
||||
|
||||
/* the field wasn't filled out at all */
|
||||
if( indexOfFirstNull == 0 )
|
||||
return VitroVocabulary.Precision.NONE.uri();
|
||||
|
||||
/* if they all had values then we have seconds precision */
|
||||
if( indexOfFirstNull == -1 )
|
||||
return VitroVocabulary.Precision.SECOND.uri();
|
||||
|
|
|
@ -182,6 +182,37 @@ public class DateTimeWithPrecisionTest {
|
|||
Assert.assertEquals(VitroVocabulary.Precision.YEAR.uri(), precisionURI);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void precisionNoValueTest() throws Exception{
|
||||
String FIELDNAME = "testfield";
|
||||
Field field = new Field();
|
||||
field.setName(FIELDNAME);
|
||||
DateTimeWithPrecision dtwp = new DateTimeWithPrecision(field);
|
||||
|
||||
Map<String,String[]> queryParameters = new HashMap<String, String[]>();
|
||||
//field is not filled out at all
|
||||
//no year
|
||||
//no months
|
||||
//no days
|
||||
//no hours
|
||||
//no minutes
|
||||
//no seconds
|
||||
|
||||
EditConfiguration editConfig=null;
|
||||
Map<String,String> validationMsgs = dtwp.getValidationMessages("testfield", editConfig, queryParameters);
|
||||
Assert.assertNotNull(validationMsgs);
|
||||
Assert.assertTrue(validationMsgs.size() == 0 );
|
||||
|
||||
String precisionURI = null;
|
||||
precisionURI = dtwp.getSubmittedPrecision( queryParameters );
|
||||
|
||||
Assert.assertNotNull(precisionURI);
|
||||
Assert.assertEquals(VitroVocabulary.Precision.NONE.uri(), precisionURI);
|
||||
|
||||
Literal date = dtwp.getDateTime( queryParameters);
|
||||
Assert.assertNull(date);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getDateLiteralTest(){
|
||||
String FIELDNAME = "testfield";
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue