seanjensengrey / jsgantt

Automatically exported from code.google.com/p/jsgantt
0 stars 0 forks source link

Invalid date output is using format yyyy-mm-dd. #60

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
JSGantt Version: 1.2
Browser: FF v3
OS: XP SP 3

What steps will reproduce the problem?
1. g.setDateInputFormat('yyyy-mm-dd');
2. This will result in an incorrect start and end date in the respective
columns.
3.

What is the expected output? What do you see instead?
Expected out put is the input date for the task. Actual output was incorrect.

Expected Output: dd/mm/yyyy
Actual Output: mm/mm/yyyy

Please provide any additional information below.

In the function: JSGantt.parseDateStr = function(pDateStr,pFormatStr), the
year does not have the correct index. See below:

Original:

vDate.setFullYear(parseInt(vDateParts[0], 10), parseInt(vDateParts[1], 10)
- 1, parseInt(vDateParts[1], 10));

Fix:

vDate.setFullYear(parseInt(vDateParts[0], 10), parseInt(vDateParts[1], 10)
- 1, parseInt(vDateParts[2], 10));

Original issue reported on code.google.com by weblo...@computech-it.co.uk on 2 Oct 2009 at 12:46

GoogleCodeExporter commented 9 years ago
Currently, the default format of date is only 'mm/dd/yyyy'. In case of others, 
you
should customize function such as:
JSGantt.formatDateStr = function(pDate,pFormatStr) {
       vYear4Str = pDate.getFullYear() + '';
       vYear2Str = vYear4Str.substring(2,4);
       vMonthStr = (pDate.getMonth()+1) + '';
       vDayStr   = pDate.getDate() + '';

      var vDateStr = "";    

      switch(pFormatStr) {
            case 'mm/dd/yyyy':
               return( vMonthStr + '/' + vDayStr + '/' + vYear4Str );
            case 'mm.dd.yyyy':
               return( vMonthStr + '.' + vDayStr + '.' + vYear4Str );
            case 'dd.mm.yyyy':
               return( vDayStr + '.' + vMonthStr + '.' + vYear4Str );
            case 'dd/mm/yyyy':
               return( vDayStr + '/' + vMonthStr + '/' + vYear4Str );
            case 'yyyy-mm-dd':
               return( vYear4Str + '-' + vMonthStr + '-' + vDayStr );
            case 'yyyy.mm.dd':
               return( vYear4Str + '.' + vMonthStr + '.' + vDayStr );
            case 'mm/dd/yy':
               return( vMonthStr + '/' + vDayStr + '/' + vYear2Str );
            case 'mm.dd.yy':
               return( vMonthStr + '.' + vDayStr + '.' + vYear2Str );
            case 'dd/mm/yy':
               return( vDayStr + '/' + vMonthStr + '/' + vYear2Str );
            case 'dd.mm.yy':
               return( vDayStr + '.' + vMonthStr + '.' + vYear2Str );
            case 'yy-mm-dd':
               return( vYear2Str + '-' + vMonthStr + '-' + vDayStr );
            case 'yy.mm.dd':
               return( vYear2Str + '.' + vMonthStr + '.' + vDayStr );
            case 'mm/dd':
               return( vMonthStr + '/' + vDayStr );
            case 'dd/mm':
               return( vDayStr + '/' + vMonthStr );
            case 'dd.mm':
               return( vDayStr + '.' + vMonthStr );
            case 'mm.dd':
               return( vMonthStr + '.' + vDayStr );
            case 'dd-mm':
               return( vDayStr + '-' + vMonthStr );
            case 'mm-dd':
               return( vMonthStr + '-' + vDayStr );
            case 'dd-mm-yy':
               return( vDayStr + '-' + vMonthStr + '-' + vYear2Str );
            case 'dd-mm-yyyy':
               return( vDayStr + '-' + vMonthStr + '-' + vYear4Str );                  
      }
}

And:

JSGantt.parseDateStr = function(pDateStr,pFormatStr) {
   var vDate =new Date();   
   vDate.setTime( Date.parse(pDateStr));

   switch(pFormatStr) 
   {
      case 'mm/dd/yyyy':
         var vDateParts = pDateStr.split('/');
         vDate.setFullYear(parseInt(vDateParts[2], 10), parseInt(vDateParts[0], 10) -
1, parseInt(vDateParts[1], 10));
         break;
      case 'mm.dd.yyyy':
         var vDateParts = pDateStr.split('.');
         vDate.setFullYear(parseInt(vDateParts[2], 10), parseInt(vDateParts[0], 10) -
1, parseInt(vDateParts[1], 10));
         break;   
      case 'dd/mm/yyyy':
         var vDateParts = pDateStr.split('/');
         vDate.setFullYear(parseInt(vDateParts[2], 10), parseInt(vDateParts[1], 10) -
1, parseInt(vDateParts[0], 10));
         break;
      case 'yyyy-mm-dd':
         var vDateParts = pDateStr.split('-');
         vDate.setFullYear(parseInt(vDateParts[0], 10), parseInt(vDateParts[1], 10) -
1, parseInt(vDateParts[1], 10));
         break;
      case 'yyyy.mm.dd':
         var vDateParts = pDateStr.split('.');
         vDate.setFullYear(parseInt(vDateParts[0], 10), parseInt(vDateParts[1], 10) -
1, parseInt(vDateParts[1], 10));
         break;   
      case 'yyyy/mm/dd':
         var vDateParts = pDateStr.split('/');
         vDate.setFullYear(parseInt(vDateParts[0], 10), parseInt(vDateParts[1], 10) -
1, parseInt(vDateParts[1], 10));
         break;   
      case 'dd.mm.yyyy':
         var vDateParts = pDateStr.split('.');
         vDate.setFullYear(parseInt(vDateParts[2], 10), parseInt(vDateParts[1], 10) -
1, parseInt(vDateParts[0], 10));
         break;

    }

    return(vDate);

}

Hope this help,
TN

Original comment by dat...@gmail.com on 9 Nov 2009 at 7:16