chronos-date 1.0.2 → 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.
- package/dist/basic-DIp_pxR2.cjs +450 -0
- package/dist/basic-Dputob9z.mjs +366 -0
- package/dist/constants.cjs +27 -1
- package/dist/constants.mjs +5 -1
- package/dist/convert-CNVL-mop.mjs +22 -0
- package/dist/convert-dQuGWhVm.cjs +33 -0
- package/dist/greet-B8ZtypgG.cjs +40 -0
- package/dist/greet-B9j4afzD.mjs +35 -0
- package/dist/guards.cjs +119 -1
- package/dist/guards.mjs +110 -1
- package/dist/helpers-CrMc9iJZ.mjs +185 -0
- package/dist/helpers-M_SfAbAv.cjs +262 -0
- package/dist/index.cjs +1461 -1
- package/dist/index.mjs +1458 -1
- package/dist/non-primitives-CT4vszrX.cjs +52 -0
- package/dist/non-primitives-DrQfPj1r.mjs +22 -0
- package/dist/plugins/banglaPlugin.cjs +121 -1
- package/dist/plugins/banglaPlugin.mjs +120 -1
- package/dist/plugins/businessPlugin.cjs +118 -1
- package/dist/plugins/businessPlugin.mjs +117 -1
- package/dist/plugins/dateRangePlugin.cjs +46 -1
- package/dist/plugins/dateRangePlugin.mjs +45 -1
- package/dist/plugins/dayPartPlugin.cjs +26 -1
- package/dist/plugins/dayPartPlugin.mjs +25 -1
- package/dist/plugins/durationPlugin.cjs +91 -1
- package/dist/plugins/durationPlugin.mjs +90 -1
- package/dist/plugins/fromNowPlugin.cjs +80 -1
- package/dist/plugins/fromNowPlugin.mjs +79 -1
- package/dist/plugins/greetingPlugin.cjs +19 -1
- package/dist/plugins/greetingPlugin.mjs +18 -1
- package/dist/plugins/palindromePlugin.cjs +22 -1
- package/dist/plugins/palindromePlugin.mjs +21 -1
- package/dist/plugins/relativeTimePlugin.cjs +74 -1
- package/dist/plugins/relativeTimePlugin.mjs +73 -1
- package/dist/plugins/roundPlugin.cjs +69 -1
- package/dist/plugins/roundPlugin.mjs +68 -1
- package/dist/plugins/seasonPlugin.cjs +31 -1
- package/dist/plugins/seasonPlugin.mjs +30 -1
- package/dist/plugins/timeZonePlugin.cjs +139 -1
- package/dist/plugins/timeZonePlugin.mjs +138 -1
- package/dist/plugins/zodiacPlugin.cjs +51 -1
- package/dist/plugins/zodiacPlugin.mjs +50 -1
- package/dist/primitives-BME3_QrA.cjs +49 -0
- package/dist/primitives-DEt6I7Sy.mjs +19 -0
- package/dist/seasons-CHnjrIKK.mjs +352 -0
- package/dist/seasons-CcZicoe1.cjs +418 -0
- package/dist/timezone-BfBXeMK_.mjs +5573 -0
- package/dist/timezone-DYVJJYKz.cjs +5609 -0
- package/dist/types.mjs +1 -1
- package/dist/utilities-BU4MSYS7.mjs +43 -0
- package/dist/utilities-CGL7F6R9.cjs +72 -0
- package/dist/utilities-CtOZhIYv.mjs +241 -0
- package/dist/utilities-bXwTPJaD.cjs +318 -0
- package/dist/utils.cjs +76 -1
- package/dist/utils.mjs +44 -1
- package/package.json +1 -1
- package/dist/basic-CKxaRSHQ.cjs +0 -1
- package/dist/basic-e46DaNAi.mjs +0 -1
- package/dist/convert-Bmp63ats.mjs +0 -1
- package/dist/convert-DrLrcgqz.cjs +0 -1
- package/dist/greet-BBsrvmkn.mjs +0 -1
- package/dist/greet-C-6mruI9.cjs +0 -1
- package/dist/helpers-DGzYnP81.cjs +0 -1
- package/dist/helpers-N1X_Rj_V.mjs +0 -1
- package/dist/non-primitives-B2EE6D6s.mjs +0 -1
- package/dist/non-primitives-Bu3a4WL4.cjs +0 -1
- package/dist/primitives-Cxss_JVF.mjs +0 -1
- package/dist/primitives-Db2FUp4e.cjs +0 -1
- package/dist/seasons-ChAIVphi.mjs +0 -1
- package/dist/seasons-oABOhHcX.cjs +0 -1
- package/dist/timezone-B10UItNO.mjs +0 -1
- package/dist/timezone-CWxbK_7I.cjs +0 -1
- package/dist/utilities-B8dOAQVD.cjs +0 -1
- package/dist/utilities-BJE06bms.mjs +0 -1
- package/dist/utilities-D2-p26DX.cjs +0 -1
- package/dist/utilities-DV_ohS37.mjs +0 -1
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
|
|
2
|
+
//#region node_modules/.pnpm/nhb-toolbox@4.30.1/node_modules/nhb-toolbox/dist/esm/guards/non-primitives.js
|
|
3
|
+
function isArray(value) {
|
|
4
|
+
return Array.isArray(value);
|
|
5
|
+
}
|
|
6
|
+
function isValidArray(value) {
|
|
7
|
+
return Array.isArray(value) && value?.length > 0;
|
|
8
|
+
}
|
|
9
|
+
function isObject(value) {
|
|
10
|
+
return value !== null && typeof value === "object" && !isArray(value);
|
|
11
|
+
}
|
|
12
|
+
function isNotEmptyObject(value) {
|
|
13
|
+
return isObject(value) && Object.keys(value)?.length > 0;
|
|
14
|
+
}
|
|
15
|
+
function isObjectWithKeys(value, keys) {
|
|
16
|
+
return isObject(value) && keys?.every((key) => key in value);
|
|
17
|
+
}
|
|
18
|
+
function isFunction(value) {
|
|
19
|
+
return typeof value === "function";
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
//#endregion
|
|
23
|
+
Object.defineProperty(exports, 'isFunction', {
|
|
24
|
+
enumerable: true,
|
|
25
|
+
get: function () {
|
|
26
|
+
return isFunction;
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
Object.defineProperty(exports, 'isNotEmptyObject', {
|
|
30
|
+
enumerable: true,
|
|
31
|
+
get: function () {
|
|
32
|
+
return isNotEmptyObject;
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
Object.defineProperty(exports, 'isObject', {
|
|
36
|
+
enumerable: true,
|
|
37
|
+
get: function () {
|
|
38
|
+
return isObject;
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
Object.defineProperty(exports, 'isObjectWithKeys', {
|
|
42
|
+
enumerable: true,
|
|
43
|
+
get: function () {
|
|
44
|
+
return isObjectWithKeys;
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
Object.defineProperty(exports, 'isValidArray', {
|
|
48
|
+
enumerable: true,
|
|
49
|
+
get: function () {
|
|
50
|
+
return isValidArray;
|
|
51
|
+
}
|
|
52
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
//#region node_modules/.pnpm/nhb-toolbox@4.30.1/node_modules/nhb-toolbox/dist/esm/guards/non-primitives.js
|
|
2
|
+
function isArray(value) {
|
|
3
|
+
return Array.isArray(value);
|
|
4
|
+
}
|
|
5
|
+
function isValidArray(value) {
|
|
6
|
+
return Array.isArray(value) && value?.length > 0;
|
|
7
|
+
}
|
|
8
|
+
function isObject(value) {
|
|
9
|
+
return value !== null && typeof value === "object" && !isArray(value);
|
|
10
|
+
}
|
|
11
|
+
function isNotEmptyObject(value) {
|
|
12
|
+
return isObject(value) && Object.keys(value)?.length > 0;
|
|
13
|
+
}
|
|
14
|
+
function isObjectWithKeys(value, keys) {
|
|
15
|
+
return isObject(value) && keys?.every((key) => key in value);
|
|
16
|
+
}
|
|
17
|
+
function isFunction(value) {
|
|
18
|
+
return typeof value === "function";
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
//#endregion
|
|
22
|
+
export { isValidArray as a, isObjectWithKeys as i, isNotEmptyObject as n, isObject as r, isFunction as t };
|
|
@@ -1 +1,121 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,
|
|
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_utilities = require('../utilities-CGL7F6R9.cjs');
|
|
5
|
+
const require_helpers = require('../helpers-M_SfAbAv.cjs');
|
|
6
|
+
|
|
7
|
+
//#region node_modules/.pnpm/nhb-toolbox@4.30.1/node_modules/nhb-toolbox/dist/esm/number/convert.js
|
|
8
|
+
function digitToBangla(digit, preserveNonDigit = true) {
|
|
9
|
+
const banglaDigits = Object.keys(require_utilities.BN_DIGITS);
|
|
10
|
+
const _matchAndConvert = (value) => {
|
|
11
|
+
return value.replace(/\d/g, (dig) => banglaDigits[Number(dig)]);
|
|
12
|
+
};
|
|
13
|
+
if (require_primitives.isNumber(digit)) return _matchAndConvert(String(digit));
|
|
14
|
+
if (require_primitives.isNonEmptyString(digit)) {
|
|
15
|
+
const bnDigStr = _matchAndConvert(digit);
|
|
16
|
+
if (preserveNonDigit || require_utilities.isNumericString(digit)) return bnDigStr;
|
|
17
|
+
return bnDigStr.split("").filter((dig) => banglaDigits.includes(dig)).join("");
|
|
18
|
+
}
|
|
19
|
+
return "";
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
//#endregion
|
|
23
|
+
//#region src/plugins/banglaPlugin.ts
|
|
24
|
+
/** * Plugin to inject methods related to Bangla calendar system (`Bongabdo`) */
|
|
25
|
+
const banglaPlugin = ($Chronos) => {
|
|
26
|
+
const { internalDate: $Date } = $Chronos[require_basic.INTERNALS];
|
|
27
|
+
const DEFAULT_CONFIG = /* @__PURE__ */ new Map();
|
|
28
|
+
function $bnDaysMonthIdx(date, variant) {
|
|
29
|
+
return require_helpers._bnDaysMonthIdx(date, variant ?? DEFAULT_CONFIG.get("config")?.variant);
|
|
30
|
+
}
|
|
31
|
+
$Chronos.prototype.configureBanglaCalendar = function(configs) {
|
|
32
|
+
DEFAULT_CONFIG.set("config", configs);
|
|
33
|
+
};
|
|
34
|
+
$Chronos.prototype.getBanglaYear = function(locale = "bn") {
|
|
35
|
+
const bnYear = require_helpers._getBnYear($Date(this));
|
|
36
|
+
return locale === "en" ? bnYear : digitToBangla(bnYear);
|
|
37
|
+
};
|
|
38
|
+
$Chronos.prototype.getBanglaMonth = function(options) {
|
|
39
|
+
const { locale = "bn", variant } = options ?? {};
|
|
40
|
+
const isoMonth = $bnDaysMonthIdx($Date(this), variant).monthIdx + 1;
|
|
41
|
+
return locale === "en" ? isoMonth : digitToBangla(isoMonth);
|
|
42
|
+
};
|
|
43
|
+
$Chronos.prototype.getBanglaDay = function(options) {
|
|
44
|
+
const { locale = "bn", variant } = options ?? {};
|
|
45
|
+
const date = $bnDaysMonthIdx($Date(this), variant).days + 1;
|
|
46
|
+
return locale === "en" ? date : digitToBangla(date);
|
|
47
|
+
};
|
|
48
|
+
$Chronos.prototype.getBanglaDayName = function(locale = "bn") {
|
|
49
|
+
const DAY = require_basic.BN_DAYS[this.weekDay];
|
|
50
|
+
return locale === "en" ? DAY.en : DAY.bn;
|
|
51
|
+
};
|
|
52
|
+
$Chronos.prototype.getBanglaMonthName = function(options) {
|
|
53
|
+
const { locale = "bn", variant } = options ?? {};
|
|
54
|
+
const { monthIdx } = $bnDaysMonthIdx($Date(this), variant);
|
|
55
|
+
const MONTH = require_basic.BN_MONTHS[monthIdx];
|
|
56
|
+
return locale === "en" ? MONTH.en : MONTH.bn;
|
|
57
|
+
};
|
|
58
|
+
$Chronos.prototype.getBanglaSeasonName = function(options) {
|
|
59
|
+
const { locale, variant } = options ?? {};
|
|
60
|
+
const { monthIdx } = $bnDaysMonthIdx($Date(this), variant);
|
|
61
|
+
return require_helpers._getBnSeason(monthIdx, locale);
|
|
62
|
+
};
|
|
63
|
+
$Chronos.prototype.toBangla = function(opts) {
|
|
64
|
+
return {
|
|
65
|
+
year: this.getBanglaYear(opts?.locale),
|
|
66
|
+
month: this.getBanglaMonth(opts),
|
|
67
|
+
date: this.getBanglaDay(opts),
|
|
68
|
+
monthName: this.getBanglaMonthName(opts),
|
|
69
|
+
dayName: this.getBanglaDayName(opts?.locale),
|
|
70
|
+
seasonName: this.getBanglaSeasonName(opts),
|
|
71
|
+
isLeapYear: require_helpers._isBnLeapYear(require_helpers._getBnYear($Date(this)), this.year, opts?.variant)
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
$Chronos.prototype.formatBangla = function(fmt, opts) {
|
|
75
|
+
const { hour, minute, second, millisecond } = this;
|
|
76
|
+
const D_NAME = require_basic.BN_DAYS[this.weekDay];
|
|
77
|
+
const { monthIdx } = $bnDaysMonthIdx($Date(this), opts?.variant);
|
|
78
|
+
const M_NAME = require_basic.BN_MONTHS[monthIdx];
|
|
79
|
+
const month = this.getBanglaMonth();
|
|
80
|
+
const year = require_helpers._padShunno(this.getBanglaYear(), 4);
|
|
81
|
+
const date = this.getBanglaDay();
|
|
82
|
+
const seasonName = this.getBanglaSeasonName();
|
|
83
|
+
const offset = digitToBangla(this.getTimeZoneOffset());
|
|
84
|
+
const dateComponents = {
|
|
85
|
+
YYYY: year,
|
|
86
|
+
YY: year.slice(-2),
|
|
87
|
+
yyyy: year,
|
|
88
|
+
yy: year.slice(-2),
|
|
89
|
+
M: month,
|
|
90
|
+
MM: require_helpers._padShunno(month),
|
|
91
|
+
mmm: M_NAME.short,
|
|
92
|
+
mmmm: M_NAME.bn,
|
|
93
|
+
d: D_NAME.short,
|
|
94
|
+
dd: D_NAME.bn.replace("বার", ""),
|
|
95
|
+
ddd: D_NAME.bn,
|
|
96
|
+
D: date,
|
|
97
|
+
DD: require_helpers._padShunno(date),
|
|
98
|
+
Do: date,
|
|
99
|
+
H: digitToBangla(hour),
|
|
100
|
+
HH: require_helpers._padShunno(digitToBangla(hour)),
|
|
101
|
+
h: digitToBangla(hour % 12 || 12),
|
|
102
|
+
hh: require_helpers._padShunno(digitToBangla(hour % 12 || 12)),
|
|
103
|
+
m: digitToBangla(minute),
|
|
104
|
+
mm: require_helpers._padShunno(digitToBangla(minute)),
|
|
105
|
+
s: digitToBangla(second),
|
|
106
|
+
ss: require_helpers._padShunno(digitToBangla(second)),
|
|
107
|
+
ms: digitToBangla(millisecond),
|
|
108
|
+
mss: require_helpers._padShunno(digitToBangla(millisecond), 3),
|
|
109
|
+
a: hour < 12 ? "পূর্বাহ্ণ" : "অপরাহ্ণ",
|
|
110
|
+
A: hour < 12 ? "পূর্বাহ্ণ" : "অপরাহ্ণ",
|
|
111
|
+
Z: offset,
|
|
112
|
+
ZZ: offset,
|
|
113
|
+
S: seasonName,
|
|
114
|
+
SS: seasonName + "কাল"
|
|
115
|
+
};
|
|
116
|
+
return require_helpers._formatDateCore(fmt || "ddd, DD mmmm (SS), YYYY বঙ্গাব্দ - hh:mm:ss (A)", dateComponents);
|
|
117
|
+
};
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
//#endregion
|
|
121
|
+
exports.banglaPlugin = banglaPlugin;
|
|
@@ -1 +1,120 @@
|
|
|
1
|
-
import{n as
|
|
1
|
+
import { n as BN_MONTHS, s as INTERNALS, t as BN_DAYS } from "../basic-Dputob9z.mjs";
|
|
2
|
+
import { n as isNonEmptyString, r as isNumber } from "../primitives-DEt6I7Sy.mjs";
|
|
3
|
+
import { a as isNumericString, i as BN_DIGITS } from "../utilities-BU4MSYS7.mjs";
|
|
4
|
+
import { a as _getBnSeason, d as _padShunno, i as _formatDateCore, l as _isBnLeapYear, o as _getBnYear, t as _bnDaysMonthIdx } from "../helpers-CrMc9iJZ.mjs";
|
|
5
|
+
|
|
6
|
+
//#region node_modules/.pnpm/nhb-toolbox@4.30.1/node_modules/nhb-toolbox/dist/esm/number/convert.js
|
|
7
|
+
function digitToBangla(digit, preserveNonDigit = true) {
|
|
8
|
+
const banglaDigits = Object.keys(BN_DIGITS);
|
|
9
|
+
const _matchAndConvert = (value) => {
|
|
10
|
+
return value.replace(/\d/g, (dig) => banglaDigits[Number(dig)]);
|
|
11
|
+
};
|
|
12
|
+
if (isNumber(digit)) return _matchAndConvert(String(digit));
|
|
13
|
+
if (isNonEmptyString(digit)) {
|
|
14
|
+
const bnDigStr = _matchAndConvert(digit);
|
|
15
|
+
if (preserveNonDigit || isNumericString(digit)) return bnDigStr;
|
|
16
|
+
return bnDigStr.split("").filter((dig) => banglaDigits.includes(dig)).join("");
|
|
17
|
+
}
|
|
18
|
+
return "";
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
//#endregion
|
|
22
|
+
//#region src/plugins/banglaPlugin.ts
|
|
23
|
+
/** * Plugin to inject methods related to Bangla calendar system (`Bongabdo`) */
|
|
24
|
+
const banglaPlugin = ($Chronos) => {
|
|
25
|
+
const { internalDate: $Date } = $Chronos[INTERNALS];
|
|
26
|
+
const DEFAULT_CONFIG = /* @__PURE__ */ new Map();
|
|
27
|
+
function $bnDaysMonthIdx(date, variant) {
|
|
28
|
+
return _bnDaysMonthIdx(date, variant ?? DEFAULT_CONFIG.get("config")?.variant);
|
|
29
|
+
}
|
|
30
|
+
$Chronos.prototype.configureBanglaCalendar = function(configs) {
|
|
31
|
+
DEFAULT_CONFIG.set("config", configs);
|
|
32
|
+
};
|
|
33
|
+
$Chronos.prototype.getBanglaYear = function(locale = "bn") {
|
|
34
|
+
const bnYear = _getBnYear($Date(this));
|
|
35
|
+
return locale === "en" ? bnYear : digitToBangla(bnYear);
|
|
36
|
+
};
|
|
37
|
+
$Chronos.prototype.getBanglaMonth = function(options) {
|
|
38
|
+
const { locale = "bn", variant } = options ?? {};
|
|
39
|
+
const isoMonth = $bnDaysMonthIdx($Date(this), variant).monthIdx + 1;
|
|
40
|
+
return locale === "en" ? isoMonth : digitToBangla(isoMonth);
|
|
41
|
+
};
|
|
42
|
+
$Chronos.prototype.getBanglaDay = function(options) {
|
|
43
|
+
const { locale = "bn", variant } = options ?? {};
|
|
44
|
+
const date = $bnDaysMonthIdx($Date(this), variant).days + 1;
|
|
45
|
+
return locale === "en" ? date : digitToBangla(date);
|
|
46
|
+
};
|
|
47
|
+
$Chronos.prototype.getBanglaDayName = function(locale = "bn") {
|
|
48
|
+
const DAY = BN_DAYS[this.weekDay];
|
|
49
|
+
return locale === "en" ? DAY.en : DAY.bn;
|
|
50
|
+
};
|
|
51
|
+
$Chronos.prototype.getBanglaMonthName = function(options) {
|
|
52
|
+
const { locale = "bn", variant } = options ?? {};
|
|
53
|
+
const { monthIdx } = $bnDaysMonthIdx($Date(this), variant);
|
|
54
|
+
const MONTH = BN_MONTHS[monthIdx];
|
|
55
|
+
return locale === "en" ? MONTH.en : MONTH.bn;
|
|
56
|
+
};
|
|
57
|
+
$Chronos.prototype.getBanglaSeasonName = function(options) {
|
|
58
|
+
const { locale, variant } = options ?? {};
|
|
59
|
+
const { monthIdx } = $bnDaysMonthIdx($Date(this), variant);
|
|
60
|
+
return _getBnSeason(monthIdx, locale);
|
|
61
|
+
};
|
|
62
|
+
$Chronos.prototype.toBangla = function(opts) {
|
|
63
|
+
return {
|
|
64
|
+
year: this.getBanglaYear(opts?.locale),
|
|
65
|
+
month: this.getBanglaMonth(opts),
|
|
66
|
+
date: this.getBanglaDay(opts),
|
|
67
|
+
monthName: this.getBanglaMonthName(opts),
|
|
68
|
+
dayName: this.getBanglaDayName(opts?.locale),
|
|
69
|
+
seasonName: this.getBanglaSeasonName(opts),
|
|
70
|
+
isLeapYear: _isBnLeapYear(_getBnYear($Date(this)), this.year, opts?.variant)
|
|
71
|
+
};
|
|
72
|
+
};
|
|
73
|
+
$Chronos.prototype.formatBangla = function(fmt, opts) {
|
|
74
|
+
const { hour, minute, second, millisecond } = this;
|
|
75
|
+
const D_NAME = BN_DAYS[this.weekDay];
|
|
76
|
+
const { monthIdx } = $bnDaysMonthIdx($Date(this), opts?.variant);
|
|
77
|
+
const M_NAME = BN_MONTHS[monthIdx];
|
|
78
|
+
const month = this.getBanglaMonth();
|
|
79
|
+
const year = _padShunno(this.getBanglaYear(), 4);
|
|
80
|
+
const date = this.getBanglaDay();
|
|
81
|
+
const seasonName = this.getBanglaSeasonName();
|
|
82
|
+
const offset = digitToBangla(this.getTimeZoneOffset());
|
|
83
|
+
const dateComponents = {
|
|
84
|
+
YYYY: year,
|
|
85
|
+
YY: year.slice(-2),
|
|
86
|
+
yyyy: year,
|
|
87
|
+
yy: year.slice(-2),
|
|
88
|
+
M: month,
|
|
89
|
+
MM: _padShunno(month),
|
|
90
|
+
mmm: M_NAME.short,
|
|
91
|
+
mmmm: M_NAME.bn,
|
|
92
|
+
d: D_NAME.short,
|
|
93
|
+
dd: D_NAME.bn.replace("বার", ""),
|
|
94
|
+
ddd: D_NAME.bn,
|
|
95
|
+
D: date,
|
|
96
|
+
DD: _padShunno(date),
|
|
97
|
+
Do: date,
|
|
98
|
+
H: digitToBangla(hour),
|
|
99
|
+
HH: _padShunno(digitToBangla(hour)),
|
|
100
|
+
h: digitToBangla(hour % 12 || 12),
|
|
101
|
+
hh: _padShunno(digitToBangla(hour % 12 || 12)),
|
|
102
|
+
m: digitToBangla(minute),
|
|
103
|
+
mm: _padShunno(digitToBangla(minute)),
|
|
104
|
+
s: digitToBangla(second),
|
|
105
|
+
ss: _padShunno(digitToBangla(second)),
|
|
106
|
+
ms: digitToBangla(millisecond),
|
|
107
|
+
mss: _padShunno(digitToBangla(millisecond), 3),
|
|
108
|
+
a: hour < 12 ? "পূর্বাহ্ণ" : "অপরাহ্ণ",
|
|
109
|
+
A: hour < 12 ? "পূর্বাহ্ণ" : "অপরাহ্ণ",
|
|
110
|
+
Z: offset,
|
|
111
|
+
ZZ: offset,
|
|
112
|
+
S: seasonName,
|
|
113
|
+
SS: seasonName + "কাল"
|
|
114
|
+
};
|
|
115
|
+
return _formatDateCore(fmt || "ddd, DD mmmm (SS), YYYY বঙ্গাব্দ - hh:mm:ss (A)", dateComponents);
|
|
116
|
+
};
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
//#endregion
|
|
120
|
+
export { banglaPlugin };
|
|
@@ -1 +1,118 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,
|
|
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/businessPlugin.ts
|
|
7
|
+
/** * Plugin to inject `business` related methods */
|
|
8
|
+
const businessPlugin = ($Chronos) => {
|
|
9
|
+
const { internalDate: $Date, withOrigin, cast, offset } = $Chronos[require_basic.INTERNALS];
|
|
10
|
+
/** Build weekend mask (array of booleans) based on `week definition` or weekend `length` */
|
|
11
|
+
const _buildWeekendMask = (weekDef, length) => {
|
|
12
|
+
const weekendDays = require_non_primitives.isValidArray(weekDef) ? [...weekDef].sort() : Array.from({ length }, (_, i) => (weekDef + 7 - 1 - i) % 7).sort();
|
|
13
|
+
const mask = new Array(7).fill(true);
|
|
14
|
+
for (const d of weekendDays) mask[d] = false;
|
|
15
|
+
return mask;
|
|
16
|
+
};
|
|
17
|
+
/** Count workdays (`wd=true`) or weekends(`wd=false`) given a `start weekday`, `total days`, `weekend mask` and optional `step` */
|
|
18
|
+
const _countDays = (sWeek, days, mask, step = 1, wd = true) => {
|
|
19
|
+
let total = Math.floor(days / 7) * mask.filter((m) => wd ? Boolean(m) : !m).length;
|
|
20
|
+
let dayIndex = (sWeek % 7 + 7) % 7;
|
|
21
|
+
for (let i = 0; i < days % 7; i++) {
|
|
22
|
+
if (wd ? Boolean(mask[dayIndex]) : !mask[dayIndex]) total++;
|
|
23
|
+
dayIndex = (dayIndex + step + 7) % 7;
|
|
24
|
+
}
|
|
25
|
+
return total;
|
|
26
|
+
};
|
|
27
|
+
$Chronos.prototype.isWeekend = function(wDef = 0, wLen = 2) {
|
|
28
|
+
const day = $Date(this).getDay();
|
|
29
|
+
if (require_non_primitives.isValidArray(wDef)) return wDef.includes(day);
|
|
30
|
+
const lastDayOfWeek = (wDef + 6) % 7;
|
|
31
|
+
return Array.from({ length: wLen }, (_, i) => (lastDayOfWeek - i + 7) % 7).includes(day);
|
|
32
|
+
};
|
|
33
|
+
$Chronos.prototype.isWorkday = function(wDef = 0, wLen = 2) {
|
|
34
|
+
return !this.isWeekend(wDef, wLen);
|
|
35
|
+
};
|
|
36
|
+
$Chronos.prototype.nextWorkday = function(wDef = 0, wLen = 2) {
|
|
37
|
+
let nxtWrk = this.addDays(1);
|
|
38
|
+
while (nxtWrk.isWeekend(wDef, wLen)) nxtWrk = nxtWrk.addDays(1);
|
|
39
|
+
return withOrigin(nxtWrk.startOf("day"), "nextWorkday", offset(this), this.timeZoneName, this.timeZoneId, this.$tzTracker);
|
|
40
|
+
};
|
|
41
|
+
$Chronos.prototype.previousWorkday = function(wDef = 0, wLen = 2) {
|
|
42
|
+
let prevWrk = this.addDays(-1);
|
|
43
|
+
while (prevWrk.isWeekend(wDef, wLen)) prevWrk = prevWrk.addDays(-1);
|
|
44
|
+
return withOrigin(prevWrk.startOf("day"), "previousWorkday", offset(this), this.timeZoneName, this.timeZoneId, this.$tzTracker);
|
|
45
|
+
};
|
|
46
|
+
$Chronos.prototype.nextWeekend = function(wDef = 0, wLen = 2) {
|
|
47
|
+
let nxtWknd = this.addDays(1);
|
|
48
|
+
while (!nxtWknd.isWeekend(wDef, wLen)) nxtWknd = nxtWknd.addDays(1);
|
|
49
|
+
return withOrigin(nxtWknd.startOf("day"), "nextWeekend", offset(this), this.timeZoneName, this.timeZoneId, this.$tzTracker);
|
|
50
|
+
};
|
|
51
|
+
$Chronos.prototype.previousWeekend = function(wDef = 0, wLen = 2) {
|
|
52
|
+
let prevWknd = this.addDays(-1);
|
|
53
|
+
while (!prevWknd.isWeekend(wDef, wLen)) prevWknd = prevWknd.addDays(-1);
|
|
54
|
+
return withOrigin(prevWknd.startOf("day"), "previousWeekend", offset(this), this.timeZoneName, this.timeZoneId, this.$tzTracker);
|
|
55
|
+
};
|
|
56
|
+
$Chronos.prototype.workdaysBetween = function(to, wDef = 0, wLen = 2) {
|
|
57
|
+
const end = cast(to).startOf("day");
|
|
58
|
+
const start = this.startOf("day");
|
|
59
|
+
if (start.isSame(end, "day")) return 0;
|
|
60
|
+
const step = start.isBefore(end, "day") ? 1 : -1;
|
|
61
|
+
const totalDays = Math.abs(end.diff(start, "day"));
|
|
62
|
+
const weekendMask = _buildWeekendMask(wDef, wLen);
|
|
63
|
+
return _countDays((start.isoWeekDay + step) % 7, totalDays, weekendMask, step);
|
|
64
|
+
};
|
|
65
|
+
$Chronos.prototype.weekendsBetween = function(to, wDef = 0, wLen = 2) {
|
|
66
|
+
const end = cast(to).startOf("day");
|
|
67
|
+
const start = this.startOf("day");
|
|
68
|
+
if (start.isSame(end, "day")) return 0;
|
|
69
|
+
const step = start.isBefore(end, "day") ? 1 : -1;
|
|
70
|
+
const totalDays = Math.abs(end.diff(start, "day"));
|
|
71
|
+
const weekendMask = _buildWeekendMask(wDef, wLen);
|
|
72
|
+
return _countDays((start.isoWeekDay + step) % 7, totalDays, weekendMask, step, false);
|
|
73
|
+
};
|
|
74
|
+
$Chronos.prototype.workdaysInMonth = function(wDef = 0, wLen = 2) {
|
|
75
|
+
const daysInMonth = this.daysInMonth();
|
|
76
|
+
const weekendMask = _buildWeekendMask(wDef, wLen);
|
|
77
|
+
return _countDays(this.startOf("month").isoWeekDay % 7, daysInMonth, weekendMask);
|
|
78
|
+
};
|
|
79
|
+
$Chronos.prototype.weekendsInMonth = function(wDef = 0, wLen = 2) {
|
|
80
|
+
const daysInMonth = this.daysInMonth();
|
|
81
|
+
const weekendMask = _buildWeekendMask(wDef, wLen);
|
|
82
|
+
return _countDays(this.startOf("month").isoWeekDay % 7, daysInMonth, weekendMask, 1, false);
|
|
83
|
+
};
|
|
84
|
+
$Chronos.prototype.workdaysInYear = function(wDef = 0, wLen = 2) {
|
|
85
|
+
const daysInYear = this.isLeapYear() ? 366 : 365;
|
|
86
|
+
const weekendMask = _buildWeekendMask(wDef, wLen);
|
|
87
|
+
return _countDays(this.startOf("year").isoWeekDay % 7, daysInYear, weekendMask);
|
|
88
|
+
};
|
|
89
|
+
$Chronos.prototype.weekendsInYear = function(wDef = 0, wLen = 2) {
|
|
90
|
+
const daysInYear = this.isLeapYear() ? 366 : 365;
|
|
91
|
+
const weekendMask = _buildWeekendMask(wDef, wLen);
|
|
92
|
+
return _countDays(this.startOf("year").isoWeekDay % 7, daysInYear, weekendMask, 1, false);
|
|
93
|
+
};
|
|
94
|
+
$Chronos.prototype.isBusinessHour = function(options) {
|
|
95
|
+
const _isBusinessHour = () => {
|
|
96
|
+
const { businessStartHour = 9, businessEndHour = 17 } = options ?? {};
|
|
97
|
+
if (businessStartHour === businessEndHour) return false;
|
|
98
|
+
const hour = $Date(this).getHours();
|
|
99
|
+
if (businessStartHour < businessEndHour) return hour >= businessStartHour && hour < businessEndHour;
|
|
100
|
+
else return hour >= businessStartHour || hour < businessEndHour;
|
|
101
|
+
};
|
|
102
|
+
if (options && "weekendDays" in options && !require_primitives.isUndefined(options?.weekendDays)) return this.isWorkday(options.weekendDays) && _isBusinessHour();
|
|
103
|
+
const { weekStartsOn = 0, weekendLength = 2 } = options ?? {};
|
|
104
|
+
return this.isWorkday(weekStartsOn, weekendLength) && _isBusinessHour();
|
|
105
|
+
};
|
|
106
|
+
$Chronos.prototype.toFiscalQuarter = function(startMonth = 7) {
|
|
107
|
+
const adjusted = (this.isoMonth - startMonth + 12) % 12;
|
|
108
|
+
return Math.floor(adjusted / 3) + 1;
|
|
109
|
+
};
|
|
110
|
+
$Chronos.prototype.toAcademicYear = function() {
|
|
111
|
+
const year = this.year;
|
|
112
|
+
if (this.month >= 6) return `${year}-${year + 1}`;
|
|
113
|
+
else return `${year - 1}-${year}`;
|
|
114
|
+
};
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
//#endregion
|
|
118
|
+
exports.businessPlugin = businessPlugin;
|
|
@@ -1 +1,117 @@
|
|
|
1
|
-
import{s as
|
|
1
|
+
import { s as INTERNALS } from "../basic-Dputob9z.mjs";
|
|
2
|
+
import { a as isUndefined } from "../primitives-DEt6I7Sy.mjs";
|
|
3
|
+
import { a as isValidArray } from "../non-primitives-DrQfPj1r.mjs";
|
|
4
|
+
|
|
5
|
+
//#region src/plugins/businessPlugin.ts
|
|
6
|
+
/** * Plugin to inject `business` related methods */
|
|
7
|
+
const businessPlugin = ($Chronos) => {
|
|
8
|
+
const { internalDate: $Date, withOrigin, cast, offset } = $Chronos[INTERNALS];
|
|
9
|
+
/** Build weekend mask (array of booleans) based on `week definition` or weekend `length` */
|
|
10
|
+
const _buildWeekendMask = (weekDef, length) => {
|
|
11
|
+
const weekendDays = isValidArray(weekDef) ? [...weekDef].sort() : Array.from({ length }, (_, i) => (weekDef + 7 - 1 - i) % 7).sort();
|
|
12
|
+
const mask = new Array(7).fill(true);
|
|
13
|
+
for (const d of weekendDays) mask[d] = false;
|
|
14
|
+
return mask;
|
|
15
|
+
};
|
|
16
|
+
/** Count workdays (`wd=true`) or weekends(`wd=false`) given a `start weekday`, `total days`, `weekend mask` and optional `step` */
|
|
17
|
+
const _countDays = (sWeek, days, mask, step = 1, wd = true) => {
|
|
18
|
+
let total = Math.floor(days / 7) * mask.filter((m) => wd ? Boolean(m) : !m).length;
|
|
19
|
+
let dayIndex = (sWeek % 7 + 7) % 7;
|
|
20
|
+
for (let i = 0; i < days % 7; i++) {
|
|
21
|
+
if (wd ? Boolean(mask[dayIndex]) : !mask[dayIndex]) total++;
|
|
22
|
+
dayIndex = (dayIndex + step + 7) % 7;
|
|
23
|
+
}
|
|
24
|
+
return total;
|
|
25
|
+
};
|
|
26
|
+
$Chronos.prototype.isWeekend = function(wDef = 0, wLen = 2) {
|
|
27
|
+
const day = $Date(this).getDay();
|
|
28
|
+
if (isValidArray(wDef)) return wDef.includes(day);
|
|
29
|
+
const lastDayOfWeek = (wDef + 6) % 7;
|
|
30
|
+
return Array.from({ length: wLen }, (_, i) => (lastDayOfWeek - i + 7) % 7).includes(day);
|
|
31
|
+
};
|
|
32
|
+
$Chronos.prototype.isWorkday = function(wDef = 0, wLen = 2) {
|
|
33
|
+
return !this.isWeekend(wDef, wLen);
|
|
34
|
+
};
|
|
35
|
+
$Chronos.prototype.nextWorkday = function(wDef = 0, wLen = 2) {
|
|
36
|
+
let nxtWrk = this.addDays(1);
|
|
37
|
+
while (nxtWrk.isWeekend(wDef, wLen)) nxtWrk = nxtWrk.addDays(1);
|
|
38
|
+
return withOrigin(nxtWrk.startOf("day"), "nextWorkday", offset(this), this.timeZoneName, this.timeZoneId, this.$tzTracker);
|
|
39
|
+
};
|
|
40
|
+
$Chronos.prototype.previousWorkday = function(wDef = 0, wLen = 2) {
|
|
41
|
+
let prevWrk = this.addDays(-1);
|
|
42
|
+
while (prevWrk.isWeekend(wDef, wLen)) prevWrk = prevWrk.addDays(-1);
|
|
43
|
+
return withOrigin(prevWrk.startOf("day"), "previousWorkday", offset(this), this.timeZoneName, this.timeZoneId, this.$tzTracker);
|
|
44
|
+
};
|
|
45
|
+
$Chronos.prototype.nextWeekend = function(wDef = 0, wLen = 2) {
|
|
46
|
+
let nxtWknd = this.addDays(1);
|
|
47
|
+
while (!nxtWknd.isWeekend(wDef, wLen)) nxtWknd = nxtWknd.addDays(1);
|
|
48
|
+
return withOrigin(nxtWknd.startOf("day"), "nextWeekend", offset(this), this.timeZoneName, this.timeZoneId, this.$tzTracker);
|
|
49
|
+
};
|
|
50
|
+
$Chronos.prototype.previousWeekend = function(wDef = 0, wLen = 2) {
|
|
51
|
+
let prevWknd = this.addDays(-1);
|
|
52
|
+
while (!prevWknd.isWeekend(wDef, wLen)) prevWknd = prevWknd.addDays(-1);
|
|
53
|
+
return withOrigin(prevWknd.startOf("day"), "previousWeekend", offset(this), this.timeZoneName, this.timeZoneId, this.$tzTracker);
|
|
54
|
+
};
|
|
55
|
+
$Chronos.prototype.workdaysBetween = function(to, wDef = 0, wLen = 2) {
|
|
56
|
+
const end = cast(to).startOf("day");
|
|
57
|
+
const start = this.startOf("day");
|
|
58
|
+
if (start.isSame(end, "day")) return 0;
|
|
59
|
+
const step = start.isBefore(end, "day") ? 1 : -1;
|
|
60
|
+
const totalDays = Math.abs(end.diff(start, "day"));
|
|
61
|
+
const weekendMask = _buildWeekendMask(wDef, wLen);
|
|
62
|
+
return _countDays((start.isoWeekDay + step) % 7, totalDays, weekendMask, step);
|
|
63
|
+
};
|
|
64
|
+
$Chronos.prototype.weekendsBetween = function(to, wDef = 0, wLen = 2) {
|
|
65
|
+
const end = cast(to).startOf("day");
|
|
66
|
+
const start = this.startOf("day");
|
|
67
|
+
if (start.isSame(end, "day")) return 0;
|
|
68
|
+
const step = start.isBefore(end, "day") ? 1 : -1;
|
|
69
|
+
const totalDays = Math.abs(end.diff(start, "day"));
|
|
70
|
+
const weekendMask = _buildWeekendMask(wDef, wLen);
|
|
71
|
+
return _countDays((start.isoWeekDay + step) % 7, totalDays, weekendMask, step, false);
|
|
72
|
+
};
|
|
73
|
+
$Chronos.prototype.workdaysInMonth = function(wDef = 0, wLen = 2) {
|
|
74
|
+
const daysInMonth = this.daysInMonth();
|
|
75
|
+
const weekendMask = _buildWeekendMask(wDef, wLen);
|
|
76
|
+
return _countDays(this.startOf("month").isoWeekDay % 7, daysInMonth, weekendMask);
|
|
77
|
+
};
|
|
78
|
+
$Chronos.prototype.weekendsInMonth = function(wDef = 0, wLen = 2) {
|
|
79
|
+
const daysInMonth = this.daysInMonth();
|
|
80
|
+
const weekendMask = _buildWeekendMask(wDef, wLen);
|
|
81
|
+
return _countDays(this.startOf("month").isoWeekDay % 7, daysInMonth, weekendMask, 1, false);
|
|
82
|
+
};
|
|
83
|
+
$Chronos.prototype.workdaysInYear = function(wDef = 0, wLen = 2) {
|
|
84
|
+
const daysInYear = this.isLeapYear() ? 366 : 365;
|
|
85
|
+
const weekendMask = _buildWeekendMask(wDef, wLen);
|
|
86
|
+
return _countDays(this.startOf("year").isoWeekDay % 7, daysInYear, weekendMask);
|
|
87
|
+
};
|
|
88
|
+
$Chronos.prototype.weekendsInYear = function(wDef = 0, wLen = 2) {
|
|
89
|
+
const daysInYear = this.isLeapYear() ? 366 : 365;
|
|
90
|
+
const weekendMask = _buildWeekendMask(wDef, wLen);
|
|
91
|
+
return _countDays(this.startOf("year").isoWeekDay % 7, daysInYear, weekendMask, 1, false);
|
|
92
|
+
};
|
|
93
|
+
$Chronos.prototype.isBusinessHour = function(options) {
|
|
94
|
+
const _isBusinessHour = () => {
|
|
95
|
+
const { businessStartHour = 9, businessEndHour = 17 } = options ?? {};
|
|
96
|
+
if (businessStartHour === businessEndHour) return false;
|
|
97
|
+
const hour = $Date(this).getHours();
|
|
98
|
+
if (businessStartHour < businessEndHour) return hour >= businessStartHour && hour < businessEndHour;
|
|
99
|
+
else return hour >= businessStartHour || hour < businessEndHour;
|
|
100
|
+
};
|
|
101
|
+
if (options && "weekendDays" in options && !isUndefined(options?.weekendDays)) return this.isWorkday(options.weekendDays) && _isBusinessHour();
|
|
102
|
+
const { weekStartsOn = 0, weekendLength = 2 } = options ?? {};
|
|
103
|
+
return this.isWorkday(weekStartsOn, weekendLength) && _isBusinessHour();
|
|
104
|
+
};
|
|
105
|
+
$Chronos.prototype.toFiscalQuarter = function(startMonth = 7) {
|
|
106
|
+
const adjusted = (this.isoMonth - startMonth + 12) % 12;
|
|
107
|
+
return Math.floor(adjusted / 3) + 1;
|
|
108
|
+
};
|
|
109
|
+
$Chronos.prototype.toAcademicYear = function() {
|
|
110
|
+
const year = this.year;
|
|
111
|
+
if (this.month >= 6) return `${year}-${year + 1}`;
|
|
112
|
+
else return `${year - 1}-${year}`;
|
|
113
|
+
};
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
//#endregion
|
|
117
|
+
export { businessPlugin };
|
|
@@ -1 +1,46 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,
|
|
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;
|