Fix date calculations

See for instance http://jsfiddle.net/yKJ59/