src/js/util/process-dates.js
function autoDateFormatAndFrequency(minDate, maxDate, dateFormat, availableWidth) {
	var timespan = Math.abs(maxDate - minDate);
	var years = timespan / 31536000000;
	var months = timespan / 2628000000;
	var days = timespan / 86400000;
	var yearGap;
	var hourGap;
	var interval;

	var targetPixelGap = 64;
	var maximum_ticks = Math.max(Math.floor(availableWidth / targetPixelGap), 1);
	var time_gap = timespan / maximum_ticks;

	if (dateFormat == "auto") {
		//lets go small to large
		if (days <= 2) {
			dateFormat = "h";
		}
		else if (days <= 91) {
			dateFormat = "M1d";
		}
		else if (months < 36) {
			dateFormat = "M";
		}
		else {
			dateFormat = "yy";
		}
	}

	var gapInYears = humanReadableNumber(Math.floor(time_gap / 31536000000));
	var gapInMonths = Math.ceil(time_gap / 2628000000);
	var gapInDays = humanReadableNumber(time_gap / 86400000);
	var gapInHours = humanReadableNumber(time_gap / 3600000);

	//make sure that the interval include the maxDate in the interval list
	maxDate.addMilliseconds(0.1);

	switch (dateFormat) {
		case "yy":
			// Add a day to the max date for years to make inclusive of max date
			// irrespective of time zone / DST
			maxDate = d3.time.day.offset(maxDate, 1);
			interval = d3.time.year.range(minDate, maxDate, gapInYears);
			break;

		case "yyyy":
			// See above
			maxDate = d3.time.day.offset(maxDate, 1);
			interval = d3.time.year.range(minDate, maxDate, gapInYears);
			break;

		case "MM":
			interval = d3.time.month.range(minDate, maxDate, gapInMonths);
			break;

		case "M":
			interval = d3.time.month.range(minDate, maxDate, gapInMonths);
			break;

		case "Mdd":
			interval = d3.time.day.range(minDate, maxDate, gapInDays);
			break;

		case "M1d":
			interval = d3.time.day.range(minDate, maxDate, gapInDays);
			break;

		case "YY":
			interval = d3.time.year.range(minDate, maxDate, gapInYears);
			break;

		case "QJan":
			interval = d3.time.month.range(minDate, maxDate, 4);
			break;

		case "QJul":
			interval = d3.time.month.range(minDate, maxDate, 4);
			break;

		case "h":
			interval = d3.time.hour.range(minDate, maxDate, gapInHours);
			break;

		default:
			interval = d3.time.year.range(minDate, maxDate, 1);
	}

	interval = cleanInterval(interval);
	return {"format": dateFormat, "frequency": interval};
}
function autoDateFormatAndFrequency(minDate, maxDate, dateFormat, availableWidth) {
	var timespan = Math.abs(maxDate - minDate);
	var years = timespan / 31536000000;
	var months = timespan / 2628000000;
	var days = timespan / 86400000;
	var yearGap;
	var hourGap;
	var interval;

	var targetPixelGap = 64;
	var maximum_ticks = Math.max(Math.floor(availableWidth / targetPixelGap), 1);
	var time_gap = timespan / maximum_ticks;

	if (dateFormat == "auto") {
		//lets go small to large
		if (days <= 2) {
			dateFormat = "h";
		}
		else if (days <= 91) {
			dateFormat = "M1d";
		}
		else if (months < 36) {
			dateFormat = "M";
		}
		else {
			dateFormat = "yy";
		}
	}

	var gapInYears = humanReadableNumber(Math.floor(time_gap / 31536000000));
	var gapInMonths = Math.ceil(time_gap / 2628000000);
	var gapInDays = humanReadableNumber(time_gap / 86400000);
	var gapInHours = humanReadableNumber(time_gap / 3600000);

	//make sure that the interval include the maxDate in the interval list
	maxDate.addMilliseconds(0.1);

	switch (dateFormat) {
		case "yy":
			// Add a day to the max date for years to make inclusive of max date
			// irrespective of time zone / DST
			maxDate = d3.time.day.offset(maxDate, 1);
			interval = d3.time.year.range(minDate, maxDate, gapInYears);
			break;

		case "yyyy":
			// See above
			maxDate = d3.time.day.offset(maxDate, 1);
			interval = d3.time.year.range(minDate, maxDate, gapInYears);
			break;

		case "MM":
			interval = d3.time.month.range(minDate, maxDate, gapInMonths);
			break;

		case "M":
			interval = d3.time.month.range(minDate, maxDate, gapInMonths);
			break;

		case "Mdd":
			interval = d3.time.day.range(minDate, maxDate, gapInDays);
			break;

		case "M1d":
			interval = d3.time.day.range(minDate, maxDate, gapInDays);
			break;

		case "YY":
			interval = d3.time.year.range(minDate, maxDate, gapInYears);
			break;

		case "QJan":
			interval = d3.time.month.range(minDate, maxDate, 4);
			break;

		case "QJul":
			interval = d3.time.month.range(minDate, maxDate, 4);
			break;

		case "h":
			interval = d3.time.hour.range(minDate, maxDate, gapInHours);
			break;

		default:
			interval = d3.time.year.range(minDate, maxDate, 1);
	}

	interval = cleanInterval(interval);
	return {"format": dateFormat, "frequency": interval};
}
Automatically calculate date frequency if not selected