nhb-toolbox 3.4.1 → 3.4.2

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,10 +1,20 @@
1
1
  export declare class Chronos {
2
- private readonly _date;
2
+ private readonly date;
3
3
  /**
4
4
  * * Creates a new immutable Chronos instance.
5
- * @param value - A date value (`timestamp`, `string`, or `Date`).
5
+ * @param value - A date value (`timestamp`, `string`, `Date`, `Chronos`).
6
6
  */
7
7
  constructor(value?: number | string | Date | Chronos);
8
+ /** * Gets the native `Date` instance (read-only). */
9
+ toDate(): Date;
10
+ /** * Returns a string representation of a date. The format of the string depends on the locale. */
11
+ toString(): string;
12
+ /** * Returns a date as a string value in ISO format. */
13
+ toISOString(): string;
14
+ /** * Returns the time value in milliseconds since midnight, January 1, 1970 UTC. */
15
+ getTimeStamp(): number;
16
+ /** * Returns the number of milliseconds elapsed since midnight, January 1, 1970 Universal Coordinated Time (UTC). */
17
+ static now(): number;
8
18
  /**
9
19
  * * Formats the date into a custom string format.
10
20
  * @param format - The desired format (Default format is `DD-MM-YYYY` = `30-06-1995`).
@@ -33,7 +43,12 @@ export declare class Chronos {
33
43
  * - Other positive or negative numbers for other relative days (e.g., `-2` for two days ago, `2` for two days ahead).
34
44
  */
35
45
  getRelativeDay(): number;
36
- /** * Gets the native `Date` instance (read-only). */
37
- toDate(): Date;
46
+ /**
47
+ * * Checks if the year is a leap year.
48
+ * - A year is a leap year if it is divisible by 4, but not divisible by 100, unless it is also divisible by 400.
49
+ * - For example, 2000 and 2400 are leap years, but 1900 and 2100 are not.
50
+ * @returns `true` if the year is a leap year, `false` otherwise.
51
+ */
52
+ isLeapYear(): boolean;
38
53
  }
39
54
  //# sourceMappingURL=Chronos.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Chronos.d.ts","sourceRoot":"","sources":["../../src/date/Chronos.ts"],"names":[],"mappings":"AAGA,qBAAa,OAAO;IACnB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAO;IAE7B;;;OAGG;gBACS,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,OAAO;IAcpD;;;;OAIG;IACH,MAAM,CAAC,MAAM,GAAE,MAAqB,GAAG,MAAM;IA2E7C;;;;OAIG;IACH,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAM9B;;;;OAIG;IACH,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAInC;;;;;;;;OAQG;IACH,cAAc,IAAI,MAAM;IAexB,qDAAqD;IACrD,MAAM,IAAI,IAAI;CAGd"}
1
+ {"version":3,"file":"Chronos.d.ts","sourceRoot":"","sources":["../../src/date/Chronos.ts"],"names":[],"mappings":"AAGA,qBAAa,OAAO;IACnB,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAO;IAE5B;;;OAGG;gBACS,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,OAAO;IAcpD,qDAAqD;IACrD,MAAM,IAAI,IAAI;IAId,mGAAmG;IACnG,QAAQ,IAAI,MAAM;IAIlB,wDAAwD;IACxD,WAAW,IAAI,MAAM;IAIrB,oFAAoF;IACpF,YAAY,IAAI,MAAM;IAItB,qHAAqH;IACrH,MAAM,CAAC,GAAG,IAAI,MAAM;IAIpB;;;;OAIG;IACH,MAAM,CAAC,MAAM,GAAE,MAAqB,GAAG,MAAM;IA2E7C;;;;OAIG;IACH,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAM9B;;;;OAIG;IACH,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAInC;;;;;;;;OAQG;IACH,cAAc,IAAI,MAAM;IAexB;;;;;OAKG;IACH,UAAU,IAAI,OAAO;CAKrB"}
@@ -1,9 +1,9 @@
1
1
  import { DAYS, MONTHS, sortedFormats } from './constants';
2
2
  export class Chronos {
3
- _date;
3
+ date;
4
4
  /**
5
5
  * * Creates a new immutable Chronos instance.
6
- * @param value - A date value (`timestamp`, `string`, or `Date`).
6
+ * @param value - A date value (`timestamp`, `string`, `Date`, `Chronos`).
7
7
  */
8
8
  constructor(value) {
9
9
  const date = value instanceof Chronos ?
@@ -13,7 +13,27 @@ export class Chronos {
13
13
  if (isNaN(date.getTime())) {
14
14
  throw new Error('Invalid date provided!');
15
15
  }
16
- this._date = date;
16
+ this.date = date;
17
+ }
18
+ /** * Gets the native `Date` instance (read-only). */
19
+ toDate() {
20
+ return new Date(this.date);
21
+ }
22
+ /** * Returns a string representation of a date. The format of the string depends on the locale. */
23
+ toString() {
24
+ return this.date.toString();
25
+ }
26
+ /** * Returns a date as a string value in ISO format. */
27
+ toISOString() {
28
+ return this.date.toISOString();
29
+ }
30
+ /** * Returns the time value in milliseconds since midnight, January 1, 1970 UTC. */
31
+ getTimeStamp() {
32
+ return this.date.getTime();
33
+ }
34
+ /** * Returns the number of milliseconds elapsed since midnight, January 1, 1970 Universal Coordinated Time (UTC). */
35
+ static now() {
36
+ return Date.now();
17
37
  }
18
38
  /**
19
39
  * * Formats the date into a custom string format.
@@ -21,14 +41,14 @@ export class Chronos {
21
41
  * @returns Formatted date string in desired format.
22
42
  */
23
43
  format(format = 'DD-MM-YYYY') {
24
- const year = this._date.getFullYear();
25
- const month = this._date.getMonth();
26
- const day = this._date.getDay();
27
- const date = this._date.getDate();
28
- const hours = this._date.getHours();
29
- const minutes = this._date.getMinutes();
30
- const seconds = this._date.getSeconds();
31
- const milliseconds = this._date.getMilliseconds();
44
+ const year = this.date.getFullYear();
45
+ const month = this.date.getMonth();
46
+ const day = this.date.getDay();
47
+ const date = this.date.getDate();
48
+ const hours = this.date.getHours();
49
+ const minutes = this.date.getMinutes();
50
+ const seconds = this.date.getSeconds();
51
+ const milliseconds = this.date.getMilliseconds();
32
52
  const dateComponents = {
33
53
  YYYY: String(year),
34
54
  YY: String(year).slice(-2),
@@ -91,7 +111,7 @@ export class Chronos {
91
111
  * @returns A new `Chronos` instance with the updated date.
92
112
  */
93
113
  addDays(days) {
94
- const newDate = new Date(this._date);
114
+ const newDate = new Date(this.date);
95
115
  newDate.setDate(newDate.getDate() + days);
96
116
  return new Chronos(newDate);
97
117
  }
@@ -117,14 +137,20 @@ export class Chronos {
117
137
  // Set the time of today to 00:00:00 for comparison purposes
118
138
  today.setHours(0, 0, 0, 0);
119
139
  // Normalize the input date to 00:00:00
120
- const inputDate = new Date(this._date);
140
+ const inputDate = new Date(this.date);
121
141
  inputDate.setHours(0, 0, 0, 0);
122
142
  const diffTime = inputDate.getTime() - today.getTime();
123
143
  const diffDays = Math.floor(diffTime / (1000 * 60 * 60 * 24));
124
144
  return diffDays;
125
145
  }
126
- /** * Gets the native `Date` instance (read-only). */
127
- toDate() {
128
- return new Date(this._date);
146
+ /**
147
+ * * Checks if the year is a leap year.
148
+ * - A year is a leap year if it is divisible by 4, but not divisible by 100, unless it is also divisible by 400.
149
+ * - For example, 2000 and 2400 are leap years, but 1900 and 2100 are not.
150
+ * @returns `true` if the year is a leap year, `false` otherwise.
151
+ */
152
+ isLeapYear() {
153
+ const year = this.date.getFullYear();
154
+ return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;
129
155
  }
130
156
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nhb-toolbox",
3
- "version": "3.4.1",
3
+ "version": "3.4.2",
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",