@things-factory/work-shift 5.0.0-alpha.33 → 5.0.0-alpha.36
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,9 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.getWorkDateAndShift = void 0;
|
|
4
7
|
const work_shift_1 = require("../service/work-shift/work-shift");
|
|
5
8
|
const typeorm_1 = require("typeorm");
|
|
6
9
|
const env_1 = require("@things-factory/env");
|
|
10
|
+
const moment_timezone_1 = __importDefault(require("moment-timezone"));
|
|
7
11
|
function between(fromDate, fromTime /* hh:mm */, toDate, toTime /* hh:mm */, theDay, dateTime) {
|
|
8
12
|
const convertedFromDate = new Date(theDay.getTime() + fromDate * (24 * 60 * 60 * 1000));
|
|
9
13
|
const convertedToDate = new Date(theDay.getTime() + toDate * (24 * 60 * 60 * 1000));
|
|
@@ -11,8 +15,13 @@ function between(fromDate, fromTime /* hh:mm */, toDate, toTime /* hh:mm */, the
|
|
|
11
15
|
const to = new Date(`${convertedToDate.toISOString().split('T')[0]}T${toTime}`);
|
|
12
16
|
return dateTime >= from && to > dateTime;
|
|
13
17
|
}
|
|
14
|
-
async function getWorkDateAndShift(domain, dateTime) {
|
|
15
|
-
const
|
|
18
|
+
async function getWorkDateAndShift(domain, dateTime, options) {
|
|
19
|
+
const dateOptions = Object.assign({ timezone: domain.timezone || 'UTC', format: 'YYYY-MM-DD' }, options);
|
|
20
|
+
const { timezone, format } = dateOptions;
|
|
21
|
+
// const givenDate = dateTime.toISOString().split('T')[0]
|
|
22
|
+
const givenDate = (0, moment_timezone_1.default)(dateTime).tz(timezone);
|
|
23
|
+
const localDate = new Date(givenDate.format('YYYY-MM-DD HH:mm:ss'));
|
|
24
|
+
const workDate = givenDate.format(format);
|
|
16
25
|
/* 1. get work-shift list for the domain */
|
|
17
26
|
const workShifts = await (0, typeorm_1.getRepository)(work_shift_1.WorkShift).find({
|
|
18
27
|
where: {
|
|
@@ -25,7 +34,7 @@ async function getWorkDateAndShift(domain, dateTime) {
|
|
|
25
34
|
});
|
|
26
35
|
/* 2. compare given date-time to every work-shift */
|
|
27
36
|
if (workShifts && workShifts.length > 0) {
|
|
28
|
-
const theDay = new Date(givenDate);
|
|
37
|
+
const theDay = new Date(givenDate.format('YYYY-MM-DD'));
|
|
29
38
|
const theDayBefore = new Date(theDay.getTime() - 24 * 60 * 60 * 1000);
|
|
30
39
|
const theDayAfter = new Date(theDay.getTime() + 24 * 60 * 60 * 1000);
|
|
31
40
|
const days = [theDayBefore, theDay, theDayAfter];
|
|
@@ -33,9 +42,9 @@ async function getWorkDateAndShift(domain, dateTime) {
|
|
|
33
42
|
const theDay = days[i];
|
|
34
43
|
for (let j = 0; j < workShifts.length; j++) {
|
|
35
44
|
const { name, fromDate, fromTime, toDate, toTime } = workShifts[j];
|
|
36
|
-
if (between(fromDate, fromTime, toDate, toTime, theDay,
|
|
45
|
+
if (between(fromDate, fromTime, toDate, toTime, theDay, localDate)) {
|
|
37
46
|
return {
|
|
38
|
-
workDate
|
|
47
|
+
workDate,
|
|
39
48
|
workShift: name
|
|
40
49
|
};
|
|
41
50
|
}
|
|
@@ -45,7 +54,7 @@ async function getWorkDateAndShift(domain, dateTime) {
|
|
|
45
54
|
}
|
|
46
55
|
/* 3. in case there are no work-shift, just give date and default shift 'NA' */
|
|
47
56
|
return {
|
|
48
|
-
workDate
|
|
57
|
+
workDate,
|
|
49
58
|
workShift: 'NA'
|
|
50
59
|
};
|
|
51
60
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../server/controllers/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../server/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CAAC,CAAC,CAAC,CAAA;gBAElE,IAAI,OAAO,CAAC,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE;oBAClE,OAAO;wBACL,QAAQ;wBACR,SAAS,EAAE,IAAI;qBAChB,CAAA;iBACF;aACF;SACF;QAED,YAAM,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC,CAAA;KAC3C;IAED,+EAA+E;IAC/E,OAAO;QACL,QAAQ;QACR,SAAS,EAAE,IAAI;KAChB,CAAA;AACH,CAAC;AAlDD,kDAkDC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@things-factory/work-shift",
|
|
3
|
-
"version": "5.0.0-alpha.
|
|
3
|
+
"version": "5.0.0-alpha.36",
|
|
4
4
|
"main": "dist-server/index.js",
|
|
5
5
|
"browser": "client/index.js",
|
|
6
6
|
"things-factory": true,
|
|
@@ -24,9 +24,9 @@
|
|
|
24
24
|
"migration:create": "node ../../node_modules/typeorm/cli.js migration:create -d ./server/migrations"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@things-factory/auth-base": "^5.0.0-alpha.
|
|
28
|
-
"@things-factory/env": "^5.0.0-alpha.
|
|
29
|
-
"@things-factory/shell": "^5.0.0-alpha.
|
|
27
|
+
"@things-factory/auth-base": "^5.0.0-alpha.36",
|
|
28
|
+
"@things-factory/env": "^5.0.0-alpha.36",
|
|
29
|
+
"@things-factory/shell": "^5.0.0-alpha.36"
|
|
30
30
|
},
|
|
31
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "e9b944908264f902a4edb2c0bc92c4ea0607bb10"
|
|
32
32
|
}
|
|
@@ -5,6 +5,8 @@ import { WorkDateWorkShiftPair } from 'server/service/work-shift/work-shift-type
|
|
|
5
5
|
import { getRepository } from 'typeorm'
|
|
6
6
|
import { logger } from '@things-factory/env'
|
|
7
7
|
|
|
8
|
+
import moment, { Moment } from 'moment-timezone'
|
|
9
|
+
|
|
8
10
|
function between(
|
|
9
11
|
fromDate: WorkShiftDateType,
|
|
10
12
|
fromTime: string /* hh:mm */,
|
|
@@ -21,9 +23,14 @@ function between(
|
|
|
21
23
|
return dateTime >= from && to > dateTime
|
|
22
24
|
}
|
|
23
25
|
|
|
24
|
-
export async function getWorkDateAndShift(domain: Domain, dateTime: Date): Promise<WorkDateWorkShiftPair> {
|
|
25
|
-
const
|
|
26
|
+
export async function getWorkDateAndShift(domain: Domain, dateTime: Date, options?: any): Promise<WorkDateWorkShiftPair> {
|
|
27
|
+
const dateOptions = { timezone: domain.timezone || 'UTC', format: 'YYYY-MM-DD', ...options }
|
|
28
|
+
const { timezone, format } = dateOptions
|
|
26
29
|
|
|
30
|
+
// const givenDate = dateTime.toISOString().split('T')[0]
|
|
31
|
+
const givenDate = moment(dateTime).tz(timezone)
|
|
32
|
+
const localDate = new Date(givenDate.format('YYYY-MM-DD HH:mm:ss'))
|
|
33
|
+
const workDate = givenDate.format(format)
|
|
27
34
|
/* 1. get work-shift list for the domain */
|
|
28
35
|
const workShifts = await getRepository(WorkShift).find({
|
|
29
36
|
where: {
|
|
@@ -37,7 +44,7 @@ export async function getWorkDateAndShift(domain: Domain, dateTime: Date): Promi
|
|
|
37
44
|
|
|
38
45
|
/* 2. compare given date-time to every work-shift */
|
|
39
46
|
if (workShifts && workShifts.length > 0) {
|
|
40
|
-
const theDay = new Date(givenDate)
|
|
47
|
+
const theDay = new Date(givenDate.format('YYYY-MM-DD'))
|
|
41
48
|
const theDayBefore = new Date(theDay.getTime() - 24 * 60 * 60 * 1000)
|
|
42
49
|
const theDayAfter = new Date(theDay.getTime() + 24 * 60 * 60 * 1000)
|
|
43
50
|
|
|
@@ -49,9 +56,9 @@ export async function getWorkDateAndShift(domain: Domain, dateTime: Date): Promi
|
|
|
49
56
|
for (let j = 0; j < workShifts.length; j++) {
|
|
50
57
|
const { name, fromDate, fromTime, toDate, toTime } = workShifts[j]
|
|
51
58
|
|
|
52
|
-
if (between(fromDate, fromTime, toDate, toTime, theDay,
|
|
59
|
+
if (between(fromDate, fromTime, toDate, toTime, theDay, localDate)) {
|
|
53
60
|
return {
|
|
54
|
-
workDate
|
|
61
|
+
workDate,
|
|
55
62
|
workShift: name
|
|
56
63
|
}
|
|
57
64
|
}
|
|
@@ -63,7 +70,7 @@ export async function getWorkDateAndShift(domain: Domain, dateTime: Date): Promi
|
|
|
63
70
|
|
|
64
71
|
/* 3. in case there are no work-shift, just give date and default shift 'NA' */
|
|
65
72
|
return {
|
|
66
|
-
workDate
|
|
73
|
+
workDate,
|
|
67
74
|
workShift: 'NA'
|
|
68
75
|
}
|
|
69
76
|
}
|