@things-factory/shell 9.0.0-beta.19 → 9.0.0-beta.21
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.
@@ -1,22 +1,42 @@
|
|
1
1
|
/**
|
2
2
|
* Get the time range for the specified period relative to the current moment in a specific domain's timezone.
|
3
3
|
*
|
4
|
-
* @param {
|
4
|
+
* @param {('today' | 'this month' | '30 days' | 'this year' | '12 months' | 'date range' | 'month')} period - The time period to calculate the range for.
|
5
|
+
* Valid options are 'today', 'this month', '30 days', 'this year', '12 months', 'date range', and 'month'.
|
6
|
+
* @param {Object} [options] - Optional parameters for 'date range' and 'month' periods.
|
7
|
+
* @param {string[]} [options.date] - The start date and end date for the 'date range' period.
|
8
|
+
* @param {string} [options.month] - The month for the 'month' period in 'YYYY-MM' format.
|
5
9
|
* @param {Object} context - The context object containing domain information.
|
10
|
+
* @param {Object} context.state - The state object containing domain information.
|
11
|
+
* @param {Object} context.state.domain - The domain object containing timezone information.
|
12
|
+
* @param {string} context.state.domain.timezone - The timezone of the domain.
|
6
13
|
* @returns {Promise<{ from: string; to: string }>} - A Promise that resolves to an object containing 'from' and 'to' ISO date strings representing the time range.
|
7
14
|
*/
|
8
|
-
export declare function getTimesForPeriod(period: 'today' | 'this month' | '30 days' | 'this year' | '12 months',
|
15
|
+
export declare function getTimesForPeriod(period: 'today' | 'this month' | '30 days' | 'this year' | '12 months' | 'date range' | 'month', options: {
|
16
|
+
date?: string[];
|
17
|
+
month?: string;
|
18
|
+
}, context: any): Promise<{
|
9
19
|
from: string;
|
10
20
|
to: string;
|
11
21
|
}>;
|
12
22
|
/**
|
13
23
|
* Get the ISO date strings for the specified period relative to the current moment in a specific domain's timezone.
|
14
24
|
*
|
15
|
-
* @param {
|
25
|
+
* @param {('today' | 'this month' | '30 days' | 'this year' | '12 months' | 'date range' | 'month')} period - The time period to calculate the range for.
|
26
|
+
* Valid options are 'today', 'this month', '30 days', 'this year', '12 months', 'date range', and 'month'.
|
27
|
+
* @param {Object} [options] - Optional parameters for 'date range' and 'month' periods.
|
28
|
+
* @param {string[]} [options.date] - The start date and end date for the 'date range' period.
|
29
|
+
* @param {string} [options.month] - The month for the 'month' period in 'YYYY-MM' format.
|
16
30
|
* @param {Object} context - The context object containing domain information.
|
31
|
+
* @param {Object} context.state - The state object containing domain information.
|
32
|
+
* @param {Object} context.state.domain - The domain object containing timezone information.
|
33
|
+
* @param {string} context.state.domain.timezone - The timezone of the domain.
|
17
34
|
* @returns {Promise<{ from: string; to: string }>} - A Promise that resolves to an object containing 'from' and 'to' ISO date strings representing the time range.
|
18
35
|
*/
|
19
|
-
export declare function getISOStringsForPeriod(period: 'today' | 'this month' | '30 days' | 'this year' | '12 months',
|
36
|
+
export declare function getISOStringsForPeriod(period: 'today' | 'this month' | '30 days' | 'this year' | '12 months' | 'date range' | 'month', options: {
|
37
|
+
date?: string[];
|
38
|
+
month?: string;
|
39
|
+
}, context: any): Promise<{
|
20
40
|
from: string;
|
21
41
|
to: string;
|
22
42
|
}>;
|
@@ -7,11 +7,18 @@ const moment_timezone_1 = tslib_1.__importDefault(require("moment-timezone"));
|
|
7
7
|
/**
|
8
8
|
* Get the time range for the specified period relative to the current moment in a specific domain's timezone.
|
9
9
|
*
|
10
|
-
* @param {
|
10
|
+
* @param {('today' | 'this month' | '30 days' | 'this year' | '12 months' | 'date range' | 'month')} period - The time period to calculate the range for.
|
11
|
+
* Valid options are 'today', 'this month', '30 days', 'this year', '12 months', 'date range', and 'month'.
|
12
|
+
* @param {Object} [options] - Optional parameters for 'date range' and 'month' periods.
|
13
|
+
* @param {string[]} [options.date] - The start date and end date for the 'date range' period.
|
14
|
+
* @param {string} [options.month] - The month for the 'month' period in 'YYYY-MM' format.
|
11
15
|
* @param {Object} context - The context object containing domain information.
|
16
|
+
* @param {Object} context.state - The state object containing domain information.
|
17
|
+
* @param {Object} context.state.domain - The domain object containing timezone information.
|
18
|
+
* @param {string} context.state.domain.timezone - The timezone of the domain.
|
12
19
|
* @returns {Promise<{ from: string; to: string }>} - A Promise that resolves to an object containing 'from' and 'to' ISO date strings representing the time range.
|
13
20
|
*/
|
14
|
-
async function getTimesForPeriod(period, context) {
|
21
|
+
async function getTimesForPeriod(period, options = {}, context) {
|
15
22
|
const { domain } = context.state;
|
16
23
|
const theDate = moment_timezone_1.default.tz(new Date(), domain.timezone);
|
17
24
|
if (period == 'today') {
|
@@ -39,17 +46,47 @@ async function getTimesForPeriod(period, context) {
|
|
39
46
|
const to = theDate.clone().add(1, 'month').startOf('month').format('YYYY-MM-DD');
|
40
47
|
return { from, to };
|
41
48
|
}
|
49
|
+
else if (period == 'date range') {
|
50
|
+
const [fromDate, toDate] = (options === null || options === void 0 ? void 0 : options.date) || [
|
51
|
+
theDate.clone().startOf('month').format('YYYY-MM-DD'),
|
52
|
+
theDate.clone().format('YYYY-MM-DD')
|
53
|
+
];
|
54
|
+
const from = moment_timezone_1.default.tz(fromDate, domain.timezone).startOf('day').format('YYYY-MM-DD');
|
55
|
+
const to = moment_timezone_1.default.tz(toDate, domain.timezone).add(1, 'day').startOf('day').format('YYYY-MM-DD');
|
56
|
+
return { from, to };
|
57
|
+
}
|
58
|
+
else if (period == 'month') {
|
59
|
+
const monthString = (options === null || options === void 0 ? void 0 : options.month) || theDate.clone().startOf('month').format('YYYY-MM');
|
60
|
+
const [year, month] = monthString.split('-').map(Number);
|
61
|
+
const from = moment_timezone_1.default
|
62
|
+
.tz({ year, month: month - 1, day: 1 }, domain.timezone)
|
63
|
+
.startOf('month')
|
64
|
+
.format('YYYY-MM-DD');
|
65
|
+
const to = moment_timezone_1.default
|
66
|
+
.tz({ year, month: month - 1, day: 1 }, domain.timezone)
|
67
|
+
.add(1, 'month')
|
68
|
+
.startOf('month')
|
69
|
+
.format('YYYY-MM-DD');
|
70
|
+
return { from, to };
|
71
|
+
}
|
42
72
|
}
|
43
73
|
/**
|
44
74
|
* Get the ISO date strings for the specified period relative to the current moment in a specific domain's timezone.
|
45
75
|
*
|
46
|
-
* @param {
|
76
|
+
* @param {('today' | 'this month' | '30 days' | 'this year' | '12 months' | 'date range' | 'month')} period - The time period to calculate the range for.
|
77
|
+
* Valid options are 'today', 'this month', '30 days', 'this year', '12 months', 'date range', and 'month'.
|
78
|
+
* @param {Object} [options] - Optional parameters for 'date range' and 'month' periods.
|
79
|
+
* @param {string[]} [options.date] - The start date and end date for the 'date range' period.
|
80
|
+
* @param {string} [options.month] - The month for the 'month' period in 'YYYY-MM' format.
|
47
81
|
* @param {Object} context - The context object containing domain information.
|
82
|
+
* @param {Object} context.state - The state object containing domain information.
|
83
|
+
* @param {Object} context.state.domain - The domain object containing timezone information.
|
84
|
+
* @param {string} context.state.domain.timezone - The timezone of the domain.
|
48
85
|
* @returns {Promise<{ from: string; to: string }>} - A Promise that resolves to an object containing 'from' and 'to' ISO date strings representing the time range.
|
49
86
|
*/
|
50
|
-
async function getISOStringsForPeriod(period, context) {
|
87
|
+
async function getISOStringsForPeriod(period, options = {}, context) {
|
51
88
|
const { domain } = context.state;
|
52
|
-
const { from, to } = await getTimesForPeriod(period, context);
|
89
|
+
const { from, to } = await getTimesForPeriod(period, options, context);
|
53
90
|
return {
|
54
91
|
from: moment_timezone_1.default.tz(from, domain.timezone).toISOString(),
|
55
92
|
to: moment_timezone_1.default.tz(to, domain.timezone).toISOString()
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"get-times-for-period.js","sourceRoot":"","sources":["../../server/utils/get-times-for-period.ts"],"names":[],"mappings":";;
|
1
|
+
{"version":3,"file":"get-times-for-period.js","sourceRoot":"","sources":["../../server/utils/get-times-for-period.ts"],"names":[],"mappings":";;AAgBA,8CA2DC;AAgBD,wDAYC;;AAvGD,8EAAoC;AAEpC;;;;;;;;;;;;;GAaG;AACI,KAAK,UAAU,iBAAiB,CACrC,MAA+F,EAC/F,UAA+C,EAAE,EACjD,OAAY;IAEZ,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,KAAK,CAAA;IAChC,MA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EACjD,OAAY;IAEZ,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,KAAK,CAAA;IAChC,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,GAAG,MAAM,iBAAiB,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,CAAA;IAEtE,OAAO;QACL,IAAI,EAAE,yBAAM,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC,WAAW,EAAE;QACpD,EAAE,EAAE,yBAAM,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC,WAAW,EAAE;KACjD,CAAA;AACH,CAAC","sourcesContent":["import moment from 'moment-timezone'\n\n/**\n * Get the time range for the specified period relative to the current moment in a specific domain's timezone.\n *\n * @param {('today' | 'this month' | '30 days' | 'this year' | '12 months' | 'date range' | 'month')} period - The time period to calculate the range for.\n * Valid options are 'today', 'this month', '30 days', 'this year', '12 months', 'date range', and 'month'.\n * @param {Object} [options] - Optional parameters for 'date range' and 'month' periods.\n * @param {string[]} [options.date] - The start date and end date for the 'date range' period.\n * @param {string} [options.month] - The month for the 'month' period in 'YYYY-MM' format.\n * @param {Object} context - The context object containing domain information.\n * @param {Object} context.state - The state object containing domain information.\n * @param {Object} context.state.domain - The domain object containing timezone information.\n * @param {string} context.state.domain.timezone - The timezone of the domain.\n * @returns {Promise<{ from: string; to: string }>} - A Promise that resolves to an object containing 'from' and 'to' ISO date strings representing the time range.\n */\nexport async function getTimesForPeriod(\n period: 'today' | 'this month' | '30 days' | 'this year' | '12 months' | 'date range' | 'month',\n options: { date?: string[]; month?: string } = {},\n context: any\n): Promise<{ from: string; to: string }> {\n const { domain } = context.state\n const theDate = moment.tz(new Date(), domain.timezone)\n\n if (period == 'today') {\n const from = theDate.clone().format('YYYY-MM-DD')\n const to = theDate.clone().add(1, 'day').startOf('day').format('YYYY-MM-DD')\n\n return { from, to }\n } else if (period == 'this month') {\n const from = theDate.clone().startOf('month').format('YYYY-MM-DD')\n const to = theDate.clone().add(1, 'month').startOf('month').format('YYYY-MM-DD')\n\n return { from, to }\n } else if (period == '30 days') {\n const from = theDate.clone().subtract(30, 'day').format('YYYY-MM-DD')\n const to = theDate.clone().add(1, 'day').startOf('day').format('YYYY-MM-DD')\n\n return { from, to }\n } else if (period == 'this year') {\n const from = theDate.clone().startOf('year').format('YYYY-MM-DD')\n const to = theDate.clone().add(1, 'year').startOf('year').format('YYYY-MM-DD')\n\n return { from, to }\n } else if (period == '12 months') {\n const from = theDate.clone().subtract(12, 'month').startOf('month').format('YYYY-MM-DD')\n const to = theDate.clone().add(1, 'month').startOf('month').format('YYYY-MM-DD')\n\n return { from, to }\n } else if (period == 'date range') {\n const [fromDate, toDate] = options?.date || [\n theDate.clone().startOf('month').format('YYYY-MM-DD'),\n theDate.clone().format('YYYY-MM-DD')\n ]\n\n const from = moment.tz(fromDate, domain.timezone).startOf('day').format('YYYY-MM-DD')\n const to = moment.tz(toDate, domain.timezone).add(1, 'day').startOf('day').format('YYYY-MM-DD')\n\n return { from, to }\n } else if (period == 'month') {\n const monthString = options?.month || theDate.clone().startOf('month').format('YYYY-MM')\n\n const [year, month] = monthString.split('-').map(Number)\n const from = moment\n .tz({ year, month: month - 1, day: 1 }, domain.timezone)\n .startOf('month')\n .format('YYYY-MM-DD')\n const to = moment\n .tz({ year, month: month - 1, day: 1 }, domain.timezone)\n .add(1, 'month')\n .startOf('month')\n .format('YYYY-MM-DD')\n\n return { from, to }\n }\n}\n\n/**\n * Get the ISO date strings for the specified period relative to the current moment in a specific domain's timezone.\n *\n * @param {('today' | 'this month' | '30 days' | 'this year' | '12 months' | 'date range' | 'month')} period - The time period to calculate the range for.\n * Valid options are 'today', 'this month', '30 days', 'this year', '12 months', 'date range', and 'month'.\n * @param {Object} [options] - Optional parameters for 'date range' and 'month' periods.\n * @param {string[]} [options.date] - The start date and end date for the 'date range' period.\n * @param {string} [options.month] - The month for the 'month' period in 'YYYY-MM' format.\n * @param {Object} context - The context object containing domain information.\n * @param {Object} context.state - The state object containing domain information.\n * @param {Object} context.state.domain - The domain object containing timezone information.\n * @param {string} context.state.domain.timezone - The timezone of the domain.\n * @returns {Promise<{ from: string; to: string }>} - A Promise that resolves to an object containing 'from' and 'to' ISO date strings representing the time range.\n */\nexport async function getISOStringsForPeriod(\n period: 'today' | 'this month' | '30 days' | 'this year' | '12 months' | 'date range' | 'month',\n options: { date?: string[]; month?: string } = {},\n context: any\n): Promise<{ from: string; to: string }> {\n const { domain } = context.state\n const { from, to } = await getTimesForPeriod(period, options, context)\n\n return {\n from: moment.tz(from, domain.timezone).toISOString(),\n to: moment.tz(to, domain.timezone).toISOString()\n }\n}\n"]}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@things-factory/shell",
|
3
|
-
"version": "9.0.0-beta.
|
3
|
+
"version": "9.0.0-beta.21",
|
4
4
|
"description": "Core module for framework",
|
5
5
|
"bin": {
|
6
6
|
"things-factory": "bin/things-factory",
|
@@ -130,5 +130,5 @@
|
|
130
130
|
"pg": "^8.7.3",
|
131
131
|
"sqlite3": "^5.0.8"
|
132
132
|
},
|
133
|
-
"gitHead": "
|
133
|
+
"gitHead": "c06587776650048bf08e5507fe629627ea9bdf8a"
|
134
134
|
}
|