@hackthedev/datetools 1.0.1 → 1.0.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.
- package/index.mjs +2 -2
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -33,7 +33,7 @@ export default class DateTools {
|
|
|
33
33
|
return `${days}d ${hours}h ${minutes}m ${seconds}s`;
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
static getDateFromOffset(offset) {
|
|
36
|
+
static getDateFromOffset(offset, customDate = null) {
|
|
37
37
|
if(!offset) throw new Error("No offset provided. Examples: -1 day, +2hours, ...");
|
|
38
38
|
|
|
39
39
|
const units = {
|
|
@@ -63,7 +63,7 @@ export default class DateTools {
|
|
|
63
63
|
throw new Error("Invalid offset format. Use '<number> <unit>' (e.g., '-1 day', '+2 hours').");
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
const now = new Date();
|
|
66
|
+
const now = customDate ? customDate : new Date();
|
|
67
67
|
|
|
68
68
|
if (units[unit] === "months") {
|
|
69
69
|
now.setMonth(now.getMonth() + amount);
|