@things-factory/shell 6.0.124 → 6.0.125
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-server/service/index.d.ts +2 -2
- package/dist-server/tsconfig.tsbuildinfo +1 -1
- package/dist-server/utils/get-times-for-period.d.ts +8 -0
- package/dist-server/utils/get-times-for-period.js +45 -0
- package/dist-server/utils/get-times-for-period.js.map +1 -0
- package/dist-server/utils/index.d.ts +1 -0
- package/dist-server/utils/index.js +1 -0
- package/dist-server/utils/index.js.map +1 -1
- package/package.json +3 -2
- package/server/utils/get-times-for-period.ts +49 -0
- package/server/utils/index.ts +1 -0
@@ -0,0 +1,8 @@
|
|
1
|
+
export declare function getTimesForPeriod(period: 'today' | 'this month' | '30 days' | 'this year' | '12 months', context: any): Promise<{
|
2
|
+
from: string;
|
3
|
+
to: string;
|
4
|
+
}>;
|
5
|
+
export declare function getISOStringsForPeriod(period: 'today' | 'this month' | '30 days' | 'this year' | '12 months', context: any): Promise<{
|
6
|
+
from: string;
|
7
|
+
to: string;
|
8
|
+
}>;
|
@@ -0,0 +1,45 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.getISOStringsForPeriod = exports.getTimesForPeriod = void 0;
|
4
|
+
const tslib_1 = require("tslib");
|
5
|
+
const moment_timezone_1 = tslib_1.__importDefault(require("moment-timezone"));
|
6
|
+
async function getTimesForPeriod(period, context) {
|
7
|
+
const { domain } = context.state;
|
8
|
+
const theDate = moment_timezone_1.default.tz(new Date(), domain.timezone);
|
9
|
+
if (period == 'today') {
|
10
|
+
const from = theDate.clone().format('YYYY-MM-DD');
|
11
|
+
const to = theDate.clone().add(1, 'day').startOf('day').format('YYYY-MM-DD');
|
12
|
+
return { from, to };
|
13
|
+
}
|
14
|
+
else if (period == 'this month') {
|
15
|
+
const from = theDate.clone().startOf('month').format('YYYY-MM-DD');
|
16
|
+
const to = theDate.clone().add(1, 'month').startOf('month').format('YYYY-MM-DD');
|
17
|
+
return { from, to };
|
18
|
+
}
|
19
|
+
else if (period == '30 days') {
|
20
|
+
const from = theDate.clone().subtract(30, 'day').format('YYYY-MM-DD');
|
21
|
+
const to = theDate.clone().add(1, 'day').startOf('day').format('YYYY-MM-DD');
|
22
|
+
return { from, to };
|
23
|
+
}
|
24
|
+
else if (period == 'this year') {
|
25
|
+
const from = theDate.clone().startOf('year').format('YYYY-MM-DD');
|
26
|
+
const to = theDate.clone().add(1, 'year').startOf('year').format('YYYY-MM-DD');
|
27
|
+
return { from, to };
|
28
|
+
}
|
29
|
+
else if (period == '12 months') {
|
30
|
+
const from = theDate.clone().subtract(12, 'month').startOf('month').format('YYYY-MM-DD');
|
31
|
+
const to = theDate.clone().add(1, 'month').startOf('month').format('YYYY-MM-DD');
|
32
|
+
return { from, to };
|
33
|
+
}
|
34
|
+
}
|
35
|
+
exports.getTimesForPeriod = getTimesForPeriod;
|
36
|
+
async function getISOStringsForPeriod(period, context) {
|
37
|
+
const { domain } = context.state;
|
38
|
+
const { from, to } = await getTimesForPeriod(period, context);
|
39
|
+
return {
|
40
|
+
from: moment_timezone_1.default.tz(from, domain.timezone).toISOString(),
|
41
|
+
to: moment_timezone_1.default.tz(to, domain.timezone).toISOString()
|
42
|
+
};
|
43
|
+
}
|
44
|
+
exports.getISOStringsForPeriod = getISOStringsForPeriod;
|
45
|
+
//# sourceMappingURL=get-times-for-period.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"get-times-for-period.js","sourceRoot":"","sources":["../../server/utils/get-times-for-period.ts"],"names":[],"mappings":";;;;AAAA,8EAAoC;AAE7B,KAAK,UAAU,iBAAiB,CACrC,MAAsE,EACtE,OAAY;IAEZ,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,KAAK,CAAA;IAChC,MAAM,OAAO,GAAG,yBAAM,CAAC,EAAE,CAAC,IAAI,IAAI,EAAE,EAAE,MAAM,CAAC,QAAQ,CAA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ACjE,MAAM,EAAE,GAAG,OAAO,CAAC,KAAK,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,YAAY,CAAC,CAAA;QAE9E,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE,CAAA;KACpB;SAAM,IAAI,MAAM,IAAI,WAAW,EAAE;QAChC,MAAM,IAAI,GAAG,OAAO,CAAC,KAAK,EAAE,CAAC,QAAQ,CAAC,EAAE,EAAE,OAAO,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,YAAY,CAAC,CAAA;QACxF,MAAM,EAAE,GAAG,OAAO,CAAC,KAAK,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,YAAY,CAAC,CAAA;QAEhF,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE,CAAA;KACpB;AACH,CAAC;AAjCD,8CAiCC;AAEM,KAAK,UAAU,sBAAsB,CAC1C,MAAsE,EACtE,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,CAAC,CAAA;IAE7D,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;AAXD,wDAWC","sourcesContent":["import moment from 'moment-timezone'\n\nexport async function getTimesForPeriod(\n period: 'today' | 'this month' | '30 days' | 'this year' | '12 months',\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 }\n}\n\nexport async function getISOStringsForPeriod(\n period: 'today' | 'this month' | '30 days' | 'this year' | '12 months',\n context: any\n): Promise<{ from: string; to: string }> {\n const { domain } = context.state\n const { from, to } = await getTimesForPeriod(period, context)\n\n return {\n from: moment.tz(from, domain.timezone).toISOString(),\n to: moment.tz(to, domain.timezone).toISOString()\n }\n}\n"]}
|
@@ -8,4 +8,5 @@ tslib_1.__exportStar(require("./list-params-converter"), exports);
|
|
8
8
|
tslib_1.__exportStar(require("./publish-progress"), exports);
|
9
9
|
tslib_1.__exportStar(require("./get-query-builder-from-list-params"), exports);
|
10
10
|
tslib_1.__exportStar(require("./list-param-adjuster"), exports);
|
11
|
+
tslib_1.__exportStar(require("./get-times-for-period"), exports);
|
11
12
|
//# sourceMappingURL=index.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../server/utils/index.ts"],"names":[],"mappings":";;;AAAA,uDAA4B;AAC5B,8DAAmC;AACnC,+DAAoC;AACpC,kEAAuC;AACvC,6DAAkC;AAClC,+EAAoD;AACpD,gEAAqC","sourcesContent":["export * from './get-domain'\nexport * from './condition-builder'\nexport * from './list-query-builder'\nexport * from './list-params-converter'\nexport * from './publish-progress'\nexport * from './get-query-builder-from-list-params'\nexport * from './list-param-adjuster'\n"]}
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../server/utils/index.ts"],"names":[],"mappings":";;;AAAA,uDAA4B;AAC5B,8DAAmC;AACnC,+DAAoC;AACpC,kEAAuC;AACvC,6DAAkC;AAClC,+EAAoD;AACpD,gEAAqC;AACrC,iEAAsC","sourcesContent":["export * from './get-domain'\nexport * from './condition-builder'\nexport * from './list-query-builder'\nexport * from './list-params-converter'\nexport * from './publish-progress'\nexport * from './get-query-builder-from-list-params'\nexport * from './list-param-adjuster'\nexport * from './get-times-for-period'\n"]}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@things-factory/shell",
|
3
|
-
"version": "6.0.
|
3
|
+
"version": "6.0.125",
|
4
4
|
"description": "Core module for framework",
|
5
5
|
"bin": {
|
6
6
|
"things-factory": "bin/things-factory",
|
@@ -97,6 +97,7 @@
|
|
97
97
|
"lodash": "^4.17.21",
|
98
98
|
"lodash-es": "^4.17.21",
|
99
99
|
"mkdirp": "^1.0.4",
|
100
|
+
"moment-timezone": "^0.5.43",
|
100
101
|
"mqtt": "^4.3.4",
|
101
102
|
"node-fetch": "^2.6.0",
|
102
103
|
"nodemon": "^2.0.19",
|
@@ -129,5 +130,5 @@
|
|
129
130
|
"pg": "^8.7.3",
|
130
131
|
"sqlite3": "^5.0.8"
|
131
132
|
},
|
132
|
-
"gitHead": "
|
133
|
+
"gitHead": "2d741c0c6ad8cf572560ac5bcc6fb7de470ede72"
|
133
134
|
}
|
@@ -0,0 +1,49 @@
|
|
1
|
+
import moment from 'moment-timezone'
|
2
|
+
|
3
|
+
export async function getTimesForPeriod(
|
4
|
+
period: 'today' | 'this month' | '30 days' | 'this year' | '12 months',
|
5
|
+
context: any
|
6
|
+
): Promise<{ from: string; to: string }> {
|
7
|
+
const { domain } = context.state
|
8
|
+
const theDate = moment.tz(new Date(), domain.timezone)
|
9
|
+
|
10
|
+
if (period == 'today') {
|
11
|
+
const from = theDate.clone().format('YYYY-MM-DD')
|
12
|
+
const to = theDate.clone().add(1, 'day').startOf('day').format('YYYY-MM-DD')
|
13
|
+
|
14
|
+
return { from, to }
|
15
|
+
} else if (period == 'this month') {
|
16
|
+
const from = theDate.clone().startOf('month').format('YYYY-MM-DD')
|
17
|
+
const to = theDate.clone().add(1, 'month').startOf('month').format('YYYY-MM-DD')
|
18
|
+
|
19
|
+
return { from, to }
|
20
|
+
} else if (period == '30 days') {
|
21
|
+
const from = theDate.clone().subtract(30, 'day').format('YYYY-MM-DD')
|
22
|
+
const to = theDate.clone().add(1, 'day').startOf('day').format('YYYY-MM-DD')
|
23
|
+
|
24
|
+
return { from, to }
|
25
|
+
} else if (period == 'this year') {
|
26
|
+
const from = theDate.clone().startOf('year').format('YYYY-MM-DD')
|
27
|
+
const to = theDate.clone().add(1, 'year').startOf('year').format('YYYY-MM-DD')
|
28
|
+
|
29
|
+
return { from, to }
|
30
|
+
} else if (period == '12 months') {
|
31
|
+
const from = theDate.clone().subtract(12, 'month').startOf('month').format('YYYY-MM-DD')
|
32
|
+
const to = theDate.clone().add(1, 'month').startOf('month').format('YYYY-MM-DD')
|
33
|
+
|
34
|
+
return { from, to }
|
35
|
+
}
|
36
|
+
}
|
37
|
+
|
38
|
+
export async function getISOStringsForPeriod(
|
39
|
+
period: 'today' | 'this month' | '30 days' | 'this year' | '12 months',
|
40
|
+
context: any
|
41
|
+
): Promise<{ from: string; to: string }> {
|
42
|
+
const { domain } = context.state
|
43
|
+
const { from, to } = await getTimesForPeriod(period, context)
|
44
|
+
|
45
|
+
return {
|
46
|
+
from: moment.tz(from, domain.timezone).toISOString(),
|
47
|
+
to: moment.tz(to, domain.timezone).toISOString()
|
48
|
+
}
|
49
|
+
}
|
package/server/utils/index.ts
CHANGED