Fix date index calculation