Friday, May 30, 2008

Date bug in GAMS/IDE

The date format is coded as the number of days since jan 1, 1900. However, it is one off compared to Excel, Access and compared to the date format in Delphi. It is also one off compared to the IDE Charting facility:


set
j /x,y/
i /i1,i2,i3/
;
 
parameter data(i,j);
 
* may 30, may 31, june 1
data(i,'x') = jdate(2008,5,30)+ord(i)-1;
data(i,'y') = ord(i);
 
* check dates
parameter check(i,*);
check(i,'year') = gyear(data(i,'x'));
check(i,'month') = gmonth(data(i,'x'));
check(i,'day') = gday(data(i,'x'));
 
option check:0:1:1;
 
display data,check;
 
execute_unload 'data',data;


The result display is:

----     20 PARAMETER data  
 
x y
 
i1 39597.000 1.000
i2 39598.000 2.000
i3 39599.000 3.000
 
 
---- 20 PARAMETER check
 
year month day
 
i1 2008 5 30
i2 2008 5 31
i3 2008 6 1


The chart is:





The dates on the x-axis are wrong (click to enlarge). The work around is to add one to each date before exporting (and subtract one after importing).

No comments:

Post a Comment