@skbkontur/cassandra-distributed-task-queue-ui
Version:
.NET library implementing distributed task queue machinery using Apache Cassandra
47 lines • 1.62 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.RangeSelector = void 0;
const edi_ui_1 = require("@skbkontur/edi-ui");
const date_fns_1 = require("date-fns");
function utc() {
return edi_ui_1.DateUtils.toTimeZone(new Date(), edi_ui_1.TimeUtils.TimeZones.UTC);
}
class RangeSelector {
constructor(timeZone) {
Object.defineProperty(this, "timeZone", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
this.timeZone = timeZone == null ? -new Date().getTimezoneOffset() : timeZone;
}
setBounds(start, end = start) {
const lower = date_fns_1.startOfDay(start);
const upper = date_fns_1.endOfDay(end);
return {
lowerBound: edi_ui_1.DateUtils.toTimeZone(lower, this.timeZone),
upperBound: edi_ui_1.DateUtils.toTimeZone(upper, this.timeZone),
};
}
getYesterday() {
return this.setBounds(date_fns_1.subDays(utc(), 1));
}
getToday() {
return this.setBounds(utc());
}
getWeek() {
return this.setBounds(date_fns_1.subDays(utc(), 6), utc());
}
getMonth() {
return this.setBounds(date_fns_1.subMonths(utc(), 1), utc());
}
getMonthOf(date) {
return this.setBounds(date_fns_1.subMonths(edi_ui_1.DateUtils.toTimeZone(date, edi_ui_1.TimeUtils.TimeZones.UTC), 1), utc());
}
getYear() {
return this.setBounds(date_fns_1.subYears(utc(), 1), utc());
}
}
exports.RangeSelector = RangeSelector;
//# sourceMappingURL=RangeSelector.js.map