Skip to content

Commit

Permalink
Fixed issue #6994: Date/time question type always records "00:00" for…
Browse files Browse the repository at this point in the history
… time
  • Loading branch information
c-schmitz committed Dec 9, 2012
1 parent bc38d20 commit 63e6761
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 21 deletions.
2 changes: 1 addition & 1 deletion application/helpers/expressions/em_manager_helper.php
Expand Up @@ -7501,7 +7501,7 @@ static function ProcessCurrentResponses()
$aAttributes=$LEM->getQuestionAttributesForEM($LEM->sid, $qid,$_SESSION['LEMlang']);
$aDateFormatData=getDateFormatDataForQID($aAttributes[$qid],$LEM->surveyOptions);
$oDateTimeConverter = new Date_Time_Converter($value, $aDateFormatData['phpdate']);
$value=$oDateTimeConverter->convert("Y-m-d");
$value=$oDateTimeConverter->convert("Y-m-d H:i");
}
break;
case 'N': //NUMERICAL QUESTION TYPE
Expand Down
2 changes: 1 addition & 1 deletion application/helpers/surveytranslator_helper.php
Expand Up @@ -635,7 +635,7 @@ function getPHPDateFromDateFormat($sDateformat)
function getJSDateFromDateFormat($sDateformat)
{
// The only difference from dateformat is that Jsdate does not support truncated years
return str_replace("yyyy", "yy", $sDateformat);
return str_replace(array('yyyy','MM','M'), array('yy','NN','NN'), $sDateformat);
}


Expand Down
46 changes: 27 additions & 19 deletions scripts/date.js
@@ -1,5 +1,5 @@
$(document).ready(function(){
// pupup calendar
// popup calendar
$(".popupdate").each(function(i,e) {
var basename = e.id.substr(6);
format=$('#dateformat'+basename).val();
Expand Down Expand Up @@ -71,23 +71,7 @@ function dateUpdater() {
}
else
{
var answer = $('#dateformat'+thisid).val();
if ($('#year'+thisid).length) answer = answer.replace(/y+/, $('#year'+thisid).val());
if ($('#month'+thisid).length) answer = answer.replace(/m+/, $('#month'+thisid).val());
if ($('#day'+thisid).length) answer = answer.replace(/d+/, $('#day'+thisid).val());
if ($('#hour'+thisid).length) answer = answer.replace(/H+/, $('#hour'+thisid).val());
if ($('#minute'+thisid).length)
{
// The minute is optional (assumed as 00)
if ($('#minute'+thisid).val()=='')
{
answer = answer.replace(/M+/, '00');
}
else
{
answer = answer.replace(/M+/, $('#minute'+thisid).val());
}
}

if ($('#year'+thisid).size()==0)
{
iYear='1900';
Expand All @@ -112,14 +96,38 @@ function dateUpdater() {
{
iDay=$('#day'+thisid).val();
}
if ($('#hour'+thisid).size()==0)
{
iHour='00';
}
else
{
iHour=$('#hour'+thisid).val();
}
if ($('#minute'+thisid).size()==0)
{
iMinute='00';
}
else
{
iMinute=$('#minute'+thisid).val();
}
ValidDate(this,iYear+'-'+iMonth+'-'+iDay);
parseddate=$.datepicker.parseDate( 'dd-mm-yy', iDay+'-'+iMonth+'-'+iYear);
$('#answer'+thisid).val($.datepicker.formatDate( $('#dateformat'+thisid).val(), parseddate));
parseddate=$.datepicker.formatDate( $('#dateformat'+thisid).val(), parseddate);
parseddate=parseddate.replace('HH',pad(iHour,2));
parseddate=parseddate.replace('H',iHour);
parseddate=parseddate.replace('NN',pad(iMinute,2));
parseddate=parseddate.replace('N',iMinute);
$('#answer'+thisid).val(parseddate);
$('#answer'+thisid).change();
$('#qattribute_answer'+thisid).val('');
}
}

function pad (str, max) {
return str.length < max ? pad("0" + str, max) : str;
}

function ValidDate(oObject, value) {// Regular expression used to check if date is in correct format
var str_regexp = /[1-9][0-9]{3}-(0[1-9]|1[0-2])-([0-2][0-9]|3[0-1])/;
Expand Down

0 comments on commit 63e6761

Please sign in to comment.