@@ -558,13 +558,6 @@ class NDB_BVL_Instrument_LINST extends \NDB_BVL_Instrument
558558 $ this ->LinstQuestions [$ pieces [1 ]] = array ('type ' => 'textarea ' );
559559 break ;
560560 case 'date ' :
561- if (strpos ($ pieces [1 ], "_date " ) !== false ) {
562- $ pieces [1 ] = substr (
563- $ pieces [1 ],
564- 0 ,
565- strpos ($ pieces [1 ], "_date " )
566- );
567- }
568561 if ($ addElements ) {
569562 if ($ pieces [3 ] == 1900 && $ pieces [4 ] == 2100 ) {
570563 $ dateOptions = null ;
@@ -582,42 +575,47 @@ class NDB_BVL_Instrument_LINST extends \NDB_BVL_Instrument
582575 // Set date format
583576 $ dateFormat = isset ($ pieces [5 ]) ? trim ($ pieces [5 ]) : "" ;
584577
585- if (isset ($ dateFormat ) && $ dateFormat != "" ) {
586- if ($ dateFormat === 'MonthYear ' ) {
587- // Shows date without day of month
588- $ this ->addMonthYear (
589- $ pieces [1 ],
590- $ pieces [2 ],
591- $ dateOptions
592- );
593- }
594- if ($ dateFormat === 'BasicDate ' ) {
595- // Shows date without not answered dropdown
596- $ this ->addBasicDate (
597- $ pieces [1 ],
598- $ pieces [2 ],
599- $ dateOptions
600- );
601- }
602- if ($ dateFormat === 'Date ' ) {
603- // Shows standard date
604- $ this ->addDateElement (
578+ if ($ dateFormat === 'MonthYear ' ) {
579+ // Shows date without day of month
580+ $ this ->addMonthYear (
581+ $ pieces [1 ],
582+ $ pieces [2 ],
583+ $ dateOptions
584+ );
585+ } elseif ($ dateFormat === 'BasicDate ' ) {
586+ // Shows date without not answered dropdown
587+ $ this ->addBasicDate (
588+ $ pieces [1 ],
589+ $ pieces [2 ],
590+ $ dateOptions
591+ );
592+ } elseif ($ dateFormat === 'Date ' || $ dateFormat === "" ) {
593+ // The dateformat for a standard date should be
594+ // explicitly set to `Date` but for backwards
595+ // compatibility we support a null/empty dateformat and
596+ // default to standard date
597+
598+ // Check that the field name ENDS with `_date` as it
599+ // should for standard dates. Then strip the `_date` so
600+ // it is not duplicated by the addDateElement function
601+ if (substr ($ pieces [1 ], -5 ) === "_date " ) {
602+ $ pieces [1 ] = substr (
605603 $ pieces [1 ],
606- $ pieces [ 2 ] ,
607- $ dateOptions
604+ 0 ,
605+ - 5
608606 );
609607 }
610- } else {
611- // it will only enter here if the date format is not
612- // explicitly set. This offers backwards compatibility
613- // for date elements created before the date formats were
614- // explicitly specified. An empty date format will be
615- // handled as a `Date` element
608+ // Shows standard date
616609 $ this ->addDateElement (
617610 $ pieces [1 ],
618611 $ pieces [2 ],
619612 $ dateOptions
620613 );
614+ } else {
615+ throw new \LorisException (
616+ "Unsupported dateformat ` $ dateFormat` in LINST " .
617+ " file ` $ filename` for date element ` $ pieces [1 ]`. "
618+ );
621619 }
622620 }
623621 if ($ firstFieldOfPage ) {
0 commit comments