@magicyan/core
Advanced tools
| 'use strict'; | ||
| class DatePlus extends Date { | ||
| /** | ||
| * Creates a new `DatePlus` instance. | ||
| * @param date Initial date. Can be a `string`, `number` (timestamp), or `Date`. Defaults to the current date/time. | ||
| * | ||
| * @example | ||
| * const d1 = new DatePlus(); // now | ||
| * @example | ||
| * const d2 = new DatePlus("2025-01-01"); // specific date | ||
| */ | ||
| constructor(date) { | ||
| super(date ?? Date.now()); | ||
| } | ||
| /** | ||
| * Adds a value to a specific unit of the date. | ||
| * @param unit Time unit to add to (`days`, `hours`, `minutes`, `seconds`, `milliseconds`, `months`, `years`). | ||
| * @param value Amount to add (can be negative or fractional, e.g., 1.5 days). | ||
| * @returns The same `DatePlus` instance (supports method chaining). | ||
| * | ||
| * @example | ||
| * const d = new DatePlus("2025-01-01"); | ||
| * d.add("days", 5); // adds 5 days | ||
| * @example | ||
| * d.add("hours", 12); // adds 12 hours | ||
| */ | ||
| add(unit, value) { | ||
| switch (unit) { | ||
| case "days": | ||
| this.setDate(this.getDate() + value); | ||
| break; | ||
| case "hours": | ||
| this.setHours(this.getHours() + value); | ||
| break; | ||
| case "minutes": | ||
| this.setMinutes(this.getMinutes() + value); | ||
| break; | ||
| case "seconds": | ||
| this.setSeconds(this.getSeconds() + value); | ||
| break; | ||
| case "milliseconds": | ||
| this.setMilliseconds(this.getMilliseconds() + value); | ||
| break; | ||
| case "months": | ||
| this.setMonth(this.getMonth() + value); | ||
| break; | ||
| case "years": | ||
| this.setFullYear(this.getFullYear() + value); | ||
| break; | ||
| } | ||
| return this; | ||
| } | ||
| /** | ||
| * Subtracts a value from a specific unit of the date. | ||
| * @param unit Time unit to subtract from (`days`, `hours`, `minutes`, `seconds`, `milliseconds`, `months`, `years`). | ||
| * @param value Amount to subtract. | ||
| * @returns The same `DatePlus` instance (supports method chaining). | ||
| * | ||
| * @example | ||
| * const d = new DatePlus("2025-01-10"); | ||
| * d.sub("days", 3); // subtracts 3 days | ||
| * @example | ||
| * d.sub("hours", 5); // subtracts 5 hours | ||
| */ | ||
| sub(unit, value) { | ||
| return this.add(unit, -value); | ||
| } | ||
| /** | ||
| * Sets a specific unit of the date to an absolute value. | ||
| * @param unit Time unit to set (`days`, `hours`, `minutes`, `seconds`, `milliseconds`, `months`, `years`). | ||
| * @param value New value for the specified unit. | ||
| * @returns The same `DatePlus` instance (supports method chaining). | ||
| * | ||
| * @example | ||
| * const d = new DatePlus("2025-01-01"); | ||
| * d.set("hours", 15); // sets the hour to 15 | ||
| * @example | ||
| * d.set("days", 10); // sets the day of the month to 10 | ||
| */ | ||
| set(unit, value) { | ||
| switch (unit) { | ||
| case "days": | ||
| this.setDate(value); | ||
| break; | ||
| case "hours": | ||
| this.setHours(value); | ||
| break; | ||
| case "minutes": | ||
| this.setMinutes(value); | ||
| break; | ||
| case "seconds": | ||
| this.setSeconds(value); | ||
| break; | ||
| case "milliseconds": | ||
| this.setMilliseconds(value); | ||
| break; | ||
| case "months": | ||
| this.setMonth(value); | ||
| break; | ||
| case "years": | ||
| this.setFullYear(value); | ||
| break; | ||
| } | ||
| return this; | ||
| } | ||
| /** | ||
| * Creates a clone of the current `DatePlus` instance. | ||
| * @returns A new `DatePlus` instance with the same date/time. | ||
| * | ||
| * @example | ||
| * const d1 = new DatePlus("2025-01-01"); | ||
| * const d2 = d1.clone(); | ||
| * @example | ||
| * d2.add("days", 5); // d1 remains unchanged | ||
| */ | ||
| clone() { | ||
| return new DatePlus(this.getTime()); | ||
| } | ||
| /** | ||
| * Calculates the difference between this date and another date. | ||
| * @param other The other `Date` or `DatePlus` instance to compare against. | ||
| * @param unit Unit to return the difference in (`milliseconds` by default). | ||
| * @returns The difference between the two dates in the specified unit. | ||
| * | ||
| * @example | ||
| * const d1 = new DatePlus("2025-01-01"); | ||
| * const d2 = new DatePlus("2025-01-10"); | ||
| * console.log(d2.diff(d1, "days")); // 9 | ||
| * @example | ||
| * console.log(d2.diff(d1, "milliseconds")); // 777600000 | ||
| */ | ||
| diff(other, unit = "milliseconds") { | ||
| const msDiff = this.getTime() - other.getTime(); | ||
| switch (unit) { | ||
| case "milliseconds": | ||
| return msDiff; | ||
| case "seconds": | ||
| return msDiff / 1e3; | ||
| case "minutes": | ||
| return msDiff / (1e3 * 60); | ||
| case "hours": | ||
| return msDiff / (1e3 * 60 * 60); | ||
| case "days": | ||
| return msDiff / (1e3 * 60 * 60 * 24); | ||
| case "months": { | ||
| const years = this.getFullYear() - other.getFullYear(); | ||
| const months = this.getMonth() - other.getMonth(); | ||
| return years * 12 + months; | ||
| } | ||
| case "years": | ||
| return this.getFullYear() - other.getFullYear(); | ||
| } | ||
| } | ||
| } | ||
| function createDate(date) { | ||
| return new DatePlus(date); | ||
| } | ||
| exports.DatePlus = DatePlus; | ||
| exports.createDate = createDate; |
| class DatePlus extends Date { | ||
| /** | ||
| * Creates a new `DatePlus` instance. | ||
| * @param date Initial date. Can be a `string`, `number` (timestamp), or `Date`. Defaults to the current date/time. | ||
| * | ||
| * @example | ||
| * const d1 = new DatePlus(); // now | ||
| * @example | ||
| * const d2 = new DatePlus("2025-01-01"); // specific date | ||
| */ | ||
| constructor(date) { | ||
| super(date ?? Date.now()); | ||
| } | ||
| /** | ||
| * Adds a value to a specific unit of the date. | ||
| * @param unit Time unit to add to (`days`, `hours`, `minutes`, `seconds`, `milliseconds`, `months`, `years`). | ||
| * @param value Amount to add (can be negative or fractional, e.g., 1.5 days). | ||
| * @returns The same `DatePlus` instance (supports method chaining). | ||
| * | ||
| * @example | ||
| * const d = new DatePlus("2025-01-01"); | ||
| * d.add("days", 5); // adds 5 days | ||
| * @example | ||
| * d.add("hours", 12); // adds 12 hours | ||
| */ | ||
| add(unit, value) { | ||
| switch (unit) { | ||
| case "days": | ||
| this.setDate(this.getDate() + value); | ||
| break; | ||
| case "hours": | ||
| this.setHours(this.getHours() + value); | ||
| break; | ||
| case "minutes": | ||
| this.setMinutes(this.getMinutes() + value); | ||
| break; | ||
| case "seconds": | ||
| this.setSeconds(this.getSeconds() + value); | ||
| break; | ||
| case "milliseconds": | ||
| this.setMilliseconds(this.getMilliseconds() + value); | ||
| break; | ||
| case "months": | ||
| this.setMonth(this.getMonth() + value); | ||
| break; | ||
| case "years": | ||
| this.setFullYear(this.getFullYear() + value); | ||
| break; | ||
| } | ||
| return this; | ||
| } | ||
| /** | ||
| * Subtracts a value from a specific unit of the date. | ||
| * @param unit Time unit to subtract from (`days`, `hours`, `minutes`, `seconds`, `milliseconds`, `months`, `years`). | ||
| * @param value Amount to subtract. | ||
| * @returns The same `DatePlus` instance (supports method chaining). | ||
| * | ||
| * @example | ||
| * const d = new DatePlus("2025-01-10"); | ||
| * d.sub("days", 3); // subtracts 3 days | ||
| * @example | ||
| * d.sub("hours", 5); // subtracts 5 hours | ||
| */ | ||
| sub(unit, value) { | ||
| return this.add(unit, -value); | ||
| } | ||
| /** | ||
| * Sets a specific unit of the date to an absolute value. | ||
| * @param unit Time unit to set (`days`, `hours`, `minutes`, `seconds`, `milliseconds`, `months`, `years`). | ||
| * @param value New value for the specified unit. | ||
| * @returns The same `DatePlus` instance (supports method chaining). | ||
| * | ||
| * @example | ||
| * const d = new DatePlus("2025-01-01"); | ||
| * d.set("hours", 15); // sets the hour to 15 | ||
| * @example | ||
| * d.set("days", 10); // sets the day of the month to 10 | ||
| */ | ||
| set(unit, value) { | ||
| switch (unit) { | ||
| case "days": | ||
| this.setDate(value); | ||
| break; | ||
| case "hours": | ||
| this.setHours(value); | ||
| break; | ||
| case "minutes": | ||
| this.setMinutes(value); | ||
| break; | ||
| case "seconds": | ||
| this.setSeconds(value); | ||
| break; | ||
| case "milliseconds": | ||
| this.setMilliseconds(value); | ||
| break; | ||
| case "months": | ||
| this.setMonth(value); | ||
| break; | ||
| case "years": | ||
| this.setFullYear(value); | ||
| break; | ||
| } | ||
| return this; | ||
| } | ||
| /** | ||
| * Creates a clone of the current `DatePlus` instance. | ||
| * @returns A new `DatePlus` instance with the same date/time. | ||
| * | ||
| * @example | ||
| * const d1 = new DatePlus("2025-01-01"); | ||
| * const d2 = d1.clone(); | ||
| * @example | ||
| * d2.add("days", 5); // d1 remains unchanged | ||
| */ | ||
| clone() { | ||
| return new DatePlus(this.getTime()); | ||
| } | ||
| /** | ||
| * Calculates the difference between this date and another date. | ||
| * @param other The other `Date` or `DatePlus` instance to compare against. | ||
| * @param unit Unit to return the difference in (`milliseconds` by default). | ||
| * @returns The difference between the two dates in the specified unit. | ||
| * | ||
| * @example | ||
| * const d1 = new DatePlus("2025-01-01"); | ||
| * const d2 = new DatePlus("2025-01-10"); | ||
| * console.log(d2.diff(d1, "days")); // 9 | ||
| * @example | ||
| * console.log(d2.diff(d1, "milliseconds")); // 777600000 | ||
| */ | ||
| diff(other, unit = "milliseconds") { | ||
| const msDiff = this.getTime() - other.getTime(); | ||
| switch (unit) { | ||
| case "milliseconds": | ||
| return msDiff; | ||
| case "seconds": | ||
| return msDiff / 1e3; | ||
| case "minutes": | ||
| return msDiff / (1e3 * 60); | ||
| case "hours": | ||
| return msDiff / (1e3 * 60 * 60); | ||
| case "days": | ||
| return msDiff / (1e3 * 60 * 60 * 24); | ||
| case "months": { | ||
| const years = this.getFullYear() - other.getFullYear(); | ||
| const months = this.getMonth() - other.getMonth(); | ||
| return years * 12 + months; | ||
| } | ||
| case "years": | ||
| return this.getFullYear() - other.getFullYear(); | ||
| } | ||
| } | ||
| } | ||
| function createDate(date) { | ||
| return new DatePlus(date); | ||
| } | ||
| export { DatePlus, createDate }; |
+3
-0
@@ -11,2 +11,3 @@ 'use strict'; | ||
| const _with = require('./functions/with.cjs'); | ||
| const date = require('./functions/date.cjs'); | ||
@@ -41,1 +42,3 @@ | ||
| exports.withTimeout = _with.withTimeout; | ||
| exports.DatePlus = date.DatePlus; | ||
| exports.createDate = date.createDate; |
+91
-9
@@ -253,9 +253,2 @@ /** | ||
| type Sleep = SetTimeoutFunction & SleepTimes; | ||
| /** | ||
| * ```ts | ||
| * await sleep(100); // wait 100 ms | ||
| * await sleep.seconds(5); // wait 5000 ms | ||
| * await sleep.minutes(2); // wait 120000 ms | ||
| * ``` | ||
| */ | ||
| declare const sleep: Sleep; | ||
@@ -383,3 +376,92 @@ interface CreateIntervalOptions { | ||
| export { brBuilder, capitalize, createInterval, createLoopInterval, createTimeout, equalsIgnoreCase, hexToRgb, includesIgnoreCase, isDefined, isEmail, isNumeric, isPromise, isUrl, limitText, notFound, parseFloatOrDefault, parseIntOrDefault, random, randomNumber, replaceText, rgbToHex, sleep, spaceBuilder, toMs, withProperties, withTimeout }; | ||
| export type { CanBeString, MaybeString }; | ||
| type DateUnit = "days" | "hours" | "minutes" | "seconds" | "milliseconds" | "months" | "years"; | ||
| declare class DatePlus extends Date { | ||
| /** | ||
| * Creates a new `DatePlus` instance. | ||
| * @param date Initial date. Can be a `string`, `number` (timestamp), or `Date`. Defaults to the current date/time. | ||
| * | ||
| * @example | ||
| * const d1 = new DatePlus(); // now | ||
| * @example | ||
| * const d2 = new DatePlus("2025-01-01"); // specific date | ||
| */ | ||
| constructor(date?: string | number | Date); | ||
| /** | ||
| * Adds a value to a specific unit of the date. | ||
| * @param unit Time unit to add to (`days`, `hours`, `minutes`, `seconds`, `milliseconds`, `months`, `years`). | ||
| * @param value Amount to add (can be negative or fractional, e.g., 1.5 days). | ||
| * @returns The same `DatePlus` instance (supports method chaining). | ||
| * | ||
| * @example | ||
| * const d = new DatePlus("2025-01-01"); | ||
| * d.add("days", 5); // adds 5 days | ||
| * @example | ||
| * d.add("hours", 12); // adds 12 hours | ||
| */ | ||
| add(unit: DateUnit, value: number): this; | ||
| /** | ||
| * Subtracts a value from a specific unit of the date. | ||
| * @param unit Time unit to subtract from (`days`, `hours`, `minutes`, `seconds`, `milliseconds`, `months`, `years`). | ||
| * @param value Amount to subtract. | ||
| * @returns The same `DatePlus` instance (supports method chaining). | ||
| * | ||
| * @example | ||
| * const d = new DatePlus("2025-01-10"); | ||
| * d.sub("days", 3); // subtracts 3 days | ||
| * @example | ||
| * d.sub("hours", 5); // subtracts 5 hours | ||
| */ | ||
| sub(unit: DateUnit, value: number): this; | ||
| /** | ||
| * Sets a specific unit of the date to an absolute value. | ||
| * @param unit Time unit to set (`days`, `hours`, `minutes`, `seconds`, `milliseconds`, `months`, `years`). | ||
| * @param value New value for the specified unit. | ||
| * @returns The same `DatePlus` instance (supports method chaining). | ||
| * | ||
| * @example | ||
| * const d = new DatePlus("2025-01-01"); | ||
| * d.set("hours", 15); // sets the hour to 15 | ||
| * @example | ||
| * d.set("days", 10); // sets the day of the month to 10 | ||
| */ | ||
| set(unit: DateUnit, value: number): this; | ||
| /** | ||
| * Creates a clone of the current `DatePlus` instance. | ||
| * @returns A new `DatePlus` instance with the same date/time. | ||
| * | ||
| * @example | ||
| * const d1 = new DatePlus("2025-01-01"); | ||
| * const d2 = d1.clone(); | ||
| * @example | ||
| * d2.add("days", 5); // d1 remains unchanged | ||
| */ | ||
| clone(): DatePlus; | ||
| /** | ||
| * Calculates the difference between this date and another date. | ||
| * @param other The other `Date` or `DatePlus` instance to compare against. | ||
| * @param unit Unit to return the difference in (`milliseconds` by default). | ||
| * @returns The difference between the two dates in the specified unit. | ||
| * | ||
| * @example | ||
| * const d1 = new DatePlus("2025-01-01"); | ||
| * const d2 = new DatePlus("2025-01-10"); | ||
| * console.log(d2.diff(d1, "days")); // 9 | ||
| * @example | ||
| * console.log(d2.diff(d1, "milliseconds")); // 777600000 | ||
| */ | ||
| diff(other: Date | DatePlus, unit?: DateUnit): number; | ||
| } | ||
| /** | ||
| * Helper function to create a `DatePlus` instance. | ||
| * @param date Optional initial date (`string`, `number`, or `Date`). Defaults to current date/time. | ||
| * @returns A new `DatePlus` instance. | ||
| * | ||
| * @example | ||
| * const d = createDate("2025-01-01"); | ||
| * @example | ||
| * const now = createDate(); // current date/time | ||
| */ | ||
| declare function createDate(date?: string | number | Date): DatePlus; | ||
| export { DatePlus, brBuilder, capitalize, createDate, createInterval, createLoopInterval, createTimeout, equalsIgnoreCase, hexToRgb, includesIgnoreCase, isDefined, isEmail, isNumeric, isPromise, isUrl, limitText, notFound, parseFloatOrDefault, parseIntOrDefault, random, randomNumber, replaceText, rgbToHex, sleep, spaceBuilder, toMs, withProperties, withTimeout }; | ||
| export type { CanBeString, DateUnit, MaybeString }; |
+91
-9
@@ -253,9 +253,2 @@ /** | ||
| type Sleep = SetTimeoutFunction & SleepTimes; | ||
| /** | ||
| * ```ts | ||
| * await sleep(100); // wait 100 ms | ||
| * await sleep.seconds(5); // wait 5000 ms | ||
| * await sleep.minutes(2); // wait 120000 ms | ||
| * ``` | ||
| */ | ||
| declare const sleep: Sleep; | ||
@@ -383,3 +376,92 @@ interface CreateIntervalOptions { | ||
| export { brBuilder, capitalize, createInterval, createLoopInterval, createTimeout, equalsIgnoreCase, hexToRgb, includesIgnoreCase, isDefined, isEmail, isNumeric, isPromise, isUrl, limitText, notFound, parseFloatOrDefault, parseIntOrDefault, random, randomNumber, replaceText, rgbToHex, sleep, spaceBuilder, toMs, withProperties, withTimeout }; | ||
| export type { CanBeString, MaybeString }; | ||
| type DateUnit = "days" | "hours" | "minutes" | "seconds" | "milliseconds" | "months" | "years"; | ||
| declare class DatePlus extends Date { | ||
| /** | ||
| * Creates a new `DatePlus` instance. | ||
| * @param date Initial date. Can be a `string`, `number` (timestamp), or `Date`. Defaults to the current date/time. | ||
| * | ||
| * @example | ||
| * const d1 = new DatePlus(); // now | ||
| * @example | ||
| * const d2 = new DatePlus("2025-01-01"); // specific date | ||
| */ | ||
| constructor(date?: string | number | Date); | ||
| /** | ||
| * Adds a value to a specific unit of the date. | ||
| * @param unit Time unit to add to (`days`, `hours`, `minutes`, `seconds`, `milliseconds`, `months`, `years`). | ||
| * @param value Amount to add (can be negative or fractional, e.g., 1.5 days). | ||
| * @returns The same `DatePlus` instance (supports method chaining). | ||
| * | ||
| * @example | ||
| * const d = new DatePlus("2025-01-01"); | ||
| * d.add("days", 5); // adds 5 days | ||
| * @example | ||
| * d.add("hours", 12); // adds 12 hours | ||
| */ | ||
| add(unit: DateUnit, value: number): this; | ||
| /** | ||
| * Subtracts a value from a specific unit of the date. | ||
| * @param unit Time unit to subtract from (`days`, `hours`, `minutes`, `seconds`, `milliseconds`, `months`, `years`). | ||
| * @param value Amount to subtract. | ||
| * @returns The same `DatePlus` instance (supports method chaining). | ||
| * | ||
| * @example | ||
| * const d = new DatePlus("2025-01-10"); | ||
| * d.sub("days", 3); // subtracts 3 days | ||
| * @example | ||
| * d.sub("hours", 5); // subtracts 5 hours | ||
| */ | ||
| sub(unit: DateUnit, value: number): this; | ||
| /** | ||
| * Sets a specific unit of the date to an absolute value. | ||
| * @param unit Time unit to set (`days`, `hours`, `minutes`, `seconds`, `milliseconds`, `months`, `years`). | ||
| * @param value New value for the specified unit. | ||
| * @returns The same `DatePlus` instance (supports method chaining). | ||
| * | ||
| * @example | ||
| * const d = new DatePlus("2025-01-01"); | ||
| * d.set("hours", 15); // sets the hour to 15 | ||
| * @example | ||
| * d.set("days", 10); // sets the day of the month to 10 | ||
| */ | ||
| set(unit: DateUnit, value: number): this; | ||
| /** | ||
| * Creates a clone of the current `DatePlus` instance. | ||
| * @returns A new `DatePlus` instance with the same date/time. | ||
| * | ||
| * @example | ||
| * const d1 = new DatePlus("2025-01-01"); | ||
| * const d2 = d1.clone(); | ||
| * @example | ||
| * d2.add("days", 5); // d1 remains unchanged | ||
| */ | ||
| clone(): DatePlus; | ||
| /** | ||
| * Calculates the difference between this date and another date. | ||
| * @param other The other `Date` or `DatePlus` instance to compare against. | ||
| * @param unit Unit to return the difference in (`milliseconds` by default). | ||
| * @returns The difference between the two dates in the specified unit. | ||
| * | ||
| * @example | ||
| * const d1 = new DatePlus("2025-01-01"); | ||
| * const d2 = new DatePlus("2025-01-10"); | ||
| * console.log(d2.diff(d1, "days")); // 9 | ||
| * @example | ||
| * console.log(d2.diff(d1, "milliseconds")); // 777600000 | ||
| */ | ||
| diff(other: Date | DatePlus, unit?: DateUnit): number; | ||
| } | ||
| /** | ||
| * Helper function to create a `DatePlus` instance. | ||
| * @param date Optional initial date (`string`, `number`, or `Date`). Defaults to current date/time. | ||
| * @returns A new `DatePlus` instance. | ||
| * | ||
| * @example | ||
| * const d = createDate("2025-01-01"); | ||
| * @example | ||
| * const now = createDate(); // current date/time | ||
| */ | ||
| declare function createDate(date?: string | number | Date): DatePlus; | ||
| export { DatePlus, brBuilder, capitalize, createDate, createInterval, createLoopInterval, createTimeout, equalsIgnoreCase, hexToRgb, includesIgnoreCase, isDefined, isEmail, isNumeric, isPromise, isUrl, limitText, notFound, parseFloatOrDefault, parseIntOrDefault, random, randomNumber, replaceText, rgbToHex, sleep, spaceBuilder, toMs, withProperties, withTimeout }; | ||
| export type { CanBeString, DateUnit, MaybeString }; |
+91
-9
@@ -253,9 +253,2 @@ /** | ||
| type Sleep = SetTimeoutFunction & SleepTimes; | ||
| /** | ||
| * ```ts | ||
| * await sleep(100); // wait 100 ms | ||
| * await sleep.seconds(5); // wait 5000 ms | ||
| * await sleep.minutes(2); // wait 120000 ms | ||
| * ``` | ||
| */ | ||
| declare const sleep: Sleep; | ||
@@ -383,3 +376,92 @@ interface CreateIntervalOptions { | ||
| export { brBuilder, capitalize, createInterval, createLoopInterval, createTimeout, equalsIgnoreCase, hexToRgb, includesIgnoreCase, isDefined, isEmail, isNumeric, isPromise, isUrl, limitText, notFound, parseFloatOrDefault, parseIntOrDefault, random, randomNumber, replaceText, rgbToHex, sleep, spaceBuilder, toMs, withProperties, withTimeout }; | ||
| export type { CanBeString, MaybeString }; | ||
| type DateUnit = "days" | "hours" | "minutes" | "seconds" | "milliseconds" | "months" | "years"; | ||
| declare class DatePlus extends Date { | ||
| /** | ||
| * Creates a new `DatePlus` instance. | ||
| * @param date Initial date. Can be a `string`, `number` (timestamp), or `Date`. Defaults to the current date/time. | ||
| * | ||
| * @example | ||
| * const d1 = new DatePlus(); // now | ||
| * @example | ||
| * const d2 = new DatePlus("2025-01-01"); // specific date | ||
| */ | ||
| constructor(date?: string | number | Date); | ||
| /** | ||
| * Adds a value to a specific unit of the date. | ||
| * @param unit Time unit to add to (`days`, `hours`, `minutes`, `seconds`, `milliseconds`, `months`, `years`). | ||
| * @param value Amount to add (can be negative or fractional, e.g., 1.5 days). | ||
| * @returns The same `DatePlus` instance (supports method chaining). | ||
| * | ||
| * @example | ||
| * const d = new DatePlus("2025-01-01"); | ||
| * d.add("days", 5); // adds 5 days | ||
| * @example | ||
| * d.add("hours", 12); // adds 12 hours | ||
| */ | ||
| add(unit: DateUnit, value: number): this; | ||
| /** | ||
| * Subtracts a value from a specific unit of the date. | ||
| * @param unit Time unit to subtract from (`days`, `hours`, `minutes`, `seconds`, `milliseconds`, `months`, `years`). | ||
| * @param value Amount to subtract. | ||
| * @returns The same `DatePlus` instance (supports method chaining). | ||
| * | ||
| * @example | ||
| * const d = new DatePlus("2025-01-10"); | ||
| * d.sub("days", 3); // subtracts 3 days | ||
| * @example | ||
| * d.sub("hours", 5); // subtracts 5 hours | ||
| */ | ||
| sub(unit: DateUnit, value: number): this; | ||
| /** | ||
| * Sets a specific unit of the date to an absolute value. | ||
| * @param unit Time unit to set (`days`, `hours`, `minutes`, `seconds`, `milliseconds`, `months`, `years`). | ||
| * @param value New value for the specified unit. | ||
| * @returns The same `DatePlus` instance (supports method chaining). | ||
| * | ||
| * @example | ||
| * const d = new DatePlus("2025-01-01"); | ||
| * d.set("hours", 15); // sets the hour to 15 | ||
| * @example | ||
| * d.set("days", 10); // sets the day of the month to 10 | ||
| */ | ||
| set(unit: DateUnit, value: number): this; | ||
| /** | ||
| * Creates a clone of the current `DatePlus` instance. | ||
| * @returns A new `DatePlus` instance with the same date/time. | ||
| * | ||
| * @example | ||
| * const d1 = new DatePlus("2025-01-01"); | ||
| * const d2 = d1.clone(); | ||
| * @example | ||
| * d2.add("days", 5); // d1 remains unchanged | ||
| */ | ||
| clone(): DatePlus; | ||
| /** | ||
| * Calculates the difference between this date and another date. | ||
| * @param other The other `Date` or `DatePlus` instance to compare against. | ||
| * @param unit Unit to return the difference in (`milliseconds` by default). | ||
| * @returns The difference between the two dates in the specified unit. | ||
| * | ||
| * @example | ||
| * const d1 = new DatePlus("2025-01-01"); | ||
| * const d2 = new DatePlus("2025-01-10"); | ||
| * console.log(d2.diff(d1, "days")); // 9 | ||
| * @example | ||
| * console.log(d2.diff(d1, "milliseconds")); // 777600000 | ||
| */ | ||
| diff(other: Date | DatePlus, unit?: DateUnit): number; | ||
| } | ||
| /** | ||
| * Helper function to create a `DatePlus` instance. | ||
| * @param date Optional initial date (`string`, `number`, or `Date`). Defaults to current date/time. | ||
| * @returns A new `DatePlus` instance. | ||
| * | ||
| * @example | ||
| * const d = createDate("2025-01-01"); | ||
| * @example | ||
| * const now = createDate(); // current date/time | ||
| */ | ||
| declare function createDate(date?: string | number | Date): DatePlus; | ||
| export { DatePlus, brBuilder, capitalize, createDate, createInterval, createLoopInterval, createTimeout, equalsIgnoreCase, hexToRgb, includesIgnoreCase, isDefined, isEmail, isNumeric, isPromise, isUrl, limitText, notFound, parseFloatOrDefault, parseIntOrDefault, random, randomNumber, replaceText, rgbToHex, sleep, spaceBuilder, toMs, withProperties, withTimeout }; | ||
| export type { CanBeString, DateUnit, MaybeString }; |
+1
-0
@@ -9,1 +9,2 @@ export { equalsIgnoreCase, includesIgnoreCase } from './functions/check.mjs'; | ||
| export { withProperties, withTimeout } from './functions/with.mjs'; | ||
| export { DatePlus, createDate } from './functions/date.mjs'; |
+1
-1
| { | ||
| "name": "@magicyan/core", | ||
| "version": "1.1.3", | ||
| "version": "1.1.4", | ||
| "description": "A collection of simple, lightweight utility functions for common tasks in projects.", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
76554
35.05%25
8.7%1138
54.41%