in resources/perf.webkit.org/public/v3/components/time-series-chart.js [621:672]
static computeTimeGrid(min, max, maxLabels)
{
const diffPerLabel = (max - min) / maxLabels;
let iterator;
for (iterator of this._timeIterators()) {
if (iterator.diff >= diffPerLabel)
break;
}
console.assert(iterator);
const currentTime = new Date(min);
currentTime.setUTCMilliseconds(0);
currentTime.setUTCSeconds(0);
currentTime.setUTCMinutes(0);
iterator.next(currentTime);
const fitsInOneDay = max - min < 24 * 3600 * 1000;
let result = [];
let previousDate = null;
let previousMonth = null;
while (currentTime <= max && result.length < maxLabels) {
const time = new Date(currentTime);
const month = time.getUTCMonth() + 1;
const date = time.getUTCDate();
const hour = time.getUTCHours();
const hourLabel = ((hour % 12) || 12) + (hour >= 12 ? 'PM' : 'AM');
iterator.next(currentTime);
let label;
const isMidnight = !hour;
if ((date == previousDate && month == previousMonth) || ((!isMidnight || previousDate == null) && fitsInOneDay))
label = hourLabel;
else {
label = `${month}/${date}`;
if (!isMidnight && currentTime.getUTCDate() != date)
label += ' ' + hourLabel;
}
result.push({time: time, label: label});
previousDate = date;
previousMonth = month;
}
console.assert(result.length <= maxLabels);
return result;
}