Compare commits
16 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7659fa0cf4 | ||
|
|
314ef5c2ff | ||
|
|
9b02c09677 | ||
|
|
45f4ca4d63 | ||
|
|
1aade62ddb | ||
|
|
31a02625e8 | ||
|
|
16c262f2c4 | ||
|
|
dfa93723ef | ||
|
|
59900bf294 | ||
|
|
1ab38c4c87 | ||
|
|
b47db3cf05 | ||
|
|
32c21f82eb | ||
|
|
5afb0e243d | ||
|
|
a80e4ec00d | ||
|
|
7beb867bd5 | ||
|
|
d11d6bf5b1 |
11
dist/homeassistant.d.ts
vendored
11
dist/homeassistant.d.ts
vendored
@@ -1,3 +1,4 @@
|
||||
import { TimeBetween } from "./timehelper";
|
||||
export type HomeAssistantEntity = {
|
||||
entity_id: string;
|
||||
state: string;
|
||||
@@ -19,7 +20,13 @@ export type HomeAssistantEntity = {
|
||||
};
|
||||
export interface HomeAssistantDeskPositionResult {
|
||||
raw: HomeAssistantEntity;
|
||||
asBoolean: boolean;
|
||||
asText: () => string;
|
||||
as_boolean: boolean;
|
||||
as_text: () => string;
|
||||
last_changed: TimeBetween;
|
||||
}
|
||||
export type API_HA_DeskPosition = {
|
||||
position: string;
|
||||
is_standing: boolean;
|
||||
last_changed: string;
|
||||
};
|
||||
//# sourceMappingURL=homeassistant.d.ts.map
|
||||
2
dist/homeassistant.d.ts.map
vendored
2
dist/homeassistant.d.ts.map
vendored
@@ -1 +1 @@
|
||||
{"version":3,"file":"homeassistant.d.ts","sourceRoot":"","sources":["../src/homeassistant.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,mBAAmB,GAAG;IAChC,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE;QACV,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,mBAAmB,CAAC,EAAE,MAAM,CAAC;QAC7B,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,aAAa,CAAC,EAAE,MAAM,CAAC;QACvB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;KACxB,CAAC;IACF,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,MAAM,CAAC;IACtB,YAAY,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE;QACP,EAAE,EAAE,MAAM,CAAC;QACX,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;QACzB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;KACxB,CAAC;CACH,CAAC;AAEF,MAAM,WAAW,+BAA+B;IAC9C,GAAG,EAAE,mBAAmB,CAAC;IACzB,SAAS,EAAE,OAAO,CAAC;IACnB,MAAM,EAAE,MAAM,MAAM,CAAC;CACtB"}
|
||||
{"version":3,"file":"homeassistant.d.ts","sourceRoot":"","sources":["../src/homeassistant.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C,MAAM,MAAM,mBAAmB,GAAG;IAChC,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE;QACV,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,mBAAmB,CAAC,EAAE,MAAM,CAAC;QAC7B,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,aAAa,CAAC,EAAE,MAAM,CAAC;QACvB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;KACxB,CAAC;IACF,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,MAAM,CAAC;IACtB,YAAY,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE;QACP,EAAE,EAAE,MAAM,CAAC;QACX,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;QACzB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;KACxB,CAAC;CACH,CAAC;AAEF,MAAM,WAAW,+BAA+B;IAC9C,GAAG,EAAE,mBAAmB,CAAC;IACzB,UAAU,EAAE,OAAO,CAAC;IACpB,OAAO,EAAE,MAAM,MAAM,CAAC;IACtB,YAAY,EAAE,WAAW,CAAC;CAC3B;AAED,MAAM,MAAM,mBAAmB,GAAG;IAChC,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,OAAO,CAAC;IACrB,YAAY,EAAE,MAAM,CAAC;CACtB,CAAC"}
|
||||
3
dist/homeassistant.js
vendored
3
dist/homeassistant.js
vendored
@@ -1,2 +1 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
export {};
|
||||
|
||||
3
dist/index.d.ts
vendored
3
dist/index.d.ts
vendored
@@ -1,6 +1,5 @@
|
||||
export * from "./homeassistant";
|
||||
export * as Logger from "./logger";
|
||||
export * from "./tidal";
|
||||
export * as TimeSpan from "./timespan";
|
||||
export * as Utility from "./utility";
|
||||
export * as TimeHelper from "./timehelper";
|
||||
//# sourceMappingURL=index.d.ts.map
|
||||
2
dist/index.d.ts.map
vendored
2
dist/index.d.ts.map
vendored
@@ -1 +1 @@
|
||||
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,OAAO,KAAK,MAAM,MAAM,UAAU,CAAC;AACnC,cAAc,SAAS,CAAC;AACxB,OAAO,KAAK,QAAQ,MAAM,YAAY,CAAC;AACvC,OAAO,KAAK,OAAO,MAAM,WAAW,CAAC"}
|
||||
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,OAAO,KAAK,MAAM,MAAM,UAAU,CAAC;AACnC,cAAc,SAAS,CAAC;AACxB,OAAO,KAAK,UAAU,MAAM,cAAc,CAAC"}
|
||||
48
dist/index.js
vendored
48
dist/index.js
vendored
@@ -1,44 +1,4 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
||||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
||||
};
|
||||
var __importStar = (this && this.__importStar) || (function () {
|
||||
var ownKeys = function(o) {
|
||||
ownKeys = Object.getOwnPropertyNames || function (o) {
|
||||
var ar = [];
|
||||
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
||||
return ar;
|
||||
};
|
||||
return ownKeys(o);
|
||||
};
|
||||
return function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
})();
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Utility = exports.TimeSpan = exports.Logger = void 0;
|
||||
__exportStar(require("./homeassistant"), exports);
|
||||
exports.Logger = __importStar(require("./logger"));
|
||||
__exportStar(require("./tidal"), exports);
|
||||
exports.TimeSpan = __importStar(require("./timespan"));
|
||||
exports.Utility = __importStar(require("./utility"));
|
||||
export * from "./homeassistant";
|
||||
export * as Logger from "./logger";
|
||||
export * from "./tidal";
|
||||
export * as TimeHelper from "./timehelper";
|
||||
|
||||
1
dist/logger.d.ts
vendored
1
dist/logger.d.ts
vendored
@@ -2,4 +2,5 @@ export declare function logError(...args: unknown[]): void;
|
||||
export declare function logWarning(...args: unknown[]): void;
|
||||
export declare function logSuccess(...args: unknown[]): void;
|
||||
export declare function logInfo(...args: unknown[]): void;
|
||||
export declare function printNetworkError(error: unknown): void;
|
||||
//# sourceMappingURL=logger.d.ts.map
|
||||
2
dist/logger.d.ts.map
vendored
2
dist/logger.d.ts.map
vendored
@@ -1 +1 @@
|
||||
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAEA,wBAAgB,QAAQ,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,QAE1C;AAED,wBAAgB,UAAU,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,QAE5C;AAED,wBAAgB,UAAU,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,QAE5C;AAED,wBAAgB,OAAO,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,QAEzC"}
|
||||
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAGA,wBAAgB,QAAQ,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,QAE1C;AAED,wBAAgB,UAAU,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,QAE5C;AAED,wBAAgB,UAAU,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,QAE5C;AAED,wBAAgB,OAAO,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,QAEzC;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,QAY/C"}
|
||||
42
dist/logger.js
vendored
42
dist/logger.js
vendored
@@ -1,22 +1,28 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.logError = logError;
|
||||
exports.logWarning = logWarning;
|
||||
exports.logSuccess = logSuccess;
|
||||
exports.logInfo = logInfo;
|
||||
const chalk_1 = __importDefault(require("chalk"));
|
||||
function logError(...args) {
|
||||
console.error(chalk_1.default.red("ERROR:"), ...args);
|
||||
import axios from "axios";
|
||||
import chalk from "chalk";
|
||||
export function logError(...args) {
|
||||
console.error(chalk.red("ERROR:"), ...args);
|
||||
}
|
||||
function logWarning(...args) {
|
||||
console.warn(chalk_1.default.yellow("WARNING:"), ...args);
|
||||
export function logWarning(...args) {
|
||||
console.warn(chalk.yellow("WARNING:"), ...args);
|
||||
}
|
||||
function logSuccess(...args) {
|
||||
console.info(chalk_1.default.green("SUCCESS:"), ...args);
|
||||
export function logSuccess(...args) {
|
||||
console.info(chalk.green("SUCCESS:"), ...args);
|
||||
}
|
||||
function logInfo(...args) {
|
||||
console.info(chalk_1.default.cyan("INFO:"), ...args);
|
||||
export function logInfo(...args) {
|
||||
console.info(chalk.cyan("INFO:"), ...args);
|
||||
}
|
||||
export function printNetworkError(error) {
|
||||
if (axios.isAxiosError(error)) {
|
||||
logError("Axios error details:", {
|
||||
message: error.message,
|
||||
status: error.response?.status,
|
||||
statusText: error.response?.statusText,
|
||||
data: error.response?.data,
|
||||
url: error.config?.url,
|
||||
});
|
||||
}
|
||||
else {
|
||||
logError("Unexpected error:", error);
|
||||
}
|
||||
}
|
||||
|
||||
3
dist/tidal.js
vendored
3
dist/tidal.js
vendored
@@ -1,2 +1 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
export {};
|
||||
|
||||
14
dist/timehelper.d.ts
vendored
Normal file
14
dist/timehelper.d.ts
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
export declare class TimeSpan {
|
||||
private start;
|
||||
private end;
|
||||
constructor(timeSpanStr: string);
|
||||
private parseTime;
|
||||
contains(timestamp?: number): boolean;
|
||||
}
|
||||
export interface TimeBetween {
|
||||
seconds: number;
|
||||
toReadable: (roundToMinutes?: boolean) => string;
|
||||
}
|
||||
export declare function calculateSecondsBetween(start: number, end: number): TimeBetween;
|
||||
export declare function secondsToReadable(secs: number, roundToMinutes?: boolean): string;
|
||||
//# sourceMappingURL=timehelper.d.ts.map
|
||||
1
dist/timehelper.d.ts.map
vendored
Normal file
1
dist/timehelper.d.ts.map
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"timehelper.d.ts","sourceRoot":"","sources":["../src/timehelper.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;AAED,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,CAAC,cAAc,CAAC,EAAE,OAAO,KAAK,MAAM,CAAC;CAClD;AAED,wBAAgB,uBAAuB,CACrC,KAAK,EAAE,MAAM,EACb,GAAG,EAAE,MAAM,GACV,WAAW,CAOb;AAED,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,MAAM,EACZ,cAAc,GAAE,OAAe,GAC9B,MAAM,CAmBR"}
|
||||
46
dist/timehelper.js
vendored
Normal file
46
dist/timehelper.js
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
export class TimeSpan {
|
||||
start;
|
||||
end;
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
export function calculateSecondsBetween(start, end) {
|
||||
const seconds = Math.max(60, (end - start) / 1000);
|
||||
return {
|
||||
seconds,
|
||||
toReadable: (roundToMinutes) => secondsToReadable(seconds, roundToMinutes),
|
||||
};
|
||||
}
|
||||
export function secondsToReadable(secs, roundToMinutes = false) {
|
||||
const totalSeconds = roundToMinutes ? Math.round(secs / 60) * 60 : secs;
|
||||
var days = Math.floor(totalSeconds / (3600 * 24));
|
||||
var hours = Math.floor((totalSeconds % (3600 * 24)) / 3600);
|
||||
var minutes = Math.floor((totalSeconds % 3600) / 60);
|
||||
var seconds = Math.floor(totalSeconds % 60);
|
||||
var dayDisplay = days > 0 ? days + (days === 1 ? " day, " : " days, ") : "";
|
||||
var hourDisplay = hours > 0 ? hours + (hours === 1 ? " hour, " : " hours, ") : "";
|
||||
var minuteDisplay = minutes > 0 ? minutes + (minutes === 1 ? " minute, " : " minutes, ") : "";
|
||||
var secondDisplay = seconds > 0 ? seconds + (seconds === 1 ? " second" : " seconds") : "";
|
||||
return (dayDisplay + hourDisplay + minuteDisplay + secondDisplay).replace(/,\s*$/, "");
|
||||
}
|
||||
4
package-lock.json
generated
4
package-lock.json
generated
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "@dpu/shared",
|
||||
"version": "1.0.5",
|
||||
"version": "1.0.13",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@dpu/shared",
|
||||
"version": "1.0.5",
|
||||
"version": "1.0.13",
|
||||
"dependencies": {
|
||||
"axios": "^1.7.9",
|
||||
"chalk": "^5.6.2"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@dpu/shared",
|
||||
"version": "1.0.5",
|
||||
"version": "1.0.13",
|
||||
"description": "",
|
||||
"main": "dist/index.js",
|
||||
"types": "dist/index.d.ts",
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { TimeBetween } from "./timehelper";
|
||||
|
||||
export type HomeAssistantEntity = {
|
||||
entity_id: string;
|
||||
state: string;
|
||||
@@ -20,6 +22,13 @@ export type HomeAssistantEntity = {
|
||||
|
||||
export interface HomeAssistantDeskPositionResult {
|
||||
raw: HomeAssistantEntity;
|
||||
asBoolean: boolean;
|
||||
asText: () => string;
|
||||
as_boolean: boolean;
|
||||
as_text: () => string;
|
||||
last_changed: TimeBetween;
|
||||
}
|
||||
|
||||
export type API_HA_DeskPosition = {
|
||||
position: string;
|
||||
is_standing: boolean;
|
||||
last_changed: string;
|
||||
};
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
export * from "./homeassistant";
|
||||
export * as Logger from "./logger";
|
||||
export * from "./tidal";
|
||||
export * as TimeSpan from "./timespan";
|
||||
export * as Utility from "./utility";
|
||||
export * as TimeHelper from "./timehelper";
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import axios from "axios";
|
||||
import chalk from "chalk";
|
||||
|
||||
export function logError(...args: unknown[]) {
|
||||
@@ -15,3 +16,17 @@ export function logSuccess(...args: unknown[]) {
|
||||
export function logInfo(...args: unknown[]) {
|
||||
console.info(chalk.cyan("INFO:"), ...args);
|
||||
}
|
||||
|
||||
export function printNetworkError(error: unknown) {
|
||||
if (axios.isAxiosError(error)) {
|
||||
logError("Axios error details:", {
|
||||
message: error.message,
|
||||
status: error.response?.status,
|
||||
statusText: error.response?.statusText,
|
||||
data: error.response?.data,
|
||||
url: error.config?.url,
|
||||
});
|
||||
} else {
|
||||
logError("Unexpected error:", error);
|
||||
}
|
||||
}
|
||||
|
||||
73
src/timehelper.ts
Normal file
73
src/timehelper.ts
Normal file
@@ -0,0 +1,73 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export interface TimeBetween {
|
||||
seconds: number;
|
||||
toReadable: (roundToMinutes?: boolean) => string;
|
||||
}
|
||||
|
||||
export function calculateSecondsBetween(
|
||||
start: number,
|
||||
end: number,
|
||||
): TimeBetween {
|
||||
const seconds = Math.max(60, (end - start) / 1000);
|
||||
return {
|
||||
seconds,
|
||||
toReadable: (roundToMinutes?: boolean) =>
|
||||
secondsToReadable(seconds, roundToMinutes),
|
||||
};
|
||||
}
|
||||
|
||||
export function secondsToReadable(
|
||||
secs: number,
|
||||
roundToMinutes: boolean = false,
|
||||
): string {
|
||||
const totalSeconds = roundToMinutes ? Math.round(secs / 60) * 60 : secs;
|
||||
|
||||
var days = Math.floor(totalSeconds / (3600 * 24));
|
||||
var hours = Math.floor((totalSeconds % (3600 * 24)) / 3600);
|
||||
var minutes = Math.floor((totalSeconds % 3600) / 60);
|
||||
var seconds = Math.floor(totalSeconds % 60);
|
||||
|
||||
var dayDisplay = days > 0 ? days + (days === 1 ? " day, " : " days, ") : "";
|
||||
var hourDisplay =
|
||||
hours > 0 ? hours + (hours === 1 ? " hour, " : " hours, ") : "";
|
||||
var minuteDisplay =
|
||||
minutes > 0 ? minutes + (minutes === 1 ? " minute, " : " minutes, ") : "";
|
||||
var secondDisplay =
|
||||
seconds > 0 ? seconds + (seconds === 1 ? " second" : " seconds") : "";
|
||||
return (dayDisplay + hourDisplay + minuteDisplay + secondDisplay).replace(
|
||||
/,\s*$/,
|
||||
"",
|
||||
);
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
import axios from "axios";
|
||||
import { logError } from "./logger";
|
||||
|
||||
export function secondsToReadable(
|
||||
secs: number,
|
||||
roundToMinutes: boolean = false,
|
||||
): string {
|
||||
const totalSeconds = roundToMinutes ? Math.round(secs / 60) * 60 : secs;
|
||||
|
||||
var days = Math.floor(totalSeconds / (3600 * 24));
|
||||
var hours = Math.floor((totalSeconds % (3600 * 24)) / 3600);
|
||||
var minutes = Math.floor((totalSeconds % 3600) / 60);
|
||||
var seconds = Math.floor(totalSeconds % 60);
|
||||
|
||||
var dayDisplay = days > 0 ? days + (days === 1 ? " day, " : " days, ") : "";
|
||||
var hourDisplay =
|
||||
hours > 0 ? hours + (hours === 1 ? " hour, " : " hours, ") : "";
|
||||
var minuteDisplay =
|
||||
minutes > 0 ? minutes + (minutes === 1 ? " minute, " : " minutes, ") : "";
|
||||
var secondDisplay =
|
||||
seconds > 0 ? seconds + (seconds === 1 ? " second" : " seconds") : "";
|
||||
return (dayDisplay + hourDisplay + minuteDisplay + secondDisplay).replace(
|
||||
/,\s*$/,
|
||||
"",
|
||||
);
|
||||
}
|
||||
|
||||
export function printNetworkError(error: unknown) {
|
||||
if (axios.isAxiosError(error)) {
|
||||
logError("Axios error details:", {
|
||||
message: error.message,
|
||||
status: error.response?.status,
|
||||
statusText: error.response?.statusText,
|
||||
data: error.response?.data,
|
||||
url: error.config?.url,
|
||||
});
|
||||
} else {
|
||||
logError("Unexpected error:", error);
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES2020",
|
||||
"module": "commonjs",
|
||||
"lib": ["ES2020"],
|
||||
"target": "ES2022",
|
||||
"module": "ES2022",
|
||||
"lib": ["ES2022"],
|
||||
"types": ["node"],
|
||||
"declaration": true,
|
||||
"declarationMap": true,
|
||||
|
||||
Reference in New Issue
Block a user