Improved the dates manupulation using d3 functions