Compare commits
4 Commits
e8161935b1
...
v1.0.3
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fee4ca327a | ||
|
|
60390fcbdf | ||
|
|
04322894b5 | ||
|
|
2e01edcb53 |
4
package-lock.json
generated
4
package-lock.json
generated
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "@dpu/shared",
|
||||
"version": "1.0.2",
|
||||
"version": "1.0.3",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@dpu/shared",
|
||||
"version": "1.0.2",
|
||||
"version": "1.0.3",
|
||||
"dependencies": {
|
||||
"axios": "^1.7.9",
|
||||
"chalk": "^5.6.2"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@dpu/shared",
|
||||
"version": "1.0.0",
|
||||
"version": "1.0.3",
|
||||
"description": "",
|
||||
"main": "dist/index.js",
|
||||
"types": "dist/index.d.ts",
|
||||
|
||||
32
src/timespan.ts
Normal file
32
src/timespan.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
export class TimeSpan {
|
||||
private start: { hours: number; minutes: number };
|
||||
private end: { hours: number; minutes: number };
|
||||
|
||||
constructor(timeSpanStr: string) {
|
||||
const [startStr, endStr] = timeSpanStr.split("-");
|
||||
this.start = this.parseTime(startStr);
|
||||
this.end = this.parseTime(endStr);
|
||||
}
|
||||
|
||||
private parseTime(timeStr: string) {
|
||||
const [hours, minutes] = timeStr.split(":").map(Number);
|
||||
return { hours, minutes };
|
||||
}
|
||||
|
||||
contains(timestamp: number = Date.now()): boolean {
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user