visitor-segments
Version:
Hellobar Segments.
25 lines (24 loc) • 844 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.DateSegment = void 0;
const segmentMaps_1 = require("../segmentMaps");
const segment_1 = require("../segment");
class DateSegment extends segment_1.Segment {
constructor(visitor) {
super(segmentMaps_1.SEGMENT_KEYS.DATE, visitor);
}
setValue(value) {
super.setValue(value || yearMonthDay(new Date()));
}
}
exports.DateSegment = DateSegment;
// returns date in format of 'YYYY-MM-DD'
function yearMonthDay(date) {
function zeropad(value) {
const length = Math.max(value.length, 2);
return value.length >= length ? value : `0${value}`;
}
const month = date.getMonth() + 1;
const day = date.getDate();
return [date.getFullYear(), zeropad(month.toString()), zeropad(day.toString())].join('-');
}