chronos-date 1.0.1 → 1.1.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.
Files changed (102) hide show
  1. package/dist/basic-DIp_pxR2.cjs +450 -0
  2. package/dist/basic-Dputob9z.mjs +366 -0
  3. package/dist/constants.cjs +27 -1
  4. package/dist/constants.mjs +5 -1
  5. package/dist/convert-CNVL-mop.mjs +22 -0
  6. package/dist/convert-dQuGWhVm.cjs +33 -0
  7. package/dist/greet-B8ZtypgG.cjs +40 -0
  8. package/dist/greet-B9j4afzD.mjs +35 -0
  9. package/dist/guards.cjs +119 -1
  10. package/dist/guards.mjs +110 -1
  11. package/dist/helpers-CrMc9iJZ.mjs +185 -0
  12. package/dist/helpers-M_SfAbAv.cjs +262 -0
  13. package/dist/index.cjs +1461 -1
  14. package/dist/index.mjs +1458 -1
  15. package/dist/non-primitives-CT4vszrX.cjs +52 -0
  16. package/dist/non-primitives-DrQfPj1r.mjs +22 -0
  17. package/dist/plugins/banglaPlugin.cjs +121 -1
  18. package/dist/plugins/banglaPlugin.d.cts +1 -1
  19. package/dist/plugins/banglaPlugin.d.mts +1 -1
  20. package/dist/plugins/banglaPlugin.mjs +120 -1
  21. package/dist/plugins/businessPlugin.cjs +118 -1
  22. package/dist/plugins/businessPlugin.d.cts +1 -1
  23. package/dist/plugins/businessPlugin.d.mts +1 -1
  24. package/dist/plugins/businessPlugin.mjs +117 -1
  25. package/dist/plugins/dateRangePlugin.cjs +46 -1
  26. package/dist/plugins/dateRangePlugin.d.cts +1 -1
  27. package/dist/plugins/dateRangePlugin.d.mts +1 -1
  28. package/dist/plugins/dateRangePlugin.mjs +45 -1
  29. package/dist/plugins/dayPartPlugin.cjs +26 -1
  30. package/dist/plugins/dayPartPlugin.d.cts +1 -1
  31. package/dist/plugins/dayPartPlugin.d.mts +1 -1
  32. package/dist/plugins/dayPartPlugin.mjs +25 -1
  33. package/dist/plugins/durationPlugin.cjs +91 -1
  34. package/dist/plugins/durationPlugin.d.cts +1 -1
  35. package/dist/plugins/durationPlugin.d.mts +1 -1
  36. package/dist/plugins/durationPlugin.mjs +90 -1
  37. package/dist/plugins/fromNowPlugin.cjs +80 -1
  38. package/dist/plugins/fromNowPlugin.d.cts +1 -1
  39. package/dist/plugins/fromNowPlugin.d.mts +1 -1
  40. package/dist/plugins/fromNowPlugin.mjs +79 -1
  41. package/dist/plugins/greetingPlugin.cjs +19 -1
  42. package/dist/plugins/greetingPlugin.d.cts +1 -1
  43. package/dist/plugins/greetingPlugin.d.mts +1 -1
  44. package/dist/plugins/greetingPlugin.mjs +18 -1
  45. package/dist/plugins/palindromePlugin.cjs +22 -1
  46. package/dist/plugins/palindromePlugin.d.cts +1 -1
  47. package/dist/plugins/palindromePlugin.d.mts +1 -1
  48. package/dist/plugins/palindromePlugin.mjs +21 -1
  49. package/dist/plugins/relativeTimePlugin.cjs +74 -1
  50. package/dist/plugins/relativeTimePlugin.d.cts +1 -1
  51. package/dist/plugins/relativeTimePlugin.d.mts +1 -1
  52. package/dist/plugins/relativeTimePlugin.mjs +73 -1
  53. package/dist/plugins/roundPlugin.cjs +69 -1
  54. package/dist/plugins/roundPlugin.d.cts +1 -1
  55. package/dist/plugins/roundPlugin.d.mts +1 -1
  56. package/dist/plugins/roundPlugin.mjs +68 -1
  57. package/dist/plugins/seasonPlugin.cjs +31 -1
  58. package/dist/plugins/seasonPlugin.d.cts +1 -1
  59. package/dist/plugins/seasonPlugin.d.mts +1 -1
  60. package/dist/plugins/seasonPlugin.mjs +30 -1
  61. package/dist/plugins/timeZonePlugin.cjs +139 -1
  62. package/dist/plugins/timeZonePlugin.d.cts +1 -1
  63. package/dist/plugins/timeZonePlugin.d.mts +1 -1
  64. package/dist/plugins/timeZonePlugin.mjs +138 -1
  65. package/dist/plugins/zodiacPlugin.cjs +51 -1
  66. package/dist/plugins/zodiacPlugin.d.cts +1 -1
  67. package/dist/plugins/zodiacPlugin.d.mts +1 -1
  68. package/dist/plugins/zodiacPlugin.mjs +50 -1
  69. package/dist/primitives-BME3_QrA.cjs +49 -0
  70. package/dist/primitives-DEt6I7Sy.mjs +19 -0
  71. package/dist/seasons-CHnjrIKK.mjs +352 -0
  72. package/dist/seasons-CcZicoe1.cjs +418 -0
  73. package/dist/timezone-BfBXeMK_.mjs +5573 -0
  74. package/dist/timezone-DYVJJYKz.cjs +5609 -0
  75. package/dist/types.mjs +1 -1
  76. package/dist/utilities-BU4MSYS7.mjs +43 -0
  77. package/dist/utilities-CGL7F6R9.cjs +72 -0
  78. package/dist/utilities-CtOZhIYv.mjs +241 -0
  79. package/dist/utilities-bXwTPJaD.cjs +318 -0
  80. package/dist/utils.cjs +76 -1
  81. package/dist/utils.mjs +44 -1
  82. package/package.json +1 -1
  83. package/dist/basic-CKxaRSHQ.cjs +0 -1
  84. package/dist/basic-e46DaNAi.mjs +0 -1
  85. package/dist/convert-Bmp63ats.mjs +0 -1
  86. package/dist/convert-DrLrcgqz.cjs +0 -1
  87. package/dist/greet-BBsrvmkn.mjs +0 -1
  88. package/dist/greet-C-6mruI9.cjs +0 -1
  89. package/dist/helpers-DGzYnP81.cjs +0 -1
  90. package/dist/helpers-N1X_Rj_V.mjs +0 -1
  91. package/dist/non-primitives-B2EE6D6s.mjs +0 -1
  92. package/dist/non-primitives-Bu3a4WL4.cjs +0 -1
  93. package/dist/primitives-Cxss_JVF.mjs +0 -1
  94. package/dist/primitives-Db2FUp4e.cjs +0 -1
  95. package/dist/seasons-ChAIVphi.mjs +0 -1
  96. package/dist/seasons-oABOhHcX.cjs +0 -1
  97. package/dist/timezone-B10UItNO.mjs +0 -1
  98. package/dist/timezone-CWxbK_7I.cjs +0 -1
  99. package/dist/utilities-B8dOAQVD.cjs +0 -1
  100. package/dist/utilities-BJE06bms.mjs +0 -1
  101. package/dist/utilities-D2-p26DX.cjs +0 -1
  102. package/dist/utilities-DV_ohS37.mjs +0 -1
@@ -1 +1,46 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../basic-CKxaRSHQ.cjs`),t=require(`../primitives-Db2FUp4e.cjs`),n=require(`../non-primitives-Bu3a4WL4.cjs`),r=r=>{let{internalDate:i,cast:a,withOrigin:o,offset:s}=r[e.s];r.prototype.getDatesInRange=function(c){let l=this.clone(),u=this.addWeeks(4),{format:d=`local`,onlyDays:f,skipDays:p,roundDate:m=!1}=c??{};if(c){if(`from`in c||`to`in c)c?.from&&(l=a(c.from)),c?.to&&(u=a(c.to));else if(`span`in c||`unit`in c){let{span:e=4,unit:t=`week`}=c;u=l.add(e,t)}}m&&(l=l.startOf(`day`),u=u.startOf(`day`));let h=n.a(f)?f:n.a(p)?p:[],g=new Set(h.map(n=>t.r(n)?n:e.o.indexOf(n))),_=[],v=i(l).getTime(),y=i(u).getTime(),b=(v<=y?1:-1)*e.u,x=Math.floor(Math.abs(y-v)/e.u);for(let e=0;e<=x;e++){let t=v+e*b,i=new Date(t).getDay();if(n.a(f)?g.has(i):!g.has(i)){let e=o(new r(t),`clone`,s(this),l.timeZoneName,l.timeZoneId,l.$tzTracker);_.push(d===`local`?e.toLocalISOString():e.toISOString())}}return _}};exports.dateRangePlugin=r;
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_basic = require('../basic-DIp_pxR2.cjs');
3
+ const require_primitives = require('../primitives-BME3_QrA.cjs');
4
+ const require_non_primitives = require('../non-primitives-CT4vszrX.cjs');
5
+
6
+ //#region src/plugins/dateRangePlugin.ts
7
+ /** * Plugin to inject `getDatesInRange` related method */
8
+ const dateRangePlugin = ($Chronos) => {
9
+ const { internalDate: $Date, cast, withOrigin, offset } = $Chronos[require_basic.INTERNALS];
10
+ $Chronos.prototype.getDatesInRange = function(options) {
11
+ let startDate = this.clone(), endDate = this.addWeeks(4);
12
+ const { format = "local", onlyDays, skipDays, roundDate = false } = options ?? {};
13
+ if (options) {
14
+ if ("from" in options || "to" in options) {
15
+ if (options?.from) startDate = cast(options.from);
16
+ if (options?.to) endDate = cast(options.to);
17
+ } else if ("span" in options || "unit" in options) {
18
+ const { span = 4, unit = "week" } = options;
19
+ endDate = startDate.add(span, unit);
20
+ }
21
+ }
22
+ if (roundDate) {
23
+ startDate = startDate.startOf("day");
24
+ endDate = endDate.startOf("day");
25
+ }
26
+ const skippedDays = require_non_primitives.isValidArray(onlyDays) ? onlyDays : require_non_primitives.isValidArray(skipDays) ? skipDays : [];
27
+ const skipSet = new Set(skippedDays.map((day) => require_primitives.isNumber(day) ? day : require_basic.DAYS.indexOf(day)));
28
+ const dates = [];
29
+ const startTime = $Date(startDate).getTime();
30
+ const endTime = $Date(endDate).getTime();
31
+ const step = (startTime <= endTime ? 1 : -1) * require_basic.MS_PER_DAY;
32
+ const totalDays = Math.floor(Math.abs(endTime - startTime) / require_basic.MS_PER_DAY);
33
+ for (let i = 0; i <= totalDays; i++) {
34
+ const ts = startTime + i * step;
35
+ const wDay = new Date(ts).getDay();
36
+ if (require_non_primitives.isValidArray(onlyDays) ? skipSet.has(wDay) : !skipSet.has(wDay)) {
37
+ const chr = withOrigin(new $Chronos(ts), "clone", offset(this), startDate.timeZoneName, startDate.timeZoneId, startDate.$tzTracker);
38
+ dates.push(format === "local" ? chr.toLocalISOString() : chr.toISOString());
39
+ }
40
+ }
41
+ return dates;
42
+ };
43
+ };
44
+
45
+ //#endregion
46
+ exports.dateRangePlugin = dateRangePlugin;
@@ -1,7 +1,7 @@
1
1
  import { C as $Chronos, I as RangeWithDates, L as RelativeDateRange, ht as ISOTimeString } from "../types-DPTQ_yLx.cjs";
2
2
 
3
3
  //#region src/plugins/dateRangePlugin.d.ts
4
- declare module '../' {
4
+ declare module 'chronos-date' {
5
5
  interface Chronos {
6
6
  /**
7
7
  * @instance Returns an array of ISO date-time strings within a specific date range.
@@ -1,7 +1,7 @@
1
1
  import { C as $Chronos, I as RangeWithDates, L as RelativeDateRange, ht as ISOTimeString } from "../types-B2fgrJ86.mjs";
2
2
 
3
3
  //#region src/plugins/dateRangePlugin.d.ts
4
- declare module '../' {
4
+ declare module 'chronos-date' {
5
5
  interface Chronos {
6
6
  /**
7
7
  * @instance Returns an array of ISO date-time strings within a specific date range.
@@ -1 +1,45 @@
1
- import{o as e,s as t,u as n}from"../basic-e46DaNAi.mjs";import{r}from"../primitives-Cxss_JVF.mjs";import{a as i}from"../non-primitives-B2EE6D6s.mjs";const a=a=>{let{internalDate:o,cast:s,withOrigin:c,offset:l}=a[t];a.prototype.getDatesInRange=function(t){let u=this.clone(),d=this.addWeeks(4),{format:f=`local`,onlyDays:p,skipDays:m,roundDate:h=!1}=t??{};if(t){if(`from`in t||`to`in t)t?.from&&(u=s(t.from)),t?.to&&(d=s(t.to));else if(`span`in t||`unit`in t){let{span:e=4,unit:n=`week`}=t;d=u.add(e,n)}}h&&(u=u.startOf(`day`),d=d.startOf(`day`));let g=i(p)?p:i(m)?m:[],_=new Set(g.map(t=>r(t)?t:e.indexOf(t))),v=[],y=o(u).getTime(),b=o(d).getTime(),x=(y<=b?1:-1)*n,S=Math.floor(Math.abs(b-y)/n);for(let e=0;e<=S;e++){let t=y+e*x,n=new Date(t).getDay();if(i(p)?_.has(n):!_.has(n)){let e=c(new a(t),`clone`,l(this),u.timeZoneName,u.timeZoneId,u.$tzTracker);v.push(f===`local`?e.toLocalISOString():e.toISOString())}}return v}};export{a as dateRangePlugin};
1
+ import { o as DAYS, s as INTERNALS, u as MS_PER_DAY } from "../basic-Dputob9z.mjs";
2
+ import { r as isNumber } from "../primitives-DEt6I7Sy.mjs";
3
+ import { a as isValidArray } from "../non-primitives-DrQfPj1r.mjs";
4
+
5
+ //#region src/plugins/dateRangePlugin.ts
6
+ /** * Plugin to inject `getDatesInRange` related method */
7
+ const dateRangePlugin = ($Chronos) => {
8
+ const { internalDate: $Date, cast, withOrigin, offset } = $Chronos[INTERNALS];
9
+ $Chronos.prototype.getDatesInRange = function(options) {
10
+ let startDate = this.clone(), endDate = this.addWeeks(4);
11
+ const { format = "local", onlyDays, skipDays, roundDate = false } = options ?? {};
12
+ if (options) {
13
+ if ("from" in options || "to" in options) {
14
+ if (options?.from) startDate = cast(options.from);
15
+ if (options?.to) endDate = cast(options.to);
16
+ } else if ("span" in options || "unit" in options) {
17
+ const { span = 4, unit = "week" } = options;
18
+ endDate = startDate.add(span, unit);
19
+ }
20
+ }
21
+ if (roundDate) {
22
+ startDate = startDate.startOf("day");
23
+ endDate = endDate.startOf("day");
24
+ }
25
+ const skippedDays = isValidArray(onlyDays) ? onlyDays : isValidArray(skipDays) ? skipDays : [];
26
+ const skipSet = new Set(skippedDays.map((day) => isNumber(day) ? day : DAYS.indexOf(day)));
27
+ const dates = [];
28
+ const startTime = $Date(startDate).getTime();
29
+ const endTime = $Date(endDate).getTime();
30
+ const step = (startTime <= endTime ? 1 : -1) * MS_PER_DAY;
31
+ const totalDays = Math.floor(Math.abs(endTime - startTime) / MS_PER_DAY);
32
+ for (let i = 0; i <= totalDays; i++) {
33
+ const ts = startTime + i * step;
34
+ const wDay = new Date(ts).getDay();
35
+ if (isValidArray(onlyDays) ? skipSet.has(wDay) : !skipSet.has(wDay)) {
36
+ const chr = withOrigin(new $Chronos(ts), "clone", offset(this), startDate.timeZoneName, startDate.timeZoneId, startDate.$tzTracker);
37
+ dates.push(format === "local" ? chr.toLocalISOString() : chr.toISOString());
38
+ }
39
+ }
40
+ return dates;
41
+ };
42
+ };
43
+
44
+ //#endregion
45
+ export { dateRangePlugin };
@@ -1 +1,26 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../basic-CKxaRSHQ.cjs`),t=require(`../non-primitives-Bu3a4WL4.cjs`),n=n=>{n.prototype.getPartOfDay=function(n){let r=this.hour,i={...e.a,...t.n(n)&&n};for(let[e,[t,n]]of Object.entries(i)){let i=Number(t),a=Number(n);if(i<=a){if(r>=i&&r<=a)return e}else if(r>=i||r<=a)return e}return`night`}};exports.dayPartPlugin=n;
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_basic = require('../basic-DIp_pxR2.cjs');
3
+ const require_non_primitives = require('../non-primitives-CT4vszrX.cjs');
4
+
5
+ //#region src/plugins/dayPartPlugin.ts
6
+ /** * Plugin to inject `getPartOfDay` method */
7
+ const dayPartPlugin = ($Chronos) => {
8
+ $Chronos.prototype.getPartOfDay = function(config) {
9
+ const hour = this.hour;
10
+ const ranges = {
11
+ ...require_basic.DATE_PART_RANGES,
12
+ ...require_non_primitives.isNotEmptyObject(config) && config
13
+ };
14
+ for (const [part, [start, end]] of Object.entries(ranges)) {
15
+ const from = Number(start);
16
+ const to = Number(end);
17
+ if (from <= to) {
18
+ if (hour >= from && hour <= to) return part;
19
+ } else if (hour >= from || hour <= to) return part;
20
+ }
21
+ return "night";
22
+ };
23
+ };
24
+
25
+ //#endregion
26
+ exports.dayPartPlugin = dayPartPlugin;
@@ -1,7 +1,7 @@
1
1
  import { C as $Chronos, c as DayPart, l as DayPartConfig } from "../types-DPTQ_yLx.cjs";
2
2
 
3
3
  //#region src/plugins/dayPartPlugin.d.ts
4
- declare module '../' {
4
+ declare module 'chronos-date' {
5
5
  interface Chronos {
6
6
  /**
7
7
  * @instance Returns the part of day (`'midnight', 'lateNight', 'night', 'morning', 'afternoon', 'evening'`) based on the current hour.
@@ -1,7 +1,7 @@
1
1
  import { C as $Chronos, c as DayPart, l as DayPartConfig } from "../types-B2fgrJ86.mjs";
2
2
 
3
3
  //#region src/plugins/dayPartPlugin.d.ts
4
- declare module '../' {
4
+ declare module 'chronos-date' {
5
5
  interface Chronos {
6
6
  /**
7
7
  * @instance Returns the part of day (`'midnight', 'lateNight', 'night', 'morning', 'afternoon', 'evening'`) based on the current hour.
@@ -1 +1,25 @@
1
- import{a as e}from"../basic-e46DaNAi.mjs";import{n as t}from"../non-primitives-B2EE6D6s.mjs";const n=n=>{n.prototype.getPartOfDay=function(n){let r=this.hour,i={...e,...t(n)&&n};for(let[e,[t,n]]of Object.entries(i)){let i=Number(t),a=Number(n);if(i<=a){if(r>=i&&r<=a)return e}else if(r>=i||r<=a)return e}return`night`}};export{n as dayPartPlugin};
1
+ import { a as DATE_PART_RANGES } from "../basic-Dputob9z.mjs";
2
+ import { n as isNotEmptyObject } from "../non-primitives-DrQfPj1r.mjs";
3
+
4
+ //#region src/plugins/dayPartPlugin.ts
5
+ /** * Plugin to inject `getPartOfDay` method */
6
+ const dayPartPlugin = ($Chronos) => {
7
+ $Chronos.prototype.getPartOfDay = function(config) {
8
+ const hour = this.hour;
9
+ const ranges = {
10
+ ...DATE_PART_RANGES,
11
+ ...isNotEmptyObject(config) && config
12
+ };
13
+ for (const [part, [start, end]] of Object.entries(ranges)) {
14
+ const from = Number(start);
15
+ const to = Number(end);
16
+ if (from <= to) {
17
+ if (hour >= from && hour <= to) return part;
18
+ } else if (hour >= from || hour <= to) return part;
19
+ }
20
+ return "night";
21
+ };
22
+ };
23
+
24
+ //#endregion
25
+ export { dayPartPlugin };
@@ -1 +1,91 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../basic-CKxaRSHQ.cjs`),t=t=>{let{toNewDate:n}=t[e.s],r=(e,t,n)=>{let r=Object.entries(e),i={...e};if(!t&&!n)for(let[e,t]of r)t!==0&&(i[e]=t*-1);else if(t)for(let[e,t]of r)i[e]=Math.abs(t);return i};t.prototype.duration=function(e,t=!0){let i=this.toDate(),a=n(this,e),o=a>i,s=o?i:a,c=o?a:i,l=e=>c[`get${e}`]()-s[`get${e}`](),u=l(`FullYear`),d=l(`Month`),f=l(`Date`),p=l(`Hours`),m=l(`Minutes`),h=l(`Seconds`),g=l(`Milliseconds`);if(g<0&&(g+=1e3,h--),h<0&&(h+=60,m--),m<0&&(m+=60,p--),p<0&&(p+=24,f--),f<0){let e=new Date(c.getFullYear(),c.getMonth(),0);f+=e.getDate(),d--}return d<0&&(d+=12,u--),r({years:u,months:d,days:f,hours:p,minutes:m,seconds:h,milliseconds:g},t,o)},t.prototype.durationString=function(e){let{toTime:t,absolute:n=!0,maxUnits:r=7,separator:i=`, `,style:a=`full`,showZero:o=!1}=e??{},s=this.duration(t,n),c={years:`y`,months:`mo`,days:`d`,hours:`h`,minutes:`m`,seconds:`s`,milliseconds:`ms`},l=(e,t)=>a===`short`?`${t}${c[e]}`:`${t} ${Math.abs(t)===1?e.slice(0,-1):e}`,u=Object.entries(s).filter(([e,t])=>o||Math.abs(t)>0).slice(0,r).map(([e,t])=>l(e,t));return u.length?u.join(i):a===`short`?`0s`:`0 seconds`}};exports.durationPlugin=t;
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_basic = require('../basic-DIp_pxR2.cjs');
3
+
4
+ //#region src/plugins/durationPlugin.ts
5
+ /** * Plugin to inject `duration` related methods */
6
+ const durationPlugin = ($Chronos) => {
7
+ const { toNewDate } = $Chronos[require_basic.INTERNALS];
8
+ /**
9
+ * @private Normalizes duration values based on sign and `absolute` flag.
10
+ * @param result The raw time breakdown to normalize.
11
+ * @param absolute If true, ensures all values are positive.
12
+ * @param isFuture Whether the duration was forward (true) or backward (false).
13
+ * @returns The normalized duration object.
14
+ */
15
+ const _normalizeDuration = (result, absolute, isFuture) => {
16
+ const entries = Object.entries(result);
17
+ const updated = { ...result };
18
+ if (!absolute && !isFuture) {
19
+ for (const [key, value] of entries) if (value !== 0) updated[key] = value * -1;
20
+ } else if (absolute) for (const [key, value] of entries) updated[key] = Math.abs(value);
21
+ return updated;
22
+ };
23
+ $Chronos.prototype.duration = function(toTime, absolute = true) {
24
+ const now = this.toDate();
25
+ const target = toNewDate(this, toTime);
26
+ const isFuture = target > now;
27
+ const from = isFuture ? now : target;
28
+ const to = isFuture ? target : now;
29
+ /** Get difference between `to` and `from` for specific unit */
30
+ const _getDiff = (suffix) => {
31
+ return to[`get${suffix}`]() - from[`get${suffix}`]();
32
+ };
33
+ let y = _getDiff("FullYear"), mo = _getDiff("Month"), d = _getDiff("Date"), h = _getDiff("Hours"), m = _getDiff("Minutes"), s = _getDiff("Seconds"), ms = _getDiff("Milliseconds");
34
+ if (ms < 0) {
35
+ ms += 1e3;
36
+ s--;
37
+ }
38
+ if (s < 0) {
39
+ s += 60;
40
+ m--;
41
+ }
42
+ if (m < 0) {
43
+ m += 60;
44
+ h--;
45
+ }
46
+ if (h < 0) {
47
+ h += 24;
48
+ d--;
49
+ }
50
+ if (d < 0) {
51
+ const prevMonth = new Date(to.getFullYear(), to.getMonth(), 0);
52
+ d += prevMonth.getDate();
53
+ mo--;
54
+ }
55
+ if (mo < 0) {
56
+ mo += 12;
57
+ y--;
58
+ }
59
+ return _normalizeDuration({
60
+ years: y,
61
+ months: mo,
62
+ days: d,
63
+ hours: h,
64
+ minutes: m,
65
+ seconds: s,
66
+ milliseconds: ms
67
+ }, absolute, isFuture);
68
+ };
69
+ $Chronos.prototype.durationString = function(options) {
70
+ const { toTime, absolute = true, maxUnits = 7, separator = ", ", style = "full", showZero = false } = options ?? {};
71
+ const duration = this.duration(toTime, absolute);
72
+ const units = {
73
+ years: "y",
74
+ months: "mo",
75
+ days: "d",
76
+ hours: "h",
77
+ minutes: "m",
78
+ seconds: "s",
79
+ milliseconds: "ms"
80
+ };
81
+ const _formatUnit = (unit, value) => {
82
+ if (style === "short") return `${value}${units[unit]}`;
83
+ return `${value} ${Math.abs(value) === 1 ? unit.slice(0, -1) : unit}`;
84
+ };
85
+ const parts = Object.entries(duration).filter(([_, value]) => showZero || Math.abs(value) > 0).slice(0, maxUnits).map(([unit, value]) => _formatUnit(unit, value));
86
+ return parts.length ? parts.join(separator) : style === "short" ? "0s" : "0 seconds";
87
+ };
88
+ };
89
+
90
+ //#endregion
91
+ exports.durationPlugin = durationPlugin;
@@ -1,7 +1,7 @@
1
1
  import { C as $Chronos, D as ChronosInput, d as DurationOptions, g as TimeDuration } from "../types-DPTQ_yLx.cjs";
2
2
 
3
3
  //#region src/plugins/durationPlugin.d.ts
4
- declare module '../' {
4
+ declare module 'chronos-date' {
5
5
  interface Chronos {
6
6
  /**
7
7
  * @instance Returns the full time duration breakdown between current input (start) and another time (to) as {@link TimeDuration} object.
@@ -1,7 +1,7 @@
1
1
  import { C as $Chronos, D as ChronosInput, d as DurationOptions, g as TimeDuration } from "../types-B2fgrJ86.mjs";
2
2
 
3
3
  //#region src/plugins/durationPlugin.d.ts
4
- declare module '../' {
4
+ declare module 'chronos-date' {
5
5
  interface Chronos {
6
6
  /**
7
7
  * @instance Returns the full time duration breakdown between current input (start) and another time (to) as {@link TimeDuration} object.
@@ -1 +1,90 @@
1
- import{s as e}from"../basic-e46DaNAi.mjs";const t=t=>{let{toNewDate:n}=t[e],r=(e,t,n)=>{let r=Object.entries(e),i={...e};if(!t&&!n)for(let[e,t]of r)t!==0&&(i[e]=t*-1);else if(t)for(let[e,t]of r)i[e]=Math.abs(t);return i};t.prototype.duration=function(e,t=!0){let i=this.toDate(),a=n(this,e),o=a>i,s=o?i:a,c=o?a:i,l=e=>c[`get${e}`]()-s[`get${e}`](),u=l(`FullYear`),d=l(`Month`),f=l(`Date`),p=l(`Hours`),m=l(`Minutes`),h=l(`Seconds`),g=l(`Milliseconds`);if(g<0&&(g+=1e3,h--),h<0&&(h+=60,m--),m<0&&(m+=60,p--),p<0&&(p+=24,f--),f<0){let e=new Date(c.getFullYear(),c.getMonth(),0);f+=e.getDate(),d--}return d<0&&(d+=12,u--),r({years:u,months:d,days:f,hours:p,minutes:m,seconds:h,milliseconds:g},t,o)},t.prototype.durationString=function(e){let{toTime:t,absolute:n=!0,maxUnits:r=7,separator:i=`, `,style:a=`full`,showZero:o=!1}=e??{},s=this.duration(t,n),c={years:`y`,months:`mo`,days:`d`,hours:`h`,minutes:`m`,seconds:`s`,milliseconds:`ms`},l=(e,t)=>a===`short`?`${t}${c[e]}`:`${t} ${Math.abs(t)===1?e.slice(0,-1):e}`,u=Object.entries(s).filter(([e,t])=>o||Math.abs(t)>0).slice(0,r).map(([e,t])=>l(e,t));return u.length?u.join(i):a===`short`?`0s`:`0 seconds`}};export{t as durationPlugin};
1
+ import { s as INTERNALS } from "../basic-Dputob9z.mjs";
2
+
3
+ //#region src/plugins/durationPlugin.ts
4
+ /** * Plugin to inject `duration` related methods */
5
+ const durationPlugin = ($Chronos) => {
6
+ const { toNewDate } = $Chronos[INTERNALS];
7
+ /**
8
+ * @private Normalizes duration values based on sign and `absolute` flag.
9
+ * @param result The raw time breakdown to normalize.
10
+ * @param absolute If true, ensures all values are positive.
11
+ * @param isFuture Whether the duration was forward (true) or backward (false).
12
+ * @returns The normalized duration object.
13
+ */
14
+ const _normalizeDuration = (result, absolute, isFuture) => {
15
+ const entries = Object.entries(result);
16
+ const updated = { ...result };
17
+ if (!absolute && !isFuture) {
18
+ for (const [key, value] of entries) if (value !== 0) updated[key] = value * -1;
19
+ } else if (absolute) for (const [key, value] of entries) updated[key] = Math.abs(value);
20
+ return updated;
21
+ };
22
+ $Chronos.prototype.duration = function(toTime, absolute = true) {
23
+ const now = this.toDate();
24
+ const target = toNewDate(this, toTime);
25
+ const isFuture = target > now;
26
+ const from = isFuture ? now : target;
27
+ const to = isFuture ? target : now;
28
+ /** Get difference between `to` and `from` for specific unit */
29
+ const _getDiff = (suffix) => {
30
+ return to[`get${suffix}`]() - from[`get${suffix}`]();
31
+ };
32
+ let y = _getDiff("FullYear"), mo = _getDiff("Month"), d = _getDiff("Date"), h = _getDiff("Hours"), m = _getDiff("Minutes"), s = _getDiff("Seconds"), ms = _getDiff("Milliseconds");
33
+ if (ms < 0) {
34
+ ms += 1e3;
35
+ s--;
36
+ }
37
+ if (s < 0) {
38
+ s += 60;
39
+ m--;
40
+ }
41
+ if (m < 0) {
42
+ m += 60;
43
+ h--;
44
+ }
45
+ if (h < 0) {
46
+ h += 24;
47
+ d--;
48
+ }
49
+ if (d < 0) {
50
+ const prevMonth = new Date(to.getFullYear(), to.getMonth(), 0);
51
+ d += prevMonth.getDate();
52
+ mo--;
53
+ }
54
+ if (mo < 0) {
55
+ mo += 12;
56
+ y--;
57
+ }
58
+ return _normalizeDuration({
59
+ years: y,
60
+ months: mo,
61
+ days: d,
62
+ hours: h,
63
+ minutes: m,
64
+ seconds: s,
65
+ milliseconds: ms
66
+ }, absolute, isFuture);
67
+ };
68
+ $Chronos.prototype.durationString = function(options) {
69
+ const { toTime, absolute = true, maxUnits = 7, separator = ", ", style = "full", showZero = false } = options ?? {};
70
+ const duration = this.duration(toTime, absolute);
71
+ const units = {
72
+ years: "y",
73
+ months: "mo",
74
+ days: "d",
75
+ hours: "h",
76
+ minutes: "m",
77
+ seconds: "s",
78
+ milliseconds: "ms"
79
+ };
80
+ const _formatUnit = (unit, value) => {
81
+ if (style === "short") return `${value}${units[unit]}`;
82
+ return `${value} ${Math.abs(value) === 1 ? unit.slice(0, -1) : unit}`;
83
+ };
84
+ const parts = Object.entries(duration).filter(([_, value]) => showZero || Math.abs(value) > 0).slice(0, maxUnits).map(([unit, value]) => _formatUnit(unit, value));
85
+ return parts.length ? parts.join(separator) : style === "short" ? "0s" : "0 seconds";
86
+ };
87
+ };
88
+
89
+ //#endregion
90
+ export { durationPlugin };
@@ -1 +1,80 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../basic-CKxaRSHQ.cjs`),t=require(`../convert-DrLrcgqz.cjs`),n=n=>{let{toNewDate:r}=n[e.s];n.prototype.fromNow=function(e=`second`,n=!0,i){let a=r(this,i),o=this.toDate(),s=o>a,c=s?a:o,l=s?o:a,u=e=>l[`get${e}`]()-c[`get${e}`](),d=u(`FullYear`),f=u(`Month`),p=u(`Date`),m=u(`Hours`),h=u(`Minutes`),g=u(`Seconds`),_=u(`Milliseconds`);if(_<0&&(_+=1e3,g--),g<0&&(g+=60,h--),h<0&&(h+=60,m--),m<0&&(m+=24,p--),p<0){let e=new Date(l.getFullYear(),l.getMonth(),0);p+=e.getDate(),f--}f<0&&(f+=12,d--);let v=[`year`,`month`,`day`,`hour`,`minute`,`second`,`millisecond`],y=v.indexOf(e),b=[],x=(e,n)=>{b.push(t.t(e,n))},S=e=>y>=v.indexOf(e);d>0&&x(d,`year`),S(`month`)&&f>0&&x(f,`month`),S(`day`)&&p>0&&x(p,`day`),S(`hour`)&&m>0&&x(m,`hour`),S(`minute`)&&h>0&&x(h,`minute`),S(`second`)&&g>0&&x(g,`second`),S(`millisecond`)&&(_>0||b?.length===0)&&x(_,`millisecond`);let C=``,w=``;return n&&(s?C=`in `:w=` ago`),`${C}${b.length?b?.join(` `):`0 ${e}s`}${w}`}};exports.fromNowPlugin=n;
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_basic = require('../basic-DIp_pxR2.cjs');
3
+ const require_convert = require('../convert-dQuGWhVm.cjs');
4
+
5
+ //#region src/plugins/fromNowPlugin.ts
6
+ /** * Plugin to inject `fromNow` method */
7
+ const fromNowPlugin = ($Chronos) => {
8
+ const { toNewDate } = $Chronos[require_basic.INTERNALS];
9
+ $Chronos.prototype.fromNow = function(level = "second", wSP = true, time) {
10
+ const now = toNewDate(this, time);
11
+ const target = this.toDate();
12
+ const isFuture = target > now;
13
+ const from = isFuture ? now : target;
14
+ const to = isFuture ? target : now;
15
+ /** Get difference between `to` and `from` for specific unit */
16
+ const _getDiff = (suffix) => {
17
+ return to[`get${suffix}`]() - from[`get${suffix}`]();
18
+ };
19
+ let y = _getDiff("FullYear"), mo = _getDiff("Month"), d = _getDiff("Date"), h = _getDiff("Hours"), m = _getDiff("Minutes"), s = _getDiff("Seconds"), ms = _getDiff("Milliseconds");
20
+ if (ms < 0) {
21
+ ms += 1e3;
22
+ s--;
23
+ }
24
+ if (s < 0) {
25
+ s += 60;
26
+ m--;
27
+ }
28
+ if (m < 0) {
29
+ m += 60;
30
+ h--;
31
+ }
32
+ if (h < 0) {
33
+ h += 24;
34
+ d--;
35
+ }
36
+ if (d < 0) {
37
+ const prevMonth = new Date(to.getFullYear(), to.getMonth(), 0);
38
+ d += prevMonth.getDate();
39
+ mo--;
40
+ }
41
+ if (mo < 0) {
42
+ mo += 12;
43
+ y--;
44
+ }
45
+ const unitOrder = [
46
+ "year",
47
+ "month",
48
+ "day",
49
+ "hour",
50
+ "minute",
51
+ "second",
52
+ "millisecond"
53
+ ];
54
+ const lvlIdx = unitOrder.indexOf(level);
55
+ const parts = [];
56
+ /** Push value-unit string to `parts` array */
57
+ const _pushToParts = (value, unit) => {
58
+ parts.push(require_convert.formatUnitWithPlural(value, unit));
59
+ };
60
+ /** Check if a unit level is required */
61
+ const _isLevelRequired = (unit) => {
62
+ return lvlIdx >= unitOrder.indexOf(unit);
63
+ };
64
+ if (y > 0) _pushToParts(y, "year");
65
+ if (_isLevelRequired("month") && mo > 0) _pushToParts(mo, "month");
66
+ if (_isLevelRequired("day") && d > 0) _pushToParts(d, "day");
67
+ if (_isLevelRequired("hour") && h > 0) _pushToParts(h, "hour");
68
+ if (_isLevelRequired("minute") && m > 0) _pushToParts(m, "minute");
69
+ if (_isLevelRequired("second") && s > 0) _pushToParts(s, "second");
70
+ if (_isLevelRequired("millisecond") && (ms > 0 || parts?.length === 0)) _pushToParts(ms, "millisecond");
71
+ let prefix = "";
72
+ let suffix = "";
73
+ if (wSP) if (isFuture) prefix = "in ";
74
+ else suffix = " ago";
75
+ return `${prefix}${parts.length ? parts?.join(" ") : `0 ${level}s`}${suffix}`;
76
+ };
77
+ };
78
+
79
+ //#endregion
80
+ exports.fromNowPlugin = fromNowPlugin;
@@ -1,7 +1,7 @@
1
1
  import { C as $Chronos, D as ChronosInput, ut as FromNowUnit } from "../types-DPTQ_yLx.cjs";
2
2
 
3
3
  //#region src/plugins/fromNowPlugin.d.ts
4
- declare module '../' {
4
+ declare module 'chronos-date' {
5
5
  interface Chronos {
6
6
  /**
7
7
  * @instance Returns full time difference from now (or a specified time) down to a given level.
@@ -1,7 +1,7 @@
1
1
  import { C as $Chronos, D as ChronosInput, ut as FromNowUnit } from "../types-B2fgrJ86.mjs";
2
2
 
3
3
  //#region src/plugins/fromNowPlugin.d.ts
4
- declare module '../' {
4
+ declare module 'chronos-date' {
5
5
  interface Chronos {
6
6
  /**
7
7
  * @instance Returns full time difference from now (or a specified time) down to a given level.
@@ -1 +1,79 @@
1
- import{s as e}from"../basic-e46DaNAi.mjs";import{t}from"../convert-Bmp63ats.mjs";const n=n=>{let{toNewDate:r}=n[e];n.prototype.fromNow=function(e=`second`,n=!0,i){let a=r(this,i),o=this.toDate(),s=o>a,c=s?a:o,l=s?o:a,u=e=>l[`get${e}`]()-c[`get${e}`](),d=u(`FullYear`),f=u(`Month`),p=u(`Date`),m=u(`Hours`),h=u(`Minutes`),g=u(`Seconds`),_=u(`Milliseconds`);if(_<0&&(_+=1e3,g--),g<0&&(g+=60,h--),h<0&&(h+=60,m--),m<0&&(m+=24,p--),p<0){let e=new Date(l.getFullYear(),l.getMonth(),0);p+=e.getDate(),f--}f<0&&(f+=12,d--);let v=[`year`,`month`,`day`,`hour`,`minute`,`second`,`millisecond`],y=v.indexOf(e),b=[],x=(e,n)=>{b.push(t(e,n))},S=e=>y>=v.indexOf(e);d>0&&x(d,`year`),S(`month`)&&f>0&&x(f,`month`),S(`day`)&&p>0&&x(p,`day`),S(`hour`)&&m>0&&x(m,`hour`),S(`minute`)&&h>0&&x(h,`minute`),S(`second`)&&g>0&&x(g,`second`),S(`millisecond`)&&(_>0||b?.length===0)&&x(_,`millisecond`);let C=``,w=``;return n&&(s?C=`in `:w=` ago`),`${C}${b.length?b?.join(` `):`0 ${e}s`}${w}`}};export{n as fromNowPlugin};
1
+ import { s as INTERNALS } from "../basic-Dputob9z.mjs";
2
+ import { t as formatUnitWithPlural } from "../convert-CNVL-mop.mjs";
3
+
4
+ //#region src/plugins/fromNowPlugin.ts
5
+ /** * Plugin to inject `fromNow` method */
6
+ const fromNowPlugin = ($Chronos) => {
7
+ const { toNewDate } = $Chronos[INTERNALS];
8
+ $Chronos.prototype.fromNow = function(level = "second", wSP = true, time) {
9
+ const now = toNewDate(this, time);
10
+ const target = this.toDate();
11
+ const isFuture = target > now;
12
+ const from = isFuture ? now : target;
13
+ const to = isFuture ? target : now;
14
+ /** Get difference between `to` and `from` for specific unit */
15
+ const _getDiff = (suffix) => {
16
+ return to[`get${suffix}`]() - from[`get${suffix}`]();
17
+ };
18
+ let y = _getDiff("FullYear"), mo = _getDiff("Month"), d = _getDiff("Date"), h = _getDiff("Hours"), m = _getDiff("Minutes"), s = _getDiff("Seconds"), ms = _getDiff("Milliseconds");
19
+ if (ms < 0) {
20
+ ms += 1e3;
21
+ s--;
22
+ }
23
+ if (s < 0) {
24
+ s += 60;
25
+ m--;
26
+ }
27
+ if (m < 0) {
28
+ m += 60;
29
+ h--;
30
+ }
31
+ if (h < 0) {
32
+ h += 24;
33
+ d--;
34
+ }
35
+ if (d < 0) {
36
+ const prevMonth = new Date(to.getFullYear(), to.getMonth(), 0);
37
+ d += prevMonth.getDate();
38
+ mo--;
39
+ }
40
+ if (mo < 0) {
41
+ mo += 12;
42
+ y--;
43
+ }
44
+ const unitOrder = [
45
+ "year",
46
+ "month",
47
+ "day",
48
+ "hour",
49
+ "minute",
50
+ "second",
51
+ "millisecond"
52
+ ];
53
+ const lvlIdx = unitOrder.indexOf(level);
54
+ const parts = [];
55
+ /** Push value-unit string to `parts` array */
56
+ const _pushToParts = (value, unit) => {
57
+ parts.push(formatUnitWithPlural(value, unit));
58
+ };
59
+ /** Check if a unit level is required */
60
+ const _isLevelRequired = (unit) => {
61
+ return lvlIdx >= unitOrder.indexOf(unit);
62
+ };
63
+ if (y > 0) _pushToParts(y, "year");
64
+ if (_isLevelRequired("month") && mo > 0) _pushToParts(mo, "month");
65
+ if (_isLevelRequired("day") && d > 0) _pushToParts(d, "day");
66
+ if (_isLevelRequired("hour") && h > 0) _pushToParts(h, "hour");
67
+ if (_isLevelRequired("minute") && m > 0) _pushToParts(m, "minute");
68
+ if (_isLevelRequired("second") && s > 0) _pushToParts(s, "second");
69
+ if (_isLevelRequired("millisecond") && (ms > 0 || parts?.length === 0)) _pushToParts(ms, "millisecond");
70
+ let prefix = "";
71
+ let suffix = "";
72
+ if (wSP) if (isFuture) prefix = "in ";
73
+ else suffix = " ago";
74
+ return `${prefix}${parts.length ? parts?.join(" ") : `0 ${level}s`}${suffix}`;
75
+ };
76
+ };
77
+
78
+ //#endregion
79
+ export { fromNowPlugin };
@@ -1 +1,19 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../greet-C-6mruI9.cjs`),t=t=>{t.prototype.getGreeting=function(t){return e.t({currentTime:this.formatStrict(`HH:mm`),...t})},t.prototype.greet=function(e){return this.getGreeting(e)}};exports.greetingPlugin=t;
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_greet = require('../greet-B8ZtypgG.cjs');
3
+
4
+ //#region src/plugins/greetingPlugin.ts
5
+ /** * Plugin to inject `getGreeting`/`greet` method */
6
+ const greetingPlugin = ($Chronos) => {
7
+ $Chronos.prototype.getGreeting = function(configs) {
8
+ return require_greet.getGreeting({
9
+ currentTime: this.formatStrict("HH:mm"),
10
+ ...configs
11
+ });
12
+ };
13
+ $Chronos.prototype.greet = function(configs) {
14
+ return this.getGreeting(configs);
15
+ };
16
+ };
17
+
18
+ //#endregion
19
+ exports.greetingPlugin = greetingPlugin;
@@ -1,7 +1,7 @@
1
1
  import { C as $Chronos, dt as GreetingConfigs } from "../types-DPTQ_yLx.cjs";
2
2
 
3
3
  //#region src/plugins/greetingPlugin.d.ts
4
- declare module '../' {
4
+ declare module 'chronos-date' {
5
5
  interface Chronos {
6
6
  /**
7
7
  * @instance Returns a greeting message based on current instance of `Chronos` time or provided time in the `configs`.
@@ -1,7 +1,7 @@
1
1
  import { C as $Chronos, dt as GreetingConfigs } from "../types-B2fgrJ86.mjs";
2
2
 
3
3
  //#region src/plugins/greetingPlugin.d.ts
4
- declare module '../' {
4
+ declare module 'chronos-date' {
5
5
  interface Chronos {
6
6
  /**
7
7
  * @instance Returns a greeting message based on current instance of `Chronos` time or provided time in the `configs`.
@@ -1 +1,18 @@
1
- import{t as e}from"../greet-BBsrvmkn.mjs";const t=t=>{t.prototype.getGreeting=function(t){return e({currentTime:this.formatStrict(`HH:mm`),...t})},t.prototype.greet=function(e){return this.getGreeting(e)}};export{t as greetingPlugin};
1
+ import { t as getGreeting } from "../greet-B9j4afzD.mjs";
2
+
3
+ //#region src/plugins/greetingPlugin.ts
4
+ /** * Plugin to inject `getGreeting`/`greet` method */
5
+ const greetingPlugin = ($Chronos) => {
6
+ $Chronos.prototype.getGreeting = function(configs) {
7
+ return getGreeting({
8
+ currentTime: this.formatStrict("HH:mm"),
9
+ ...configs
10
+ });
11
+ };
12
+ $Chronos.prototype.greet = function(configs) {
13
+ return this.getGreeting(configs);
14
+ };
15
+ };
16
+
17
+ //#endregion
18
+ export { greetingPlugin };