Error in date() function

When running the following code:
function make_csv() { local csv = ""; local d = ""; for (local i=1396963408; i<1396963408+3600; ++i) { d = date(i); csv += format("%i-%02i-%02i %02i:%02i:%02i %i\ ",d.year,d.month+1,d.day,d.hour,d.min,d.sec,i); } return csv; }
there is an error with the date() function roughly every second time I run the code. The error occurs randomly. E.g.:

2014-04-08 14:01:51 1396965711 2014-04-08 14:01:52 1396965712 2014-04-08 13:44:52 1396965713 2014-04-08 14:01:54 1396965714 2014-04-08 14:01:55 1396965715
It is easily observed when plotting the output:

Oops. I know what that is. Fix coming shortly…

Peter