diff --git a/dist/index.d.ts b/dist/index.d.ts index a383e90..ce0bd28 100644 --- a/dist/index.d.ts +++ b/dist/index.d.ts @@ -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 \ No newline at end of file diff --git a/dist/index.d.ts.map b/dist/index.d.ts.map index 544c5e1..135a925 100644 --- a/dist/index.d.ts.map +++ b/dist/index.d.ts.map @@ -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"} \ No newline at end of file +{"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"} \ No newline at end of file diff --git a/dist/index.js b/dist/index.js index 82bf8bf..298e9ea 100644 --- a/dist/index.js +++ b/dist/index.js @@ -36,9 +36,8 @@ var __importStar = (this && this.__importStar) || (function () { }; })(); Object.defineProperty(exports, "__esModule", { value: true }); -exports.Utility = exports.TimeSpan = exports.Logger = void 0; +exports.TimeHelper = 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")); +exports.TimeHelper = __importStar(require("./timehelper")); diff --git a/dist/logger.d.ts b/dist/logger.d.ts index cac43cb..0d4ace6 100644 --- a/dist/logger.d.ts +++ b/dist/logger.d.ts @@ -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 \ No newline at end of file diff --git a/dist/logger.d.ts.map b/dist/logger.d.ts.map index 843f22e..c324f67 100644 --- a/dist/logger.d.ts.map +++ b/dist/logger.d.ts.map @@ -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"} \ No newline at end of file +{"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"} \ No newline at end of file diff --git a/dist/logger.js b/dist/logger.js index e26403f..b5f398f 100644 --- a/dist/logger.js +++ b/dist/logger.js @@ -7,6 +7,8 @@ exports.logError = logError; exports.logWarning = logWarning; exports.logSuccess = logSuccess; exports.logInfo = logInfo; +exports.printNetworkError = printNetworkError; +const axios_1 = __importDefault(require("axios")); const chalk_1 = __importDefault(require("chalk")); function logError(...args) { console.error(chalk_1.default.red("ERROR:"), ...args); @@ -20,3 +22,17 @@ function logSuccess(...args) { function logInfo(...args) { console.info(chalk_1.default.cyan("INFO:"), ...args); } +function printNetworkError(error) { + if (axios_1.default.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); + } +} diff --git a/dist/timehelper.d.ts b/dist/timehelper.d.ts new file mode 100644 index 0000000..ff1a0be --- /dev/null +++ b/dist/timehelper.d.ts @@ -0,0 +1,9 @@ +export declare class TimeSpan { + private start; + private end; + constructor(timeSpanStr: string); + private parseTime; + contains(timestamp?: number): boolean; +} +export declare function secondsToReadable(secs: number, roundToMinutes?: boolean): string; +//# sourceMappingURL=timehelper.d.ts.map \ No newline at end of file diff --git a/dist/timehelper.d.ts.map b/dist/timehelper.d.ts.map new file mode 100644 index 0000000..b339475 --- /dev/null +++ b/dist/timehelper.d.ts.map @@ -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,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,MAAM,EACZ,cAAc,GAAE,OAAe,GAC9B,MAAM,CAmBR"} \ No newline at end of file diff --git a/dist/timehelper.js b/dist/timehelper.js new file mode 100644 index 0000000..83ced22 --- /dev/null +++ b/dist/timehelper.js @@ -0,0 +1,42 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.TimeSpan = void 0; +exports.secondsToReadable = secondsToReadable; +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; +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*$/, ""); +}