diff --git a/dist/timespan.d.ts b/dist/timespan.d.ts new file mode 100644 index 0000000..a81c3aa --- /dev/null +++ b/dist/timespan.d.ts @@ -0,0 +1,8 @@ +export declare class TimeSpan { + private start; + private end; + constructor(timeSpanStr: string); + private parseTime; + contains(timestamp?: number): boolean; +} +//# sourceMappingURL=timespan.d.ts.map \ No newline at end of file diff --git a/dist/timespan.d.ts.map b/dist/timespan.d.ts.map new file mode 100644 index 0000000..a1085f5 --- /dev/null +++ b/dist/timespan.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"timespan.d.ts","sourceRoot":"","sources":["../src/timespan.ts"],"names":[],"mappings":"AAAA,qBAAa,QAAQ;IACnB,OAAO,CAAC,KAAK,CAAqC;IAClD,OAAO,CAAC,GAAG,CAAqC;gBAEpC,WAAW,EAAE,MAAM;IAM/B,OAAO,CAAC,SAAS;IAKjB,QAAQ,CAAC,SAAS,GAAE,MAAmB,GAAG,OAAO;CAgBlD"} \ No newline at end of file diff --git a/dist/timespan.js b/dist/timespan.js new file mode 100644 index 0000000..f8f1e98 --- /dev/null +++ b/dist/timespan.js @@ -0,0 +1,29 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.TimeSpan = void 0; +class TimeSpan { + constructor(timeSpanStr) { + const [startStr, endStr] = timeSpanStr.split("-"); + this.start = this.parseTime(startStr); + this.end = this.parseTime(endStr); + } + parseTime(timeStr) { + const [hours, minutes] = timeStr.split(":").map(Number); + return { hours, minutes }; + } + contains(timestamp = Date.now()) { + const date = new Date(timestamp); + const hours = date.getHours(); + const minutes = date.getMinutes(); + const currentMinutes = hours * 60 + minutes; + const startMinutes = this.start.hours * 60 + this.start.minutes; + const endMinutes = this.end.hours * 60 + this.end.minutes; + if (startMinutes > endMinutes) { + return currentMinutes >= startMinutes || currentMinutes < endMinutes; + } + else { + return currentMinutes >= startMinutes && currentMinutes < endMinutes; + } + } +} +exports.TimeSpan = TimeSpan;