chronos-date 1.0.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.
- package/LICENSE +201 -0
- package/README.md +31 -0
- package/dist/basic-CKxaRSHQ.cjs +1 -0
- package/dist/basic-e46DaNAi.mjs +1 -0
- package/dist/constants.cjs +1 -0
- package/dist/constants.d.cts +2 -0
- package/dist/constants.d.mts +2 -0
- package/dist/constants.mjs +1 -0
- package/dist/convert-Bmp63ats.mjs +1 -0
- package/dist/convert-DrLrcgqz.cjs +1 -0
- package/dist/greet-BBsrvmkn.mjs +1 -0
- package/dist/greet-C-6mruI9.cjs +1 -0
- package/dist/guards.cjs +1 -0
- package/dist/guards.d.cts +71 -0
- package/dist/guards.d.mts +71 -0
- package/dist/guards.mjs +1 -0
- package/dist/helpers-DGzYnP81.cjs +1 -0
- package/dist/helpers-N1X_Rj_V.mjs +1 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.cts +3 -0
- package/dist/index.d.mts +3 -0
- package/dist/index.mjs +1 -0
- package/dist/non-primitives-B2EE6D6s.mjs +1 -0
- package/dist/non-primitives-Bu3a4WL4.cjs +1 -0
- package/dist/plugins/banglaPlugin.cjs +1 -0
- package/dist/plugins/banglaPlugin.d.cts +225 -0
- package/dist/plugins/banglaPlugin.d.mts +225 -0
- package/dist/plugins/banglaPlugin.mjs +1 -0
- package/dist/plugins/businessPlugin.cjs +1 -0
- package/dist/plugins/businessPlugin.d.cts +446 -0
- package/dist/plugins/businessPlugin.d.mts +446 -0
- package/dist/plugins/businessPlugin.mjs +1 -0
- package/dist/plugins/dateRangePlugin.cjs +1 -0
- package/dist/plugins/dateRangePlugin.d.cts +71 -0
- package/dist/plugins/dateRangePlugin.d.mts +71 -0
- package/dist/plugins/dateRangePlugin.mjs +1 -0
- package/dist/plugins/dayPartPlugin.cjs +1 -0
- package/dist/plugins/dayPartPlugin.d.cts +45 -0
- package/dist/plugins/dayPartPlugin.d.mts +45 -0
- package/dist/plugins/dayPartPlugin.mjs +1 -0
- package/dist/plugins/durationPlugin.cjs +1 -0
- package/dist/plugins/durationPlugin.d.cts +30 -0
- package/dist/plugins/durationPlugin.d.mts +30 -0
- package/dist/plugins/durationPlugin.mjs +1 -0
- package/dist/plugins/fromNowPlugin.cjs +1 -0
- package/dist/plugins/fromNowPlugin.d.cts +24 -0
- package/dist/plugins/fromNowPlugin.d.mts +24 -0
- package/dist/plugins/fromNowPlugin.mjs +1 -0
- package/dist/plugins/greetingPlugin.cjs +1 -0
- package/dist/plugins/greetingPlugin.d.cts +29 -0
- package/dist/plugins/greetingPlugin.d.mts +29 -0
- package/dist/plugins/greetingPlugin.mjs +1 -0
- package/dist/plugins/palindromePlugin.cjs +1 -0
- package/dist/plugins/palindromePlugin.d.cts +38 -0
- package/dist/plugins/palindromePlugin.d.mts +38 -0
- package/dist/plugins/palindromePlugin.mjs +1 -0
- package/dist/plugins/relativeTimePlugin.cjs +1 -0
- package/dist/plugins/relativeTimePlugin.d.cts +82 -0
- package/dist/plugins/relativeTimePlugin.d.mts +82 -0
- package/dist/plugins/relativeTimePlugin.mjs +1 -0
- package/dist/plugins/roundPlugin.cjs +1 -0
- package/dist/plugins/roundPlugin.d.cts +29 -0
- package/dist/plugins/roundPlugin.d.mts +29 -0
- package/dist/plugins/roundPlugin.mjs +1 -0
- package/dist/plugins/seasonPlugin.cjs +1 -0
- package/dist/plugins/seasonPlugin.d.cts +26 -0
- package/dist/plugins/seasonPlugin.d.mts +26 -0
- package/dist/plugins/seasonPlugin.mjs +1 -0
- package/dist/plugins/timeZonePlugin.cjs +1 -0
- package/dist/plugins/timeZonePlugin.d.cts +88 -0
- package/dist/plugins/timeZonePlugin.d.mts +88 -0
- package/dist/plugins/timeZonePlugin.mjs +1 -0
- package/dist/plugins/zodiacPlugin.cjs +1 -0
- package/dist/plugins/zodiacPlugin.d.cts +41 -0
- package/dist/plugins/zodiacPlugin.d.mts +41 -0
- package/dist/plugins/zodiacPlugin.mjs +1 -0
- package/dist/primitives-Cxss_JVF.mjs +1 -0
- package/dist/primitives-Db2FUp4e.cjs +1 -0
- package/dist/seasons-ChAIVphi.mjs +1 -0
- package/dist/seasons-CioTH5Dm.d.mts +5285 -0
- package/dist/seasons-CsVeJ27s.d.cts +5285 -0
- package/dist/seasons-oABOhHcX.cjs +1 -0
- package/dist/timezone-B10UItNO.mjs +1 -0
- package/dist/timezone-CWxbK_7I.cjs +1 -0
- package/dist/types-B2fgrJ86.d.mts +2123 -0
- package/dist/types-DPTQ_yLx.d.cts +2123 -0
- package/dist/types.cjs +0 -0
- package/dist/types.d.cts +2 -0
- package/dist/types.d.mts +2 -0
- package/dist/types.mjs +1 -0
- package/dist/utilities-B8dOAQVD.cjs +1 -0
- package/dist/utilities-BJE06bms.mjs +1 -0
- package/dist/utilities-D2-p26DX.cjs +1 -0
- package/dist/utilities-DV_ohS37.mjs +1 -0
- package/dist/utils.cjs +1 -0
- package/dist/utils.d.cts +188 -0
- package/dist/utils.d.mts +188 -0
- package/dist/utils.mjs +1 -0
- package/package.json +162 -0
package/dist/types.cjs
ADDED
|
File without changes
|
package/dist/types.d.cts
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { $ as ChronosStaticKey, $t as BanglaDateOptions, A as ChronosObject, At as TimeZoneDetails, B as WithoutOrigin, Bt as ChronosStatics, C as $Chronos, Ct as NumberingSystem, D as ChronosInput, Dt as TimeUnitValue, E as $StaticMethods, Et as TimeUnit, F as PluginMethods, Ft as TimeZoneNameNative, G as $NativeTzNameOrId, Gt as $BanglaYear, H as $GMTOffset, I as RangeWithDates, It as TimestampOptions, J as $TimeUnitVar, Jt as $BnMonthPadded, K as $TZLabelKey, Kt as $BnDatePadded, L as RelativeDateRange, Lt as UTCMinute, M as ChronosWithOptions, Mt as TimeZoneIdNative, N as DateRangeOptions, Nt as TimeZoneIdentifier, O as ChronosInternals, Ot as TimeWithUnit, P as DatesInRangeOptions, Pt as TimeZoneName, Q as $UnitAnyCase, Qt as BanglaDateObject, R as RelativeRangeOptions, Rt as UTCOffset, S as ZodiacSign, St as NegativeUTCHour, T as $PluginMethods, Tt as Quarter, U as $ISOTimeString, Ut as $BanglaMonth, V as $DateUnit, W as $LocalArguments, Wt as $BanglaMonthDate, X as $TimeZoneIdentifier, Xt as BanglaDate, Y as $TimeUnitVarMap, Yt as $BnYearPadded, Z as $UTCOffset, Zt as BanglaDateFormat, _ as ZodiacArray, _n as StrictFormat, _t as LocalesArguments, a as BusinessOptionsWeekends, an as BnCalendarConfig, at as DateFormatOptions, b as ZodiacOptions, bn as TimeToken, bt as MonthName, c as DayPart, cn as DateFormatToken, ct as DateTimeFormatOptions, d as DurationOptions, dn as FormatToken, dt as GreetingConfigs, en as BanglaDayName, et as ClockHour, f as MonthBoundary, fn as HourToken, ft as HourMinutes, g as TimeDuration, gn as SecondToken, gt as LocaleCalendar, h as SeasonPreset, hn as MonthToken, ht as ISOTimeString, i as BusinessOptionsBasic, in as BanglaYear, it as DateArgs, j as ChronosProperties, jt as TimeZoneId, k as ChronosMethods, kt as TimeZone, l as DayPartConfig, ln as DateToken, lt as FormatOptions, m as SeasonOptions, mn as MinuteToken, mt as ISODateTimeString, n as $BusinessHourOptions, nn as BanglaMonthName, nt as ClockSecond, o as ChronosPlugin, on as BnCalendarVariant, ot as DateLike, p as SeasonDefinition, pn as MSToken, pt as ISODateFormat, q as $TimeUnitKey, qt as $BnEn, r as AcademicYear, rn as BanglaSeasonName, rt as ClockTime, s as DateBoundary, sn as DateWithSeasonToken, st as DateString, t as $BusinessHourBaseOptions, tn as BanglaMonth, tt as ClockMinute, u as DurationKey, un as DayToken, ut as FromNowUnit, v as ZodiacMeta, vn as TimeFormatToken, vt as Milliseconds, w as $InstanceMethods, wt as PositiveUTCHour, x as ZodiacPreset, xn as YearToken, xt as MonthString, y as ZodiacMetaOptions, yn as TimeOnlyFormat, yt as MonthDateString, z as WeekdayOptions, zt as WeekDay } from "./types-DPTQ_yLx.cjs";
|
|
2
|
+
export { $BanglaMonth, $BanglaMonthDate, $BanglaYear, $BnDatePadded, $BnEn, $BnMonthPadded, $BnYearPadded, $BusinessHourBaseOptions, $BusinessHourOptions, $Chronos, $DateUnit, $GMTOffset, $ISOTimeString, $InstanceMethods, $LocalArguments, $NativeTzNameOrId, $PluginMethods, $StaticMethods, $TZLabelKey, $TimeUnitKey, $TimeUnitVar, $TimeUnitVarMap, $TimeZoneIdentifier, $UTCOffset, $UnitAnyCase, AcademicYear, BanglaDate, BanglaDateFormat, BanglaDateObject, BanglaDateOptions, BanglaDayName, BanglaMonth, BanglaMonthName, BanglaSeasonName, BanglaYear, BnCalendarConfig, BnCalendarVariant, BusinessOptionsBasic, BusinessOptionsWeekends, ChronosInput, ChronosInternals, ChronosMethods, ChronosObject, ChronosPlugin, ChronosProperties, ChronosStaticKey, ChronosStatics, ChronosWithOptions, ClockHour, ClockMinute, ClockSecond, ClockTime, DateArgs, DateBoundary, DateFormatOptions, DateFormatToken, DateLike, DateRangeOptions, DateString, DateTimeFormatOptions, DateToken, DateWithSeasonToken, DatesInRangeOptions, DayPart, DayPartConfig, DayToken, DurationKey, DurationOptions, FormatOptions, FormatToken, FromNowUnit, GreetingConfigs, HourMinutes, HourToken, ISODateFormat, ISODateTimeString, ISOTimeString, LocaleCalendar, LocalesArguments, MSToken, Milliseconds, MinuteToken, MonthBoundary, MonthDateString, MonthName, MonthString, MonthToken, NegativeUTCHour, NumberingSystem, PluginMethods, PositiveUTCHour, Quarter, RangeWithDates, RelativeDateRange, RelativeRangeOptions, SeasonDefinition, SeasonOptions, SeasonPreset, SecondToken, StrictFormat, TimeDuration, TimeFormatToken, TimeOnlyFormat, TimeToken, TimeUnit, TimeUnitValue, TimeWithUnit, TimeZone, TimeZoneDetails, TimeZoneId, TimeZoneIdNative, TimeZoneIdentifier, TimeZoneName, TimeZoneNameNative, TimestampOptions, UTCMinute, UTCOffset, WeekDay, WeekdayOptions, WithoutOrigin, YearToken, ZodiacArray, ZodiacMeta, ZodiacMetaOptions, ZodiacOptions, ZodiacPreset, ZodiacSign };
|
package/dist/types.d.mts
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { $ as ChronosStaticKey, $t as BanglaDateOptions, A as ChronosObject, At as TimeZoneDetails, B as WithoutOrigin, Bt as ChronosStatics, C as $Chronos, Ct as NumberingSystem, D as ChronosInput, Dt as TimeUnitValue, E as $StaticMethods, Et as TimeUnit, F as PluginMethods, Ft as TimeZoneNameNative, G as $NativeTzNameOrId, Gt as $BanglaYear, H as $GMTOffset, I as RangeWithDates, It as TimestampOptions, J as $TimeUnitVar, Jt as $BnMonthPadded, K as $TZLabelKey, Kt as $BnDatePadded, L as RelativeDateRange, Lt as UTCMinute, M as ChronosWithOptions, Mt as TimeZoneIdNative, N as DateRangeOptions, Nt as TimeZoneIdentifier, O as ChronosInternals, Ot as TimeWithUnit, P as DatesInRangeOptions, Pt as TimeZoneName, Q as $UnitAnyCase, Qt as BanglaDateObject, R as RelativeRangeOptions, Rt as UTCOffset, S as ZodiacSign, St as NegativeUTCHour, T as $PluginMethods, Tt as Quarter, U as $ISOTimeString, Ut as $BanglaMonth, V as $DateUnit, W as $LocalArguments, Wt as $BanglaMonthDate, X as $TimeZoneIdentifier, Xt as BanglaDate, Y as $TimeUnitVarMap, Yt as $BnYearPadded, Z as $UTCOffset, Zt as BanglaDateFormat, _ as ZodiacArray, _n as StrictFormat, _t as LocalesArguments, a as BusinessOptionsWeekends, an as BnCalendarConfig, at as DateFormatOptions, b as ZodiacOptions, bn as TimeToken, bt as MonthName, c as DayPart, cn as DateFormatToken, ct as DateTimeFormatOptions, d as DurationOptions, dn as FormatToken, dt as GreetingConfigs, en as BanglaDayName, et as ClockHour, f as MonthBoundary, fn as HourToken, ft as HourMinutes, g as TimeDuration, gn as SecondToken, gt as LocaleCalendar, h as SeasonPreset, hn as MonthToken, ht as ISOTimeString, i as BusinessOptionsBasic, in as BanglaYear, it as DateArgs, j as ChronosProperties, jt as TimeZoneId, k as ChronosMethods, kt as TimeZone, l as DayPartConfig, ln as DateToken, lt as FormatOptions, m as SeasonOptions, mn as MinuteToken, mt as ISODateTimeString, n as $BusinessHourOptions, nn as BanglaMonthName, nt as ClockSecond, o as ChronosPlugin, on as BnCalendarVariant, ot as DateLike, p as SeasonDefinition, pn as MSToken, pt as ISODateFormat, q as $TimeUnitKey, qt as $BnEn, r as AcademicYear, rn as BanglaSeasonName, rt as ClockTime, s as DateBoundary, sn as DateWithSeasonToken, st as DateString, t as $BusinessHourBaseOptions, tn as BanglaMonth, tt as ClockMinute, u as DurationKey, un as DayToken, ut as FromNowUnit, v as ZodiacMeta, vn as TimeFormatToken, vt as Milliseconds, w as $InstanceMethods, wt as PositiveUTCHour, x as ZodiacPreset, xn as YearToken, xt as MonthString, y as ZodiacMetaOptions, yn as TimeOnlyFormat, yt as MonthDateString, z as WeekdayOptions, zt as WeekDay } from "./types-B2fgrJ86.mjs";
|
|
2
|
+
export { $BanglaMonth, $BanglaMonthDate, $BanglaYear, $BnDatePadded, $BnEn, $BnMonthPadded, $BnYearPadded, $BusinessHourBaseOptions, $BusinessHourOptions, $Chronos, $DateUnit, $GMTOffset, $ISOTimeString, $InstanceMethods, $LocalArguments, $NativeTzNameOrId, $PluginMethods, $StaticMethods, $TZLabelKey, $TimeUnitKey, $TimeUnitVar, $TimeUnitVarMap, $TimeZoneIdentifier, $UTCOffset, $UnitAnyCase, AcademicYear, BanglaDate, BanglaDateFormat, BanglaDateObject, BanglaDateOptions, BanglaDayName, BanglaMonth, BanglaMonthName, BanglaSeasonName, BanglaYear, BnCalendarConfig, BnCalendarVariant, BusinessOptionsBasic, BusinessOptionsWeekends, ChronosInput, ChronosInternals, ChronosMethods, ChronosObject, ChronosPlugin, ChronosProperties, ChronosStaticKey, ChronosStatics, ChronosWithOptions, ClockHour, ClockMinute, ClockSecond, ClockTime, DateArgs, DateBoundary, DateFormatOptions, DateFormatToken, DateLike, DateRangeOptions, DateString, DateTimeFormatOptions, DateToken, DateWithSeasonToken, DatesInRangeOptions, DayPart, DayPartConfig, DayToken, DurationKey, DurationOptions, FormatOptions, FormatToken, FromNowUnit, GreetingConfigs, HourMinutes, HourToken, ISODateFormat, ISODateTimeString, ISOTimeString, LocaleCalendar, LocalesArguments, MSToken, Milliseconds, MinuteToken, MonthBoundary, MonthDateString, MonthName, MonthString, MonthToken, NegativeUTCHour, NumberingSystem, PluginMethods, PositiveUTCHour, Quarter, RangeWithDates, RelativeDateRange, RelativeRangeOptions, SeasonDefinition, SeasonOptions, SeasonPreset, SecondToken, StrictFormat, TimeDuration, TimeFormatToken, TimeOnlyFormat, TimeToken, TimeUnit, TimeUnitValue, TimeWithUnit, TimeZone, TimeZoneDetails, TimeZoneId, TimeZoneIdNative, TimeZoneIdentifier, TimeZoneName, TimeZoneNameNative, TimestampOptions, UTCMinute, UTCOffset, WeekDay, WeekdayOptions, WithoutOrigin, YearToken, ZodiacArray, ZodiacMeta, ZodiacMetaOptions, ZodiacOptions, ZodiacPreset, ZodiacSign };
|
package/dist/types.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=require(`./timezone-CWxbK_7I.cjs`),t=require(`./primitives-Db2FUp4e.cjs`),n=require(`./non-primitives-Bu3a4WL4.cjs`),r=require(`./utilities-D2-p26DX.cjs`),i=require(`./guards.cjs`),a=require(`./helpers-DGzYnP81.cjs`);function o(e){let[t,n]=e.split(`:`).map(Number);return[t,n]}function s(e){let t=e.startsWith(`-`),[n,r]=o(t?e.slice(1):e),i=n*60+r;return t?-i:i}function c(e){return e.replace(/^UTC[+]?/g,``)}function l(e){return s(c(e))}function u(e){let n=r.n(e);if(t.a(n))throw TypeError(`Invalid numeric input!`,{cause:`${e} cannot be converted to a number.`});let i=Math.abs(n);return`${String(Math.floor(i/60))}:${String(i%60).padStart(2,`0`)}`}function d(e){let n=r.n(e);if(t.a(n))throw TypeError(`Invalid numeric input!`,{cause:`${e} cannot be converted to a number.`});let i=n<0?`-`:`+`,a=Math.abs(n);return`UTC${i}${String(Math.floor(a/60)).padStart(2,`0`)}:${String(a%60).padStart(2,`0`)}`}function f(){return Intl.DateTimeFormat().resolvedOptions().timeZone}function p(e,t){let n=[`long`,`longGeneric`,`longOffset`],r=e||f(),i={tzIdentifier:r};for(let e of n){let n=`tzName${e[0].toUpperCase()}${e.slice(1)}`;i[n]=a.p(r,e,t)}return i}const m=new Map;function h(t){if(!i.isValidUTCOffset(t))return[];if(m.has(t))return m.get(t)??[];for(let t of e.n){let e=a.s(a.p(t,`longOffset`));e&&m.set(e,[...m.get(e)??[],t])}return m.get(t)??[]}function g(e){let{date:t=new Date,format:n=`dd, mmm DD, YYYY HH:mm:ss`,useUTC:r=!1}=e??{},i=a.n(t);if(isNaN(i.getTime()))return`Invalid Date!`;let o=e=>r?i[`getUTC${e}`]():i[`get${e}`]();return a.r(n,o(`FullYear`),o(`Month`),o(`Day`),o(`Date`),o(`Hours`),o(`Minutes`),o(`Seconds`),o(`Milliseconds`),r?`Z`:d(-i.getTimezoneOffset()).slice(3))}function _(e,t){return g({date:`${g({format:`YYYY-MM-DD`})}T${a.u(e)}`,format:t||`hh:mm:ss a`})}function v(e,t){let n=a.n(e);if(isNaN(n.getTime()))return`Invalid Date!`;let r=Date.now(),i=n.getTime(),o=Math.abs(r-i),s=Math.floor(o/6e4),c=Math.floor(o/36e5),l=Math.floor(o/864e5),u=i<r?`ago`:`from now`;return s<1?`Just now`:s<60?`${s}m ${u}`:c<24?`${c}h ${u}`:l<7?`${l}d ${u}`:g({date:e,format:t||`mmm D, yyyy hh:mm a`})}function y(e,t){let r,i;(e=>n.r(e)&&(`value`in e||`format`in e))(e)?(r=e.value||new Date,i=e.format||`utc`):(r=e||new Date,i=t||`utc`);let o=a.n(r);if(isNaN(o.getTime())&&(o=new Date),i===`local`){let e=o.getTimezoneOffset(),t=new Date(o.getTime()-e*6e4),n=d(-e).slice(3);return t.toISOString().replace(`Z`,n)}return o.toISOString()}Object.defineProperty(exports,`a`,{enumerable:!0,get:function(){return g}}),Object.defineProperty(exports,`c`,{enumerable:!0,get:function(){return d}}),Object.defineProperty(exports,`d`,{enumerable:!0,get:function(){return h}}),Object.defineProperty(exports,`f`,{enumerable:!0,get:function(){return y}}),Object.defineProperty(exports,`i`,{enumerable:!0,get:function(){return c}}),Object.defineProperty(exports,`l`,{enumerable:!0,get:function(){return f}}),Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return o}}),Object.defineProperty(exports,`o`,{enumerable:!0,get:function(){return v}}),Object.defineProperty(exports,`p`,{enumerable:!0,get:function(){return s}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return l}}),Object.defineProperty(exports,`s`,{enumerable:!0,get:function(){return _}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return u}}),Object.defineProperty(exports,`u`,{enumerable:!0,get:function(){return p}});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{i as e,r as t}from"./primitives-Cxss_JVF.mjs";function n(t){return e(t)&&t?.trim()!==``&&Number.isFinite(Number(t))}const r=Object.freeze({"০":0,"১":1,"২":2,"৩":3,"৪":4,"৫":5,"৬":6,"৭":7,"৮":8,"৯":9}),i=(e,t=5)=>Math.round(Number(e)/t)*t,a=(e,t=!0)=>{let n=Number(e)%10,r=Number(e)%100,i;return i=n===1&&r!==11?`st`:n===2&&r!==12?`nd`:n===3&&r!==13?`rd`:`th`,t?String(e).concat(i):i};function o(e){return t(e)?e:n(e)?Number(e):void 0}export{n as a,r as i,o as n,i as r,a as t};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=require(`./primitives-Db2FUp4e.cjs`);function t(t){return e.i(t)&&t?.trim()!==``&&Number.isFinite(Number(t))}const n=Object.freeze({"০":0,"১":1,"২":2,"৩":3,"৪":4,"৫":5,"৬":6,"৭":7,"৮":8,"৯":9}),r=(e,t=5)=>Math.round(Number(e)/t)*t,i=(e,t=!0)=>{let n=Number(e)%10,r=Number(e)%100,i;return i=n===1&&r!==11?`st`:n===2&&r!==12?`nd`:n===3&&r!==13?`rd`:`th`,t?String(e).concat(i):i};function a(n){return e.r(n)?n:t(n)?Number(n):void 0}Object.defineProperty(exports,`a`,{enumerable:!0,get:function(){return t}}),Object.defineProperty(exports,`i`,{enumerable:!0,get:function(){return n}}),Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return a}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return r}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return i}});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{n as e}from"./timezone-B10UItNO.mjs";import{a as t}from"./primitives-Cxss_JVF.mjs";import{r as n}from"./non-primitives-B2EE6D6s.mjs";import{n as r}from"./utilities-BJE06bms.mjs";import{isValidUTCOffset as i}from"./guards.mjs";import{n as a,p as o,r as s,s as c,u as l}from"./helpers-N1X_Rj_V.mjs";function u(e){let[t,n]=e.split(`:`).map(Number);return[t,n]}function d(e){let t=e.startsWith(`-`),[n,r]=u(t?e.slice(1):e),i=n*60+r;return t?-i:i}function f(e){return e.replace(/^UTC[+]?/g,``)}function p(e){return d(f(e))}function m(e){let n=r(e);if(t(n))throw TypeError(`Invalid numeric input!`,{cause:`${e} cannot be converted to a number.`});let i=Math.abs(n);return`${String(Math.floor(i/60))}:${String(i%60).padStart(2,`0`)}`}function h(e){let n=r(e);if(t(n))throw TypeError(`Invalid numeric input!`,{cause:`${e} cannot be converted to a number.`});let i=n<0?`-`:`+`,a=Math.abs(n);return`UTC${i}${String(Math.floor(a/60)).padStart(2,`0`)}:${String(a%60).padStart(2,`0`)}`}function g(){return Intl.DateTimeFormat().resolvedOptions().timeZone}function _(e,t){let n=[`long`,`longGeneric`,`longOffset`],r=e||g(),i={tzIdentifier:r};for(let e of n){let n=`tzName${e[0].toUpperCase()}${e.slice(1)}`;i[n]=o(r,e,t)}return i}const v=new Map;function y(t){if(!i(t))return[];if(v.has(t))return v.get(t)??[];for(let t of e){let e=c(o(t,`longOffset`));e&&v.set(e,[...v.get(e)??[],t])}return v.get(t)??[]}function b(e){let{date:t=new Date,format:n=`dd, mmm DD, YYYY HH:mm:ss`,useUTC:r=!1}=e??{},i=a(t);if(isNaN(i.getTime()))return`Invalid Date!`;let o=e=>r?i[`getUTC${e}`]():i[`get${e}`]();return s(n,o(`FullYear`),o(`Month`),o(`Day`),o(`Date`),o(`Hours`),o(`Minutes`),o(`Seconds`),o(`Milliseconds`),r?`Z`:h(-i.getTimezoneOffset()).slice(3))}function x(e,t){return b({date:`${b({format:`YYYY-MM-DD`})}T${l(e)}`,format:t||`hh:mm:ss a`})}function S(e,t){let n=a(e);if(isNaN(n.getTime()))return`Invalid Date!`;let r=Date.now(),i=n.getTime(),o=Math.abs(r-i),s=Math.floor(o/6e4),c=Math.floor(o/36e5),l=Math.floor(o/864e5),u=i<r?`ago`:`from now`;return s<1?`Just now`:s<60?`${s}m ${u}`:c<24?`${c}h ${u}`:l<7?`${l}d ${u}`:b({date:e,format:t||`mmm D, yyyy hh:mm a`})}function C(e,t){let r,i;(e=>n(e)&&(`value`in e||`format`in e))(e)?(r=e.value||new Date,i=e.format||`utc`):(r=e||new Date,i=t||`utc`);let o=a(r);if(isNaN(o.getTime())&&(o=new Date),i===`local`){let e=o.getTimezoneOffset(),t=new Date(o.getTime()-e*6e4),n=h(-e).slice(3);return t.toISOString().replace(`Z`,n)}return o.toISOString()}export{b as a,h as c,y as d,C as f,f as i,g as l,u as n,S as o,d as p,p as r,x as s,m as t,_ as u};
|
package/dist/utils.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./basic-CKxaRSHQ.cjs`),t=require(`./primitives-Db2FUp4e.cjs`),n=require(`./utilities-D2-p26DX.cjs`),r=require(`./guards.cjs`),i=require(`./utilities-B8dOAQVD.cjs`),a=require(`./greet-C-6mruI9.cjs`);function o(e,i=!1){return t.r(e)||n.a(e)?s(`${e}s`,i):r.isTimeWithUnit(e)?s(e,i):NaN}function s(n,r=!1){if(!t.n(n)||n.length>100)throw RangeError(`Value must be a string with length between 1 and 99!`);let i=/^(?<value>-?\d*\.?\d+) *(?<unit>milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|months?|mo|years?|yrs?|y)?$/i.exec(n);if(!i?.groups)return NaN;let a=(i.groups.unit??`ms`).toLowerCase(),o=e.l[a];if(!o)throw RangeError(`Unknown unit "${a}"!`);let s=parseFloat(i.groups.value)*o;return r?s/1e3:s}exports.convertMinutesToHourMinutes=i.t,exports.convertMinutesToTime=i.t,exports.getHourMinutesFromMinutes=i.t,exports.getTimeFromMinutes=i.t,exports.convertMinutesToUTCOffset=i.c,exports.formatUTCOffset=i.c,exports.minutesToUTCOffset=i.c,exports.extractHourMinute=i.n,exports.extractMinutesFromUTC=i.r,exports.getMinutesFromUTC=i.r,exports.getTotalMinutesFromUTC=i.r,exports.extractTimeFromUTC=i.i,exports.extractTimeStringFromUTC=i.i,exports.getTimeStringFromUTC=i.i,exports.extractTotalMinutesFromTime=i.p,exports.getTotalMinutes=i.p,exports.getTotalMinutesFromTime=i.p,exports.formatDate=i.a,exports.formatDateTime=i.a,exports.formatDateRelative=i.o,exports.formatRelativeDate=i.o,exports.formatRelativeTime=i.o,exports.formatTimePart=i.s,exports.generateGreeting=a.t,exports.getGreeting=a.t,exports.greet=a.t,exports.getNativeTimeZoneId=i.l,exports.getTimeZoneDetails=i.u,exports.getTimeZoneIds=i.d,exports.getTimestamp=i.f,exports.parseMSec=o,exports.parseMs=o;
|
package/dist/utils.d.cts
ADDED
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import { At as TimeZoneDetails, Cn as Numeric, It as TimestampOptions, Mt as TimeZoneIdNative, Ot as TimeWithUnit, Rt as UTCOffset, Sn as Maybe, X as $TimeZoneIdentifier, _n as StrictFormat, at as DateFormatOptions, dt as GreetingConfigs, ft as HourMinutes, ht as ISOTimeString, it as DateArgs, pt as ISODateFormat, rt as ClockTime, yn as TimeOnlyFormat } from "./types-DPTQ_yLx.cjs";
|
|
2
|
+
|
|
3
|
+
//#region src/utils/greet.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* * Returns a greeting message based on the provided time or current time.
|
|
6
|
+
*
|
|
7
|
+
* @param configs - Configuration options for greeting times and messages.
|
|
8
|
+
* @returns The appropriate greeting message.
|
|
9
|
+
*/
|
|
10
|
+
declare function getGreeting(configs?: GreetingConfigs): string;
|
|
11
|
+
//#endregion
|
|
12
|
+
//#region src/utils/parser.d.ts
|
|
13
|
+
/**
|
|
14
|
+
* * Parse the given value to milliseconds or optionally to seconds.
|
|
15
|
+
*
|
|
16
|
+
* @param value - The string (with unit) or number (or numeric string) to convert.
|
|
17
|
+
* @param sec - Whether to return the value in seconds. Defaults to `false`.
|
|
18
|
+
* @returns The given value parsed in milliseconds (or seconds if specified).
|
|
19
|
+
*
|
|
20
|
+
* @remarks
|
|
21
|
+
* - A numeric value (number or numeric string ({@link Numeric})) is interpreted as seconds count, e.g., `120` or `'120'` will be treated as `'120 seconds'`.
|
|
22
|
+
* - If you use time value with unit ({@link TimeWithUnit}) be sure you provide the time units (days, hours, etc.), otherwise it will return `NaN`, e.g., `'120 unknown'` will return `NaN`.
|
|
23
|
+
*/
|
|
24
|
+
declare function parseMSec(value: TimeWithUnit | Numeric, sec?: boolean): number;
|
|
25
|
+
//#endregion
|
|
26
|
+
//#region src/utils/utilities.d.ts
|
|
27
|
+
/**
|
|
28
|
+
* * Extracts the hour and minute from a time string in `HH:MM` or `-HH:MM` format.
|
|
29
|
+
*
|
|
30
|
+
* @param time - The time string to extract from.
|
|
31
|
+
* @return The extracted hour and minute as number tuple.
|
|
32
|
+
*/
|
|
33
|
+
declare function extractHourMinute(time: `-${ClockTime}` | ClockTime): [number, number];
|
|
34
|
+
/**
|
|
35
|
+
* * Converts a time string `HH:MM` or `-HH:MM` into total minutes from `00:00`.
|
|
36
|
+
*
|
|
37
|
+
* @param time - The time in `HH:MM` or `-HH:MM` format.
|
|
38
|
+
* @returns The total minutes elapsed since `00:00`.
|
|
39
|
+
*/
|
|
40
|
+
declare function getTotalMinutes(time: `-${ClockTime}` | ClockTime): number;
|
|
41
|
+
/**
|
|
42
|
+
* * Extract Time in `HH:MM` format from given UTC value.
|
|
43
|
+
*
|
|
44
|
+
* @param utc UTC value in `UTC-01:30` or `UTC+01:30` format.
|
|
45
|
+
* @returns The UTC value in `HH:MM` format.
|
|
46
|
+
*/
|
|
47
|
+
declare function extractTimeFromUTC(utc: UTCOffset): `-${ClockTime}` | ClockTime;
|
|
48
|
+
/**
|
|
49
|
+
* * Converts a UTC value in `UTC-01:30` or `UTC+01:30` format into total minutes in number.
|
|
50
|
+
*
|
|
51
|
+
* @param time - UTC value in `UTC-01:30` or `UTC+01:30` format.
|
|
52
|
+
* @returns The total minutes elapsed since `00:00`.
|
|
53
|
+
*/
|
|
54
|
+
declare function extractMinutesFromUTC(utc: UTCOffset): number;
|
|
55
|
+
/**
|
|
56
|
+
* * Converts a number of minutes into a time string in "HH:MM" format.
|
|
57
|
+
*
|
|
58
|
+
* @param minutes - The number of minutes to convert. Can be a number or a numeric string.
|
|
59
|
+
* @returns A string representing the time in "HH:MM" format.
|
|
60
|
+
*
|
|
61
|
+
* @remarks Always returns the absolute value of the minutes, ignoring the sign if they are negative.
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* convertMinutesToTime(75); // "1:15"
|
|
65
|
+
* convertMinutesToTime(-45); // "0:45"
|
|
66
|
+
*/
|
|
67
|
+
declare function convertMinutesToTime(minutes: Numeric): HourMinutes;
|
|
68
|
+
/**
|
|
69
|
+
* * Converts a minute-based offset to a UTC offset string in the format `UTC±HH:MM`.
|
|
70
|
+
*
|
|
71
|
+
* @param minutes - The offset in minutes (positive or negative).
|
|
72
|
+
* @returns A formatted UTC offset string like `UTC+05:30` or `UTC-04:00`.
|
|
73
|
+
*/
|
|
74
|
+
declare function formatUTCOffset(minutes: Numeric): UTCOffset;
|
|
75
|
+
/** Get the current system's time zone identifier using {@link Intl.DateTimeFormat} API. */
|
|
76
|
+
declare function getNativeTimeZoneId(): TimeZoneIdNative;
|
|
77
|
+
/**
|
|
78
|
+
* * Retrieves comprehensive time zone details using the {@link Intl.DateTimeFormat} API.
|
|
79
|
+
* @param tzId Optional timezone identifier. Defaults to the system timezone.
|
|
80
|
+
* @param date Optional date for which to resolve the information.
|
|
81
|
+
* @returns Object containing time zone identifier, names, and offset.
|
|
82
|
+
*/
|
|
83
|
+
declare function getTimeZoneDetails(tzId?: $TimeZoneIdentifier, date?: Date): TimeZoneDetails;
|
|
84
|
+
/**
|
|
85
|
+
* * Resolves all IANA time-zone identifiers that match a given UTC offset.
|
|
86
|
+
*
|
|
87
|
+
* @remarks
|
|
88
|
+
* - Uses an internal in-memory cache that persists for the lifetime of the running application.
|
|
89
|
+
* - The cache is lazily populated so the `offset`-to-`time-zone` mapping is computed only once per offset.
|
|
90
|
+
* - Offset and time-zone identifier detection uses the {@link Intl.DateTimeFormat} API.
|
|
91
|
+
*
|
|
92
|
+
* @param offset The UTC offset in `"UTC±HH:MM"` format.
|
|
93
|
+
* @returns An array of matching IANA time-zone identifiers, or an empty array if the offset is invalid.
|
|
94
|
+
*/
|
|
95
|
+
declare function getTimeZoneIds(offset: UTCOffset): TimeZoneIdNative[];
|
|
96
|
+
/**
|
|
97
|
+
* * Formats a date into a specified string format.
|
|
98
|
+
*
|
|
99
|
+
* @param options Options to control date and time formatting.
|
|
100
|
+
*
|
|
101
|
+
* @remarks
|
|
102
|
+
* - If no date is provided, the current date and time will be used.
|
|
103
|
+
* - If the provided date is invalid, the function will return `'Invalid Date!'`.
|
|
104
|
+
* - The default format is `'dd, mmm DD, YYYY HH:mm:ss'` (e.g., `'Sun, Apr 06, 2025 16:11:55'`).
|
|
105
|
+
* - By default, local time is used; set `useUTC` to `true` to format in UTC.
|
|
106
|
+
* - The format string supports various tokens for date and time components, as well as literal text enclosed in square brackets.
|
|
107
|
+
* - See {@link https://toolbox.nazmul-nhb.dev/docs/utilities/date/formatDate#format-tokens format tokens} for details on supported tokens.
|
|
108
|
+
* - For more complex date/time manipulations, consider using the {@link https://toolbox.nazmul-nhb.dev/docs/classes/Chronos Chronos} class.
|
|
109
|
+
*
|
|
110
|
+
* @returns Date/time string in specified format.
|
|
111
|
+
*/
|
|
112
|
+
declare function formatDate(options?: DateFormatOptions): string;
|
|
113
|
+
/**
|
|
114
|
+
* * Formats a time-only string into a formatted time string.
|
|
115
|
+
*
|
|
116
|
+
* @param time - Time string to be formatted. Supported formats include:
|
|
117
|
+
* - `HH:mm` → e.g., `'14:50'`
|
|
118
|
+
* - `HH:mm:ss` → e.g., `'14:50:00'`
|
|
119
|
+
* - `HH:mm:ss.mss` → e.g., `'14:50:00.800'`
|
|
120
|
+
* - `HH:mm+TimeZoneOffset(HH)` → e.g., `'14:50+06'`
|
|
121
|
+
* - `HH:mm+TimeZoneOffset(HH:mm)` → e.g., `'14:50+06:00'`
|
|
122
|
+
* - `HH:mm:ss+TimeZoneOffset(HH)` → e.g., `'14:50:00+06'`
|
|
123
|
+
* - `HH:mm:ss+TimeZoneOffset(HH:mm)` → e.g., `'14:50:00+05:30'`
|
|
124
|
+
* - `HH:mm:ss.mss+TimeZoneOffset(HH)` → e.g., `'14:50:00.800+06'`
|
|
125
|
+
* - `HH:mm:ss.mss+TimeZoneOffset(HH:mm)` → e.g., `'14:50:00.800+06:30'`
|
|
126
|
+
*
|
|
127
|
+
* - *Input will default to today's date and assume local timezone if no offset is provided.*
|
|
128
|
+
*
|
|
129
|
+
* @param format - Format tokens accepted by {@link formatDate} method ({@link TimeOnlyFormat}) for time part only.
|
|
130
|
+
* Default: `hh:mm:ss a` → 02:33:36 pm.
|
|
131
|
+
* @returns Formatted time string in local (System) time.
|
|
132
|
+
*/
|
|
133
|
+
declare function formatTimePart(time: string, format?: TimeOnlyFormat): string;
|
|
134
|
+
/**
|
|
135
|
+
* * Formats a date as a relative time string (e.g., "5m ago", "2h from now").
|
|
136
|
+
*
|
|
137
|
+
* @param date - The date to format, which can be a `Date` object, a date string, or a timestamp number.
|
|
138
|
+
* @param format - Optional format string for dates older than 7 days. Defaults to `'mmm D, yyyy hh:mm a'`.
|
|
139
|
+
* @returns A relative time string if the date is within the last 7 days, otherwise a formatted date string.
|
|
140
|
+
*
|
|
141
|
+
* @remarks
|
|
142
|
+
* - If date is provided but `undefined`, current date and time will be used.
|
|
143
|
+
* - If the provided date is invalid, the function will return `'Invalid Date!'`.
|
|
144
|
+
* - For dates within the last 7 days, the output will be in the format of "Xm ago" or "Xh from now".
|
|
145
|
+
* - For dates older than 7 days, the output will be formatted using the provided `format` string or the default format if none is provided.
|
|
146
|
+
*
|
|
147
|
+
* @example
|
|
148
|
+
* formatDateRelative(Date.now() - 5 * 60000); // "5m ago"
|
|
149
|
+
* formatDateRelative(Date.now() + 2 * 3600000); // "2h from now"
|
|
150
|
+
* formatDateRelative(Date.now() - 10 * 86400000); // "Apr 6, 2026 04:11 PM" (formatted date string)
|
|
151
|
+
*/
|
|
152
|
+
declare function formatDateRelative(date: Maybe<DateArgs>, format?: StrictFormat): string;
|
|
153
|
+
/**
|
|
154
|
+
* * Get timestamp in ISO 8601 format for the current date and time.
|
|
155
|
+
*
|
|
156
|
+
* @returns Timestamp string in ISO 8601 format.
|
|
157
|
+
*/
|
|
158
|
+
declare function getTimestamp(): ISOTimeString;
|
|
159
|
+
/**
|
|
160
|
+
* * Get timestamp in ISO 8601 format.
|
|
161
|
+
*
|
|
162
|
+
* @param value - Date value to convert to timestamp. Supported formats include:
|
|
163
|
+
* - `Date` object → e.g., `new Date()`
|
|
164
|
+
* - Date string → e.g., `'2025-04-06'`, `'2025-04-06 16:11:55'`, `'April 6, 2025 16:11:55'` etc.
|
|
165
|
+
* - Timestamp number → e.g., `1712748715000`
|
|
166
|
+
* @param format - Format of the output timestamp.
|
|
167
|
+
* - Use `format: 'local'` to include the current system timezone offset.
|
|
168
|
+
* - Default is `'utc'` which returns timestamp in UTC format (ending with 'Z').
|
|
169
|
+
*
|
|
170
|
+
* @remarks If the provided {@link value} is invalid, the current date and time will be used.
|
|
171
|
+
*
|
|
172
|
+
* @returns Timestamp string in ISO 8601 format.
|
|
173
|
+
*/
|
|
174
|
+
declare function getTimestamp(value: DateArgs, format?: ISODateFormat): ISOTimeString;
|
|
175
|
+
/**
|
|
176
|
+
* * Get timestamp in ISO 8601 format.
|
|
177
|
+
*
|
|
178
|
+
* @param options Options to control date input and output format.
|
|
179
|
+
*
|
|
180
|
+
* @remarks
|
|
181
|
+
* - If the provided {@link TimestampOptions.value value} is invalid, the current date and time will be used.
|
|
182
|
+
* - Use {@link TimestampOptions.format format}: `'local'` to include the current system time & timezone offset.
|
|
183
|
+
*
|
|
184
|
+
* @returns Timestamp string in ISO 8601 format.
|
|
185
|
+
*/
|
|
186
|
+
declare function getTimestamp(options: TimestampOptions): ISOTimeString;
|
|
187
|
+
//#endregion
|
|
188
|
+
export { convertMinutesToTime as convertMinutesToHourMinutes, convertMinutesToTime, convertMinutesToTime as getHourMinutesFromMinutes, convertMinutesToTime as getTimeFromMinutes, formatUTCOffset as convertMinutesToUTCOffset, formatUTCOffset, formatUTCOffset as minutesToUTCOffset, extractHourMinute, extractMinutesFromUTC, extractMinutesFromUTC as getMinutesFromUTC, extractMinutesFromUTC as getTotalMinutesFromUTC, extractTimeFromUTC, extractTimeFromUTC as extractTimeStringFromUTC, extractTimeFromUTC as getTimeStringFromUTC, getTotalMinutes as extractTotalMinutesFromTime, getTotalMinutes, getTotalMinutes as getTotalMinutesFromTime, formatDate, formatDate as formatDateTime, formatDateRelative, formatDateRelative as formatRelativeDate, formatDateRelative as formatRelativeTime, formatTimePart, getGreeting as generateGreeting, getGreeting, getGreeting as greet, getNativeTimeZoneId, getTimeZoneDetails, getTimeZoneIds, getTimestamp, parseMSec, parseMSec as parseMs };
|
package/dist/utils.d.mts
ADDED
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import { At as TimeZoneDetails, Cn as Numeric, It as TimestampOptions, Mt as TimeZoneIdNative, Ot as TimeWithUnit, Rt as UTCOffset, Sn as Maybe, X as $TimeZoneIdentifier, _n as StrictFormat, at as DateFormatOptions, dt as GreetingConfigs, ft as HourMinutes, ht as ISOTimeString, it as DateArgs, pt as ISODateFormat, rt as ClockTime, yn as TimeOnlyFormat } from "./types-B2fgrJ86.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/utils/greet.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* * Returns a greeting message based on the provided time or current time.
|
|
6
|
+
*
|
|
7
|
+
* @param configs - Configuration options for greeting times and messages.
|
|
8
|
+
* @returns The appropriate greeting message.
|
|
9
|
+
*/
|
|
10
|
+
declare function getGreeting(configs?: GreetingConfigs): string;
|
|
11
|
+
//#endregion
|
|
12
|
+
//#region src/utils/parser.d.ts
|
|
13
|
+
/**
|
|
14
|
+
* * Parse the given value to milliseconds or optionally to seconds.
|
|
15
|
+
*
|
|
16
|
+
* @param value - The string (with unit) or number (or numeric string) to convert.
|
|
17
|
+
* @param sec - Whether to return the value in seconds. Defaults to `false`.
|
|
18
|
+
* @returns The given value parsed in milliseconds (or seconds if specified).
|
|
19
|
+
*
|
|
20
|
+
* @remarks
|
|
21
|
+
* - A numeric value (number or numeric string ({@link Numeric})) is interpreted as seconds count, e.g., `120` or `'120'` will be treated as `'120 seconds'`.
|
|
22
|
+
* - If you use time value with unit ({@link TimeWithUnit}) be sure you provide the time units (days, hours, etc.), otherwise it will return `NaN`, e.g., `'120 unknown'` will return `NaN`.
|
|
23
|
+
*/
|
|
24
|
+
declare function parseMSec(value: TimeWithUnit | Numeric, sec?: boolean): number;
|
|
25
|
+
//#endregion
|
|
26
|
+
//#region src/utils/utilities.d.ts
|
|
27
|
+
/**
|
|
28
|
+
* * Extracts the hour and minute from a time string in `HH:MM` or `-HH:MM` format.
|
|
29
|
+
*
|
|
30
|
+
* @param time - The time string to extract from.
|
|
31
|
+
* @return The extracted hour and minute as number tuple.
|
|
32
|
+
*/
|
|
33
|
+
declare function extractHourMinute(time: `-${ClockTime}` | ClockTime): [number, number];
|
|
34
|
+
/**
|
|
35
|
+
* * Converts a time string `HH:MM` or `-HH:MM` into total minutes from `00:00`.
|
|
36
|
+
*
|
|
37
|
+
* @param time - The time in `HH:MM` or `-HH:MM` format.
|
|
38
|
+
* @returns The total minutes elapsed since `00:00`.
|
|
39
|
+
*/
|
|
40
|
+
declare function getTotalMinutes(time: `-${ClockTime}` | ClockTime): number;
|
|
41
|
+
/**
|
|
42
|
+
* * Extract Time in `HH:MM` format from given UTC value.
|
|
43
|
+
*
|
|
44
|
+
* @param utc UTC value in `UTC-01:30` or `UTC+01:30` format.
|
|
45
|
+
* @returns The UTC value in `HH:MM` format.
|
|
46
|
+
*/
|
|
47
|
+
declare function extractTimeFromUTC(utc: UTCOffset): `-${ClockTime}` | ClockTime;
|
|
48
|
+
/**
|
|
49
|
+
* * Converts a UTC value in `UTC-01:30` or `UTC+01:30` format into total minutes in number.
|
|
50
|
+
*
|
|
51
|
+
* @param time - UTC value in `UTC-01:30` or `UTC+01:30` format.
|
|
52
|
+
* @returns The total minutes elapsed since `00:00`.
|
|
53
|
+
*/
|
|
54
|
+
declare function extractMinutesFromUTC(utc: UTCOffset): number;
|
|
55
|
+
/**
|
|
56
|
+
* * Converts a number of minutes into a time string in "HH:MM" format.
|
|
57
|
+
*
|
|
58
|
+
* @param minutes - The number of minutes to convert. Can be a number or a numeric string.
|
|
59
|
+
* @returns A string representing the time in "HH:MM" format.
|
|
60
|
+
*
|
|
61
|
+
* @remarks Always returns the absolute value of the minutes, ignoring the sign if they are negative.
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* convertMinutesToTime(75); // "1:15"
|
|
65
|
+
* convertMinutesToTime(-45); // "0:45"
|
|
66
|
+
*/
|
|
67
|
+
declare function convertMinutesToTime(minutes: Numeric): HourMinutes;
|
|
68
|
+
/**
|
|
69
|
+
* * Converts a minute-based offset to a UTC offset string in the format `UTC±HH:MM`.
|
|
70
|
+
*
|
|
71
|
+
* @param minutes - The offset in minutes (positive or negative).
|
|
72
|
+
* @returns A formatted UTC offset string like `UTC+05:30` or `UTC-04:00`.
|
|
73
|
+
*/
|
|
74
|
+
declare function formatUTCOffset(minutes: Numeric): UTCOffset;
|
|
75
|
+
/** Get the current system's time zone identifier using {@link Intl.DateTimeFormat} API. */
|
|
76
|
+
declare function getNativeTimeZoneId(): TimeZoneIdNative;
|
|
77
|
+
/**
|
|
78
|
+
* * Retrieves comprehensive time zone details using the {@link Intl.DateTimeFormat} API.
|
|
79
|
+
* @param tzId Optional timezone identifier. Defaults to the system timezone.
|
|
80
|
+
* @param date Optional date for which to resolve the information.
|
|
81
|
+
* @returns Object containing time zone identifier, names, and offset.
|
|
82
|
+
*/
|
|
83
|
+
declare function getTimeZoneDetails(tzId?: $TimeZoneIdentifier, date?: Date): TimeZoneDetails;
|
|
84
|
+
/**
|
|
85
|
+
* * Resolves all IANA time-zone identifiers that match a given UTC offset.
|
|
86
|
+
*
|
|
87
|
+
* @remarks
|
|
88
|
+
* - Uses an internal in-memory cache that persists for the lifetime of the running application.
|
|
89
|
+
* - The cache is lazily populated so the `offset`-to-`time-zone` mapping is computed only once per offset.
|
|
90
|
+
* - Offset and time-zone identifier detection uses the {@link Intl.DateTimeFormat} API.
|
|
91
|
+
*
|
|
92
|
+
* @param offset The UTC offset in `"UTC±HH:MM"` format.
|
|
93
|
+
* @returns An array of matching IANA time-zone identifiers, or an empty array if the offset is invalid.
|
|
94
|
+
*/
|
|
95
|
+
declare function getTimeZoneIds(offset: UTCOffset): TimeZoneIdNative[];
|
|
96
|
+
/**
|
|
97
|
+
* * Formats a date into a specified string format.
|
|
98
|
+
*
|
|
99
|
+
* @param options Options to control date and time formatting.
|
|
100
|
+
*
|
|
101
|
+
* @remarks
|
|
102
|
+
* - If no date is provided, the current date and time will be used.
|
|
103
|
+
* - If the provided date is invalid, the function will return `'Invalid Date!'`.
|
|
104
|
+
* - The default format is `'dd, mmm DD, YYYY HH:mm:ss'` (e.g., `'Sun, Apr 06, 2025 16:11:55'`).
|
|
105
|
+
* - By default, local time is used; set `useUTC` to `true` to format in UTC.
|
|
106
|
+
* - The format string supports various tokens for date and time components, as well as literal text enclosed in square brackets.
|
|
107
|
+
* - See {@link https://toolbox.nazmul-nhb.dev/docs/utilities/date/formatDate#format-tokens format tokens} for details on supported tokens.
|
|
108
|
+
* - For more complex date/time manipulations, consider using the {@link https://toolbox.nazmul-nhb.dev/docs/classes/Chronos Chronos} class.
|
|
109
|
+
*
|
|
110
|
+
* @returns Date/time string in specified format.
|
|
111
|
+
*/
|
|
112
|
+
declare function formatDate(options?: DateFormatOptions): string;
|
|
113
|
+
/**
|
|
114
|
+
* * Formats a time-only string into a formatted time string.
|
|
115
|
+
*
|
|
116
|
+
* @param time - Time string to be formatted. Supported formats include:
|
|
117
|
+
* - `HH:mm` → e.g., `'14:50'`
|
|
118
|
+
* - `HH:mm:ss` → e.g., `'14:50:00'`
|
|
119
|
+
* - `HH:mm:ss.mss` → e.g., `'14:50:00.800'`
|
|
120
|
+
* - `HH:mm+TimeZoneOffset(HH)` → e.g., `'14:50+06'`
|
|
121
|
+
* - `HH:mm+TimeZoneOffset(HH:mm)` → e.g., `'14:50+06:00'`
|
|
122
|
+
* - `HH:mm:ss+TimeZoneOffset(HH)` → e.g., `'14:50:00+06'`
|
|
123
|
+
* - `HH:mm:ss+TimeZoneOffset(HH:mm)` → e.g., `'14:50:00+05:30'`
|
|
124
|
+
* - `HH:mm:ss.mss+TimeZoneOffset(HH)` → e.g., `'14:50:00.800+06'`
|
|
125
|
+
* - `HH:mm:ss.mss+TimeZoneOffset(HH:mm)` → e.g., `'14:50:00.800+06:30'`
|
|
126
|
+
*
|
|
127
|
+
* - *Input will default to today's date and assume local timezone if no offset is provided.*
|
|
128
|
+
*
|
|
129
|
+
* @param format - Format tokens accepted by {@link formatDate} method ({@link TimeOnlyFormat}) for time part only.
|
|
130
|
+
* Default: `hh:mm:ss a` → 02:33:36 pm.
|
|
131
|
+
* @returns Formatted time string in local (System) time.
|
|
132
|
+
*/
|
|
133
|
+
declare function formatTimePart(time: string, format?: TimeOnlyFormat): string;
|
|
134
|
+
/**
|
|
135
|
+
* * Formats a date as a relative time string (e.g., "5m ago", "2h from now").
|
|
136
|
+
*
|
|
137
|
+
* @param date - The date to format, which can be a `Date` object, a date string, or a timestamp number.
|
|
138
|
+
* @param format - Optional format string for dates older than 7 days. Defaults to `'mmm D, yyyy hh:mm a'`.
|
|
139
|
+
* @returns A relative time string if the date is within the last 7 days, otherwise a formatted date string.
|
|
140
|
+
*
|
|
141
|
+
* @remarks
|
|
142
|
+
* - If date is provided but `undefined`, current date and time will be used.
|
|
143
|
+
* - If the provided date is invalid, the function will return `'Invalid Date!'`.
|
|
144
|
+
* - For dates within the last 7 days, the output will be in the format of "Xm ago" or "Xh from now".
|
|
145
|
+
* - For dates older than 7 days, the output will be formatted using the provided `format` string or the default format if none is provided.
|
|
146
|
+
*
|
|
147
|
+
* @example
|
|
148
|
+
* formatDateRelative(Date.now() - 5 * 60000); // "5m ago"
|
|
149
|
+
* formatDateRelative(Date.now() + 2 * 3600000); // "2h from now"
|
|
150
|
+
* formatDateRelative(Date.now() - 10 * 86400000); // "Apr 6, 2026 04:11 PM" (formatted date string)
|
|
151
|
+
*/
|
|
152
|
+
declare function formatDateRelative(date: Maybe<DateArgs>, format?: StrictFormat): string;
|
|
153
|
+
/**
|
|
154
|
+
* * Get timestamp in ISO 8601 format for the current date and time.
|
|
155
|
+
*
|
|
156
|
+
* @returns Timestamp string in ISO 8601 format.
|
|
157
|
+
*/
|
|
158
|
+
declare function getTimestamp(): ISOTimeString;
|
|
159
|
+
/**
|
|
160
|
+
* * Get timestamp in ISO 8601 format.
|
|
161
|
+
*
|
|
162
|
+
* @param value - Date value to convert to timestamp. Supported formats include:
|
|
163
|
+
* - `Date` object → e.g., `new Date()`
|
|
164
|
+
* - Date string → e.g., `'2025-04-06'`, `'2025-04-06 16:11:55'`, `'April 6, 2025 16:11:55'` etc.
|
|
165
|
+
* - Timestamp number → e.g., `1712748715000`
|
|
166
|
+
* @param format - Format of the output timestamp.
|
|
167
|
+
* - Use `format: 'local'` to include the current system timezone offset.
|
|
168
|
+
* - Default is `'utc'` which returns timestamp in UTC format (ending with 'Z').
|
|
169
|
+
*
|
|
170
|
+
* @remarks If the provided {@link value} is invalid, the current date and time will be used.
|
|
171
|
+
*
|
|
172
|
+
* @returns Timestamp string in ISO 8601 format.
|
|
173
|
+
*/
|
|
174
|
+
declare function getTimestamp(value: DateArgs, format?: ISODateFormat): ISOTimeString;
|
|
175
|
+
/**
|
|
176
|
+
* * Get timestamp in ISO 8601 format.
|
|
177
|
+
*
|
|
178
|
+
* @param options Options to control date input and output format.
|
|
179
|
+
*
|
|
180
|
+
* @remarks
|
|
181
|
+
* - If the provided {@link TimestampOptions.value value} is invalid, the current date and time will be used.
|
|
182
|
+
* - Use {@link TimestampOptions.format format}: `'local'` to include the current system time & timezone offset.
|
|
183
|
+
*
|
|
184
|
+
* @returns Timestamp string in ISO 8601 format.
|
|
185
|
+
*/
|
|
186
|
+
declare function getTimestamp(options: TimestampOptions): ISOTimeString;
|
|
187
|
+
//#endregion
|
|
188
|
+
export { convertMinutesToTime as convertMinutesToHourMinutes, convertMinutesToTime, convertMinutesToTime as getHourMinutesFromMinutes, convertMinutesToTime as getTimeFromMinutes, formatUTCOffset as convertMinutesToUTCOffset, formatUTCOffset, formatUTCOffset as minutesToUTCOffset, extractHourMinute, extractMinutesFromUTC, extractMinutesFromUTC as getMinutesFromUTC, extractMinutesFromUTC as getTotalMinutesFromUTC, extractTimeFromUTC, extractTimeFromUTC as extractTimeStringFromUTC, extractTimeFromUTC as getTimeStringFromUTC, getTotalMinutes as extractTotalMinutesFromTime, getTotalMinutes, getTotalMinutes as getTotalMinutesFromTime, formatDate, formatDate as formatDateTime, formatDateRelative, formatDateRelative as formatRelativeDate, formatDateRelative as formatRelativeTime, formatTimePart, getGreeting as generateGreeting, getGreeting, getGreeting as greet, getNativeTimeZoneId, getTimeZoneDetails, getTimeZoneIds, getTimestamp, parseMSec, parseMSec as parseMs };
|
package/dist/utils.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{l as e}from"./basic-e46DaNAi.mjs";import{n as t,r as n}from"./primitives-Cxss_JVF.mjs";import{a as r}from"./utilities-BJE06bms.mjs";import{isTimeWithUnit as i}from"./guards.mjs";import{a,c as o,d as s,f as c,i as l,l as u,n as d,o as f,p,r as m,s as h,t as g,u as _}from"./utilities-DV_ohS37.mjs";import{t as v}from"./greet-BBsrvmkn.mjs";function y(e,t=!1){return n(e)||r(e)?b(`${e}s`,t):i(e)?b(e,t):NaN}function b(n,r=!1){if(!t(n)||n.length>100)throw RangeError(`Value must be a string with length between 1 and 99!`);let i=/^(?<value>-?\d*\.?\d+) *(?<unit>milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|months?|mo|years?|yrs?|y)?$/i.exec(n);if(!i?.groups)return NaN;let a=(i.groups.unit??`ms`).toLowerCase(),o=e[a];if(!o)throw RangeError(`Unknown unit "${a}"!`);let s=parseFloat(i.groups.value)*o;return r?s/1e3:s}export{g as convertMinutesToHourMinutes,g as convertMinutesToTime,g as getHourMinutesFromMinutes,g as getTimeFromMinutes,o as convertMinutesToUTCOffset,o as formatUTCOffset,o as minutesToUTCOffset,d as extractHourMinute,m as extractMinutesFromUTC,m as getMinutesFromUTC,m as getTotalMinutesFromUTC,l as extractTimeFromUTC,l as extractTimeStringFromUTC,l as getTimeStringFromUTC,p as extractTotalMinutesFromTime,p as getTotalMinutes,p as getTotalMinutesFromTime,a as formatDate,a as formatDateTime,f as formatDateRelative,f as formatRelativeDate,f as formatRelativeTime,h as formatTimePart,v as generateGreeting,v as getGreeting,v as greet,u as getNativeTimeZoneId,_ as getTimeZoneDetails,s as getTimeZoneIds,c as getTimestamp,y as parseMSec,y as parseMs};
|
package/package.json
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "chronos-date",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Flexible date-time library for any JavaScript and TypeScript environment.",
|
|
5
|
+
"main": "./dist/index.cjs",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"sideEffects": false,
|
|
8
|
+
"keywords": [
|
|
9
|
+
"time",
|
|
10
|
+
"date",
|
|
11
|
+
"chronos-date",
|
|
12
|
+
"date-utilities",
|
|
13
|
+
"date-helper",
|
|
14
|
+
"date-utils",
|
|
15
|
+
"date-tools",
|
|
16
|
+
"timezone"
|
|
17
|
+
],
|
|
18
|
+
"publishConfig": {
|
|
19
|
+
"access": "public"
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"dist",
|
|
23
|
+
"LICENSE",
|
|
24
|
+
"README.md",
|
|
25
|
+
"package.json"
|
|
26
|
+
],
|
|
27
|
+
"repository": {
|
|
28
|
+
"type": "git",
|
|
29
|
+
"url": "git+https://github.com/nazmul-nhb/chronos-date.git"
|
|
30
|
+
},
|
|
31
|
+
"homepage": "https://github.com/nazmul-nhb/chronos-date#readme",
|
|
32
|
+
"author": {
|
|
33
|
+
"name": "Nazmul Hassan",
|
|
34
|
+
"email": "nazmulnhb@gmail.com",
|
|
35
|
+
"url": "https://nazmul-nhb.dev"
|
|
36
|
+
},
|
|
37
|
+
"contributors": [
|
|
38
|
+
{
|
|
39
|
+
"name": "Nazmul Hassan",
|
|
40
|
+
"email": "nazmulnhb007@yahoo.com",
|
|
41
|
+
"url": "https://github.com/nazmul-nhb"
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
"name": "Nazmul Hassan",
|
|
45
|
+
"email": "nazmulnhb@gmail.com",
|
|
46
|
+
"url": "https://github.com/nhb-nazmul"
|
|
47
|
+
}
|
|
48
|
+
],
|
|
49
|
+
"bugs": {
|
|
50
|
+
"url": "https://github.com/nazmul-nhb/chronos-date/issues",
|
|
51
|
+
"email": "nazmulnhb@gmail.com"
|
|
52
|
+
},
|
|
53
|
+
"license": "Apache-2.0",
|
|
54
|
+
"devDependencies": {
|
|
55
|
+
"@biomejs/biome": "^2.4.14",
|
|
56
|
+
"@types/node": "^25.6.2",
|
|
57
|
+
"husky": "^9.1.7",
|
|
58
|
+
"lint-staged": "^17.0.3",
|
|
59
|
+
"nhb-scripts": "^1.9.2",
|
|
60
|
+
"nhb-toolbox": "^4.30.1",
|
|
61
|
+
"tsdown": "^0.22.0",
|
|
62
|
+
"typescript": "^6.0.3"
|
|
63
|
+
},
|
|
64
|
+
"lint-staged": {
|
|
65
|
+
"*.+((c|m)?js(x)?|(c|m)?ts(x)?)": [
|
|
66
|
+
"biome format --write --diagnostic-level=error",
|
|
67
|
+
"biome lint --diagnostic-level=error"
|
|
68
|
+
]
|
|
69
|
+
},
|
|
70
|
+
"module": "./dist/index.mjs",
|
|
71
|
+
"types": "./dist/index.d.cts",
|
|
72
|
+
"exports": {
|
|
73
|
+
".": {
|
|
74
|
+
"import": "./dist/index.mjs",
|
|
75
|
+
"require": "./dist/index.cjs"
|
|
76
|
+
},
|
|
77
|
+
"./constants": {
|
|
78
|
+
"import": "./dist/constants.mjs",
|
|
79
|
+
"require": "./dist/constants.cjs"
|
|
80
|
+
},
|
|
81
|
+
"./guards": {
|
|
82
|
+
"import": "./dist/guards.mjs",
|
|
83
|
+
"require": "./dist/guards.cjs"
|
|
84
|
+
},
|
|
85
|
+
"./plugins/banglaPlugin": {
|
|
86
|
+
"import": "./dist/plugins/banglaPlugin.mjs",
|
|
87
|
+
"require": "./dist/plugins/banglaPlugin.cjs"
|
|
88
|
+
},
|
|
89
|
+
"./plugins/businessPlugin": {
|
|
90
|
+
"import": "./dist/plugins/businessPlugin.mjs",
|
|
91
|
+
"require": "./dist/plugins/businessPlugin.cjs"
|
|
92
|
+
},
|
|
93
|
+
"./plugins/dateRangePlugin": {
|
|
94
|
+
"import": "./dist/plugins/dateRangePlugin.mjs",
|
|
95
|
+
"require": "./dist/plugins/dateRangePlugin.cjs"
|
|
96
|
+
},
|
|
97
|
+
"./plugins/dayPartPlugin": {
|
|
98
|
+
"import": "./dist/plugins/dayPartPlugin.mjs",
|
|
99
|
+
"require": "./dist/plugins/dayPartPlugin.cjs"
|
|
100
|
+
},
|
|
101
|
+
"./plugins/durationPlugin": {
|
|
102
|
+
"import": "./dist/plugins/durationPlugin.mjs",
|
|
103
|
+
"require": "./dist/plugins/durationPlugin.cjs"
|
|
104
|
+
},
|
|
105
|
+
"./plugins/fromNowPlugin": {
|
|
106
|
+
"import": "./dist/plugins/fromNowPlugin.mjs",
|
|
107
|
+
"require": "./dist/plugins/fromNowPlugin.cjs"
|
|
108
|
+
},
|
|
109
|
+
"./plugins/greetingPlugin": {
|
|
110
|
+
"import": "./dist/plugins/greetingPlugin.mjs",
|
|
111
|
+
"require": "./dist/plugins/greetingPlugin.cjs"
|
|
112
|
+
},
|
|
113
|
+
"./plugins/palindromePlugin": {
|
|
114
|
+
"import": "./dist/plugins/palindromePlugin.mjs",
|
|
115
|
+
"require": "./dist/plugins/palindromePlugin.cjs"
|
|
116
|
+
},
|
|
117
|
+
"./plugins/relativeTimePlugin": {
|
|
118
|
+
"import": "./dist/plugins/relativeTimePlugin.mjs",
|
|
119
|
+
"require": "./dist/plugins/relativeTimePlugin.cjs"
|
|
120
|
+
},
|
|
121
|
+
"./plugins/roundPlugin": {
|
|
122
|
+
"import": "./dist/plugins/roundPlugin.mjs",
|
|
123
|
+
"require": "./dist/plugins/roundPlugin.cjs"
|
|
124
|
+
},
|
|
125
|
+
"./plugins/seasonPlugin": {
|
|
126
|
+
"import": "./dist/plugins/seasonPlugin.mjs",
|
|
127
|
+
"require": "./dist/plugins/seasonPlugin.cjs"
|
|
128
|
+
},
|
|
129
|
+
"./plugins/timeZonePlugin": {
|
|
130
|
+
"import": "./dist/plugins/timeZonePlugin.mjs",
|
|
131
|
+
"require": "./dist/plugins/timeZonePlugin.cjs"
|
|
132
|
+
},
|
|
133
|
+
"./plugins/zodiacPlugin": {
|
|
134
|
+
"import": "./dist/plugins/zodiacPlugin.mjs",
|
|
135
|
+
"require": "./dist/plugins/zodiacPlugin.cjs"
|
|
136
|
+
},
|
|
137
|
+
"./types": {
|
|
138
|
+
"import": "./dist/types.mjs",
|
|
139
|
+
"require": "./dist/types.cjs"
|
|
140
|
+
},
|
|
141
|
+
"./utils": {
|
|
142
|
+
"import": "./dist/utils.mjs",
|
|
143
|
+
"require": "./dist/utils.cjs"
|
|
144
|
+
},
|
|
145
|
+
"./package.json": "./package.json"
|
|
146
|
+
},
|
|
147
|
+
"inlinedDependencies": {
|
|
148
|
+
"nhb-toolbox": "4.30.1"
|
|
149
|
+
},
|
|
150
|
+
"scripts": {
|
|
151
|
+
"build": "tsdown",
|
|
152
|
+
"dev:pkg": "tsdown --watch",
|
|
153
|
+
"typecheck": "tsc --noEmit",
|
|
154
|
+
"commit": "nhb-commit",
|
|
155
|
+
"count": "nhb-count",
|
|
156
|
+
"delete": "nhb-delete",
|
|
157
|
+
"lint": "biome lint --diagnostic-level=error",
|
|
158
|
+
"fix": "biome check --write --diagnostic-level=error",
|
|
159
|
+
"format": "biome format --write --diagnostic-level=error",
|
|
160
|
+
"plugin": "nhb-module -t chronos-plugin -d src/plugins"
|
|
161
|
+
}
|
|
162
|
+
}
|