nhb-toolbox 3.5.20 → 3.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import type { FormatOptions, TimeZone, UTCOffSet } from './types';
1
+ import type { FormatOptions, TimeUnit, TimeZone, UTCOffSet } from './types';
2
2
  export declare class Chronos {
3
3
  #private;
4
4
  /**
@@ -81,16 +81,6 @@ export declare class Chronos {
81
81
  * @returns A new `Chronos` instance with the updated date.
82
82
  */
83
83
  subtractDays(days: number): Chronos;
84
- /**
85
- * * Determines if the given date is today, tomorrow, yesterday or any relative day.
86
- * @param date - The date to compare (Date object).
87
- * @returns
88
- * - `-1` if the date is yesterday.
89
- * - `0` if the date is today.
90
- * - `1` if the date is tomorrow.
91
- * - Other positive or negative numbers for other relative days (e.g., `-2` for two days ago, `2` for two days ahead).
92
- */
93
- getRelativeDay(): number;
94
84
  /**
95
85
  * * Checks if the year is a leap year.
96
86
  * - A year is a leap year if it is divisible by 4, but not divisible by 100, unless it is also divisible by 400.
@@ -105,5 +95,44 @@ export declare class Chronos {
105
95
  * @returns A new instance of `Chronos` with time in the given timezone. Invalid input sets time-zone to `UTC`.
106
96
  */
107
97
  timeZone(zone: TimeZone | UTCOffSet): Chronos;
98
+ /** - Checks if the current date is today. */
99
+ isToday(): boolean;
100
+ /** - Checks if the current date is tomorrow. */
101
+ isTomorrow(): boolean;
102
+ /** - Checks if the current date is yesterday. */
103
+ isYesterday(): boolean;
104
+ /**
105
+ * * Returns full time difference from now (or specified time) in years, months, days, hours, minutes, and seconds.
106
+ * @param time An optional time value (`number`, `string`, `Date`, or `Chronos` object).
107
+ * @returns The difference as string, e.g., `2 years 1 month 9 days 18 hours 56 minutes 9 seconds ago`.
108
+ */
109
+ fromNow(time?: string | number | Date | Chronos): string;
110
+ /** * Returns the number of full years between the input date and now. */
111
+ getRelativeYear(): number;
112
+ /** * Returns the number of full months between the input date and now. */
113
+ getRelativeMonth(): number;
114
+ /**
115
+ * * Determines if the given date is today, tomorrow, yesterday or any relative day.
116
+ * @param date - The date to compare (Date object).
117
+ * @returns
118
+ * - `-1` if the date is yesterday.
119
+ * - `0` if the date is today.
120
+ * - `1` if the date is tomorrow.
121
+ * - Other positive or negative numbers for other relative days (e.g., `-2` for two days ago, `2` for two days ahead).
122
+ */
123
+ getRelativeDay(): number;
124
+ /** * Returns the number of full hours between the input date and now. */
125
+ getRelativeHour(): number;
126
+ /** * Returns the number of full minutes between the input date and now. */
127
+ getRelativeMinute(): number;
128
+ /** * Returns the number of full seconds between the input date and now. */
129
+ getRelativeSecond(): number;
130
+ /** * Returns the number of milliseconds between the input date and now. */
131
+ getRelativeMilliSecond(): number;
132
+ /**
133
+ * * Compares the stored date with now, returning the difference in the specified unit.
134
+ * @param unit The time unit to compare by. Defaults to 'minute'.
135
+ */
136
+ compare(unit?: TimeUnit): number;
108
137
  }
109
138
  //# sourceMappingURL=Chronos.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Chronos.d.ts","sourceRoot":"","sources":["../../src/date/Chronos.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAEX,aAAa,EACb,QAAQ,EACR,SAAS,EACT,MAAM,SAAS,CAAC;AAGjB,qBAAa,OAAO;;IAInB;;;;;;;;OAQG;gBACS,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,OAAO;IAepD,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,MAAM,CAEjC;IAED;;;;OAIG;IACH,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM;IAKnD,4EAA4E;IAC5E,MAAM,IAAI,MAAM;IAIhB,6EAA6E;IAC7E,OAAO,IAAI,MAAM;IAIjB,qDAAqD;IACrD,MAAM,IAAI,IAAI;IAId,mGAAmG;IACnG,QAAQ,IAAI,MAAM;IAIlB,wDAAwD;IACxD,WAAW,IAAI,MAAM;I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IAAI,MAAM;IAc1B;;;;;;;;OAQG;IACH,cAAc,IAAI,MAAM;IAexB,yEAAyE;IACzE,eAAe,IAAI,MAAM;IAKzB,2EAA2E;IAC3E,iBAAiB,IAAI,MAAM;IAK3B,2EAA2E;IAC3E,iBAAiB,IAAI,MAAM;IAK3B,2EAA2E;IAC3E,sBAAsB,IAAI,MAAM;IAIhC;;;OAGG;IACH,OAAO,CAAC,IAAI,GAAE,QAAmB,GAAG,MAAM;CAoB1C"}
@@ -209,26 +209,6 @@ export class Chronos {
209
209
  subtractDays(days) {
210
210
  return this.addDays(-days);
211
211
  }
212
- /**
213
- * * Determines if the given date is today, tomorrow, yesterday or any relative day.
214
- * @param date - The date to compare (Date object).
215
- * @returns
216
- * - `-1` if the date is yesterday.
217
- * - `0` if the date is today.
218
- * - `1` if the date is tomorrow.
219
- * - Other positive or negative numbers for other relative days (e.g., `-2` for two days ago, `2` for two days ahead).
220
- */
221
- getRelativeDay() {
222
- const today = new Date();
223
- // Set the time of today to 00:00:00 for comparison purposes
224
- today.setHours(0, 0, 0, 0);
225
- // Normalize the input date to 00:00:00
226
- const inputDate = new Date(this.#date);
227
- inputDate.setHours(0, 0, 0, 0);
228
- const diffTime = inputDate.getTime() - today.getTime();
229
- const diffDays = Math.floor(diffTime / (1000 * 60 * 60 * 24));
230
- return diffDays;
231
- }
232
212
  /**
233
213
  * * Checks if the year is a leap year.
234
214
  * - A year is a leap year if it is divisible by 4, but not divisible by 100, unless it is also divisible by 400.
@@ -257,4 +237,162 @@ export class Chronos {
257
237
  const adjusted = new Date(utc + offset * 60 * 1000);
258
238
  return new Chronos(adjusted);
259
239
  }
240
+ /** - Checks if the current date is today. */
241
+ isToday() {
242
+ return this.getRelativeDay() === 0;
243
+ }
244
+ /** - Checks if the current date is tomorrow. */
245
+ isTomorrow() {
246
+ return this.getRelativeDay() === 1;
247
+ }
248
+ /** - Checks if the current date is yesterday. */
249
+ isYesterday() {
250
+ return this.getRelativeDay() === -1;
251
+ }
252
+ /**
253
+ * * Returns full time difference from now (or specified time) in years, months, days, hours, minutes, and seconds.
254
+ * @param time An optional time value (`number`, `string`, `Date`, or `Chronos` object).
255
+ * @returns The difference as string, e.g., `2 years 1 month 9 days 18 hours 56 minutes 9 seconds ago`.
256
+ */
257
+ fromNow(time) {
258
+ const now = time instanceof Chronos ?
259
+ time.toDate()
260
+ : new Date(time ?? Date.now());
261
+ // Check if the date is invalid
262
+ if (isNaN(now.getTime())) {
263
+ throw new Error('Provided date is invalid!');
264
+ }
265
+ const target = this.#date;
266
+ const isFuture = target > now;
267
+ const from = isFuture ? now : target;
268
+ const to = isFuture ? target : now;
269
+ let years = to.getFullYear() - from.getFullYear();
270
+ let months = to.getMonth() - from.getMonth();
271
+ let days = to.getDate() - from.getDate();
272
+ let hours = to.getHours() - from.getHours();
273
+ let minutes = to.getMinutes() - from.getMinutes();
274
+ let seconds = to.getSeconds() - from.getSeconds();
275
+ // Adjust negative values
276
+ if (seconds < 0) {
277
+ seconds += 60;
278
+ minutes--;
279
+ }
280
+ if (minutes < 0) {
281
+ minutes += 60;
282
+ hours--;
283
+ }
284
+ if (hours < 0) {
285
+ hours += 24;
286
+ days--;
287
+ }
288
+ if (days < 0) {
289
+ const prevMonth = new Date(to.getFullYear(), to.getMonth(), 0);
290
+ days += prevMonth.getDate();
291
+ months--;
292
+ }
293
+ if (months < 0) {
294
+ months += 12;
295
+ years--;
296
+ }
297
+ const parts = [];
298
+ if (years > 0)
299
+ parts.push(`${years} year${years > 1 ? 's' : ''}`);
300
+ if (months > 0)
301
+ parts.push(`${months} month${months > 1 ? 's' : ''}`);
302
+ if (days > 0)
303
+ parts.push(`${days} day${days > 1 ? 's' : ''}`);
304
+ if (hours > 0)
305
+ parts.push(`${hours} hour${hours > 1 ? 's' : ''}`);
306
+ if (minutes > 0)
307
+ parts.push(`${minutes} minute${minutes > 1 ? 's' : ''}`);
308
+ if (seconds > 0 || parts.length === 0)
309
+ parts.push(`${seconds} second${seconds !== 1 ? 's' : ''}`);
310
+ return `${isFuture ? 'in ' : ''}${parts.join(' ')}${isFuture ? '' : ' ago'}`;
311
+ }
312
+ /** * Returns the number of full years between the input date and now. */
313
+ getRelativeYear() {
314
+ const now = new Date();
315
+ let years = now.getFullYear() - this.#date.getFullYear();
316
+ const hasNotHadBirthday = now.getMonth() < this.#date.getMonth() ||
317
+ (now.getMonth() === this.#date.getMonth() &&
318
+ now.getDate() < this.#date.getDate());
319
+ if (hasNotHadBirthday) {
320
+ years--;
321
+ }
322
+ return years;
323
+ }
324
+ /** * Returns the number of full months between the input date and now. */
325
+ getRelativeMonth() {
326
+ const now = new Date();
327
+ let months = (now.getFullYear() - this.#date.getFullYear()) * 12 +
328
+ (now.getMonth() - this.#date.getMonth());
329
+ const hasNotHadMonthDay = now.getDate() < this.#date.getDate();
330
+ if (hasNotHadMonthDay) {
331
+ months--;
332
+ }
333
+ return months;
334
+ }
335
+ /**
336
+ * * Determines if the given date is today, tomorrow, yesterday or any relative day.
337
+ * @param date - The date to compare (Date object).
338
+ * @returns
339
+ * - `-1` if the date is yesterday.
340
+ * - `0` if the date is today.
341
+ * - `1` if the date is tomorrow.
342
+ * - Other positive or negative numbers for other relative days (e.g., `-2` for two days ago, `2` for two days ahead).
343
+ */
344
+ getRelativeDay() {
345
+ const today = new Date();
346
+ // Set the time of today to 00:00:00 for comparison purposes
347
+ today.setHours(0, 0, 0, 0);
348
+ // Normalize the input date to 00:00:00
349
+ const inputDate = new Date(this.#date);
350
+ inputDate.setHours(0, 0, 0, 0);
351
+ const diffTime = inputDate.getTime() - today.getTime();
352
+ const diffDays = Math.floor(diffTime / (1000 * 60 * 60 * 24));
353
+ return diffDays;
354
+ }
355
+ /** * Returns the number of full hours between the input date and now. */
356
+ getRelativeHour() {
357
+ const diff = new Date().getTime() - this.#date.getTime();
358
+ return Math.floor(diff / (1000 * 60 * 60));
359
+ }
360
+ /** * Returns the number of full minutes between the input date and now. */
361
+ getRelativeMinute() {
362
+ const diff = new Date().getTime() - this.#date.getTime();
363
+ return Math.floor(diff / (1000 * 60));
364
+ }
365
+ /** * Returns the number of full seconds between the input date and now. */
366
+ getRelativeSecond() {
367
+ const diff = new Date().getTime() - this.#date.getTime();
368
+ return Math.floor(diff / 1000);
369
+ }
370
+ /** * Returns the number of milliseconds between the input date and now. */
371
+ getRelativeMilliSecond() {
372
+ return new Date().getTime() - this.#date.getTime();
373
+ }
374
+ /**
375
+ * * Compares the stored date with now, returning the difference in the specified unit.
376
+ * @param unit The time unit to compare by. Defaults to 'minute'.
377
+ */
378
+ compare(unit = 'minute') {
379
+ switch (unit) {
380
+ case 'year':
381
+ return this.getRelativeYear();
382
+ case 'month':
383
+ return this.getRelativeMonth();
384
+ case 'day':
385
+ return this.getRelativeDay();
386
+ case 'hour':
387
+ return this.getRelativeHour();
388
+ case 'minute':
389
+ return this.getRelativeMinute();
390
+ case 'second':
391
+ return this.getRelativeSecond();
392
+ case 'millisecond':
393
+ return this.getRelativeMilliSecond();
394
+ default:
395
+ throw new Error(`Unsupported time unit: ${unit}`);
396
+ }
397
+ }
260
398
  }
@@ -36,7 +36,7 @@ export interface GreetingConfigs {
36
36
  /** Default greeting message if no period matches. */
37
37
  defaultMessage?: string;
38
38
  }
39
- export type FormatType = 'year' | 'month' | 'day' | 'date' | 'hour' | 'minute' | 'second' | 'millisecond';
39
+ export type TimeUnit = 'year' | 'month' | 'day' | 'hour' | 'minute' | 'second' | 'millisecond';
40
40
  export type Year = (typeof YEAR_FORMATS)[number];
41
41
  export type Month = (typeof MONTH_FORMATS)[number];
42
42
  export type Day = (typeof DAY_FORMATS)[number];
@@ -49,7 +49,7 @@ export type TimeFormats = (typeof TIME_FORMATS)[number];
49
49
  export type ChronosFormat = Year | Month | Day | Date | Hour | Minute | Second | Millisecond | TimeFormats;
50
50
  export type TimeZone = keyof typeof TIME_ZONES;
51
51
  export type PositiveUTCHour = '+00' | '+01' | '+02' | '+03' | '+04' | '+05' | '+06' | '+07' | '+08' | '+09' | '+10' | '+11' | '+12' | '+13' | '+14';
52
- export type NegativeUTCHour = '-01' | '-02' | '-03' | '-04' | '-05' | '-06' | '-07' | '-08' | '-09' | '-10' | '-11' | '-12';
52
+ export type NegativeUTCHour = '-00' | '-01' | '-02' | '-03' | '-04' | '-05' | '-06' | '-07' | '-08' | '-09' | '-10' | '-11' | '-12' | '-13' | '-14';
53
53
  export type UTCMinute = '00' | '15' | '30' | '45';
54
54
  export type UTCOffSet = `UTC${PositiveUTCHour | NegativeUTCHour}:${UTCMinute}`;
55
55
  /** * Format options */
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/date/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,YAAY,EACZ,WAAW,EACX,YAAY,EACZ,mBAAmB,EACnB,cAAc,EACd,aAAa,EACb,cAAc,EACd,YAAY,EACZ,UAAU,EACV,YAAY,EACZ,MAAM,aAAa,CAAC;AAErB,mDAAmD;AACnD,MAAM,MAAM,KAAK,GACd,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,CAAC;AAER,mDAAmD;AACnD,MAAM,MAAM,OAAO,GAChB,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,I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MAAM,eAAe,GACxB,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,CAAC;AAET,MAAM,MAAM,eAAe,GACxB,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,GACL,KAAK,CAAC;AAET,MAAM,MAAM,SAAS,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;AAElD,MAAM,MAAM,SAAS,GAAG,MAAM,eAAe,GAAG,eAAe,IAAI,SAAS,EAAE,CAAC;AAE/E,uBAAuB;AACvB,MAAM,WAAW,aAAa;IAC7B,+GAA+G;IAC/G,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,sDAAsD;IACtD,MAAM,CAAC,EAAE,OAAO,CAAC;CACjB"}
@@ -1,19 +1,19 @@
1
1
  import { Chronos } from './Chronos';
2
2
  import type { Time, UTCOffSet } from './types';
3
3
  /**
4
- * * Extracts the hour and minute from a time string in `HH:MM` format.
4
+ * * Extracts the hour and minute from a time string in `HH:MM` or `-HH:MM` format.
5
5
  *
6
6
  * @param time - The time string to extract from.
7
7
  * @return The extracted hour and minute as number tuple.
8
8
  */
9
- export declare function extractHourMinute(time: Time): [number, number];
9
+ export declare function extractHourMinute(time: `-${Time}` | Time): [number, number];
10
10
  /**
11
- * * Converts a time string `HH:MM` into total minutes from `00:00`.
11
+ * * Converts a time string `HH:MM` or `-HH:MM` into total minutes from `00:00`.
12
12
  *
13
- * @param time - The time in `HH:MM` format.
13
+ * @param time - The time in `HH:MM` or `-HH:MM` format.
14
14
  * @returns The total minutes elapsed since `00:00`.
15
15
  */
16
- export declare function getTotalMinutes(time: Time): number;
16
+ export declare function getTotalMinutes(time: `-${Time}` | Time): number;
17
17
  /**
18
18
  * * Returns the current date and time as `Date` object.
19
19
  * - All the methods and properties of `new Date()` are accessible.
@@ -38,7 +38,7 @@ export declare function chronos(date?: number | string | Date | Chronos): Chrono
38
38
  * @param utc UTC value in `UTC-01:30` or `UTC+01:30` format.
39
39
  * @returns The UTC value in `HH:MM` format.
40
40
  */
41
- export declare function extractTimeFromUTC(utc: UTCOffSet): Time;
41
+ export declare function extractTimeFromUTC(utc: UTCOffSet): `-${Time}` | Time;
42
42
  /**
43
43
  * * Converts a UTC value in `UTC-01:30` or `UTC+01:30` format into total minutes in number.
44
44
  *
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/date/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAE/C;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,IAAI,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAI9D;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAIlD;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,IAAI,IAAI,CAEzC;AAED;;;;;;;;;GASG;AACH,wBAAgB,OAAO,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,OAAO,WAE9D;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,SAAS,GAAG,IAAI,CAEvD;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,SAAS,GAAG,MAAM,CAE5D"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/date/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAE/C;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,IAAI,IAAI,EAAE,GAAG,IAAI,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAI3E;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,IAAI,IAAI,EAAE,GAAG,IAAI,GAAG,MAAM,CAU/D;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,IAAI,IAAI,CAEzC;AAED;;;;;;;;;GASG;AACH,wBAAgB,OAAO,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,OAAO,WAE9D;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,SAAS,GAAG,IAAI,IAAI,EAAE,GAAG,IAAI,CAEpE;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,SAAS,GAAG,MAAM,CAE5D"}
@@ -1,6 +1,6 @@
1
1
  import { Chronos } from './Chronos';
2
2
  /**
3
- * * Extracts the hour and minute from a time string in `HH:MM` format.
3
+ * * Extracts the hour and minute from a time string in `HH:MM` or `-HH:MM` format.
4
4
  *
5
5
  * @param time - The time string to extract from.
6
6
  * @return The extracted hour and minute as number tuple.
@@ -10,14 +10,16 @@ export function extractHourMinute(time) {
10
10
  return [hour, minute];
11
11
  }
12
12
  /**
13
- * * Converts a time string `HH:MM` into total minutes from `00:00`.
13
+ * * Converts a time string `HH:MM` or `-HH:MM` into total minutes from `00:00`.
14
14
  *
15
- * @param time - The time in `HH:MM` format.
15
+ * @param time - The time in `HH:MM` or `-HH:MM` format.
16
16
  * @returns The total minutes elapsed since `00:00`.
17
17
  */
18
18
  export function getTotalMinutes(time) {
19
- const [h, m] = extractHourMinute(time);
20
- return h * 60 + m;
19
+ const isNegative = time.startsWith('-');
20
+ const [h, m] = extractHourMinute(isNegative ? time.slice(1) : time);
21
+ const total = h * 60 + m;
22
+ return isNegative ? -total : total;
21
23
  }
22
24
  /**
23
25
  * * Returns the current date and time as `Date` object.
@@ -48,7 +50,7 @@ export function chronos(date) {
48
50
  * @returns The UTC value in `HH:MM` format.
49
51
  */
50
52
  export function extractTimeFromUTC(utc) {
51
- return utc.replace(/^UTC[+-]?/g, '');
53
+ return utc.replace(/^UTC[+]?/g, '');
52
54
  }
53
55
  /**
54
56
  * * Converts a UTC value in `UTC-01:30` or `UTC+01:30` format into total minutes in number.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nhb-toolbox",
3
- "version": "3.5.20",
3
+ "version": "3.6.0",
4
4
  "description": "A versatile collection of smart, efficient, and reusable utility functions for everyday development needs.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",