in glean/src/core/metrics/types/datetime.ts [209:238]
private truncateDate(value?: Date) {
if (!value) {
value = new Date();
}
// We always save a milliseconds precision ISO string on the database,
// regardless of the time unit. So we zero out information that
// is not necessary for the current time unit of this metric.
const truncatedDate = value;
switch (this.timeUnit) {
case TimeUnit.Day:
truncatedDate.setMilliseconds(0);
truncatedDate.setSeconds(0);
truncatedDate.setMinutes(0);
truncatedDate.setMilliseconds(0);
case TimeUnit.Hour:
truncatedDate.setMilliseconds(0);
truncatedDate.setSeconds(0);
truncatedDate.setMinutes(0);
case TimeUnit.Minute:
truncatedDate.setMilliseconds(0);
truncatedDate.setSeconds(0);
case TimeUnit.Second:
truncatedDate.setMilliseconds(0);
default:
break;
}
return truncatedDate;
}