@psmarketplace/config 11.8.0-alpha.20 → 11.8.0-alpha.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.
- package/dist/date.js +76 -0
- package/dist/date.js.map +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/types/date.d.ts +6 -0
- package/dist/types/date.d.ts.map +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +5 -2
- package/src/date.ts +90 -0
- package/src/index.ts +2 -0
package/dist/date.js
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getDaysToClose = exports.getDateToClose = exports.dayjsParis = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const dayjs_1 = tslib_1.__importDefault(require("dayjs"));
|
|
6
|
+
const utc_1 = tslib_1.__importDefault(require("dayjs/plugin/utc"));
|
|
7
|
+
const timezone_1 = tslib_1.__importDefault(require("dayjs/plugin/timezone"));
|
|
8
|
+
const articho = tslib_1.__importStar(require("./types"));
|
|
9
|
+
// Extend dayjs with plugins
|
|
10
|
+
dayjs_1.default.extend(utc_1.default);
|
|
11
|
+
dayjs_1.default.extend(timezone_1.default);
|
|
12
|
+
const dayjsParis = (args) => (0, dayjs_1.default)(args).tz('Europe/Paris');
|
|
13
|
+
exports.dayjsParis = dayjsParis;
|
|
14
|
+
const getDateToClose = (publishDate, daysToClose, emergencyType) => {
|
|
15
|
+
if (emergencyType) {
|
|
16
|
+
const hoursToAdd = emergencyType === articho.EmergencyType.ASSIGN ? 4 : 24;
|
|
17
|
+
const published = (0, exports.dayjsParis)(publishDate);
|
|
18
|
+
const noon = published.hour(12).minute(0).second(0).millisecond(0);
|
|
19
|
+
let startTime;
|
|
20
|
+
if (published.isBefore(noon)) {
|
|
21
|
+
// Published before noon: start counting from the next full hour
|
|
22
|
+
// e.g. published at 9:35 → startTime = 10:00
|
|
23
|
+
const hasRemainingMinutes = published.minute() > 0 || published.second() > 0;
|
|
24
|
+
startTime = hasRemainingMinutes
|
|
25
|
+
? published.add(1, 'hour').startOf('hour')
|
|
26
|
+
: published.startOf('hour');
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
// Published at or after noon: start counting from 8:00 AM next day
|
|
30
|
+
startTime = published
|
|
31
|
+
.add(1, 'day')
|
|
32
|
+
.hour(8)
|
|
33
|
+
.minute(0)
|
|
34
|
+
.second(0)
|
|
35
|
+
.millisecond(0);
|
|
36
|
+
}
|
|
37
|
+
// Skip weekends for the start time
|
|
38
|
+
while (startTime.day() === 0 || startTime.day() === 6) {
|
|
39
|
+
startTime = startTime.add(1, 'day');
|
|
40
|
+
}
|
|
41
|
+
let result = startTime;
|
|
42
|
+
let remainingHours = hoursToAdd;
|
|
43
|
+
while (remainingHours > 0) {
|
|
44
|
+
result = result.add(1, 'hour');
|
|
45
|
+
while (result.day() === 0 || result.day() === 6) {
|
|
46
|
+
result = result.add(1, 'day');
|
|
47
|
+
}
|
|
48
|
+
remainingHours--;
|
|
49
|
+
}
|
|
50
|
+
return result;
|
|
51
|
+
}
|
|
52
|
+
// Standard logic: count business days, closes at 12:00 the next day
|
|
53
|
+
let date = (0, exports.dayjsParis)(publishDate).startOf('days');
|
|
54
|
+
let addedDays = 0;
|
|
55
|
+
while (addedDays < daysToClose) {
|
|
56
|
+
date = date.add(1, 'day');
|
|
57
|
+
if (date.day() !== 0 && date.day() !== 6) {
|
|
58
|
+
addedDays++;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
let closeDate = date.add(1, 'day');
|
|
62
|
+
while (closeDate.day() === 0 || closeDate.day() === 6) {
|
|
63
|
+
closeDate = closeDate.add(1, 'day');
|
|
64
|
+
}
|
|
65
|
+
return closeDate.hour(12).minute(0).second(0).millisecond(0);
|
|
66
|
+
};
|
|
67
|
+
exports.getDateToClose = getDateToClose;
|
|
68
|
+
const getDaysToClose = (publishDate, daysToClose, emergencyType) => {
|
|
69
|
+
const dateToClose = (0, exports.getDateToClose)(publishDate, daysToClose, emergencyType);
|
|
70
|
+
const now = emergencyType ? (0, exports.dayjsParis)() : (0, exports.dayjsParis)().startOf('days');
|
|
71
|
+
// For emergencies: return total minutes remaining (can be negative if expired)
|
|
72
|
+
// For standard: return remaining business days
|
|
73
|
+
return dateToClose.diff(now, emergencyType ? 'minute' : 'day');
|
|
74
|
+
};
|
|
75
|
+
exports.getDaysToClose = getDaysToClose;
|
|
76
|
+
//# sourceMappingURL=date.js.map
|
package/dist/date.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"date.js","sourceRoot":"","sources":["../src/date.ts"],"names":[],"mappings":";;;;AAAA,0DAA0B;AAC1B,mEAAmC;AACnC,6EAA6C;AAC7C,yDAAmC;AAEnC,4BAA4B;AAC5B,eAAK,CAAC,MAAM,CAAC,aAAG,CAAC,CAAC;AAClB,eAAK,CAAC,MAAM,CAAC,kBAAQ,CAAC,CAAC;AAEhB,MAAM,UAAU,GAAG,CAAC,IAAuB,EAAE,EAAE,CAAC,IAAA,eAAK,EAAC,IAAI,CAAC,CAAC,EAAE,CAAC,cAAc,CAAC,CAAC;AAAzE,QAAA,UAAU,cAA+D;AAE/E,MAAM,cAAc,GAAG,CAC5B,WAAmB,EACnB,WAAmB,EACnB,aAAqC,EACxB,EAAE;IACf,IAAI,aAAa,EAAE,CAAC;QAClB,MAAM,UAAU,GAAG,aAAa,KAAK,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QAE3E,MAAM,SAAS,GAAG,IAAA,kBAAU,EAAC,WAAW,CAAC,CAAC;QAC1C,MAAM,IAAI,GAAG,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC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AU,GAAE,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IACxE,+EAA+E;IAC/E,+CAA+C;IAC/C,OAAO,WAAW,CAAC,IAAI,CAAC,GAAG,EAAE,aAAa,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;AACjE,CAAC,CAAC;AAVW,QAAA,cAAc,kBAUzB"}
|
package/dist/index.js
CHANGED
|
@@ -14,4 +14,5 @@ const articho = tslib_1.__importStar(require("./types"));
|
|
|
14
14
|
exports.articho = articho;
|
|
15
15
|
const WhatsApp = tslib_1.__importStar(require("./whatsapp"));
|
|
16
16
|
exports.WhatsApp = WhatsApp;
|
|
17
|
+
tslib_1.__exportStar(require("./date"), exports);
|
|
17
18
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;AAAA,+CAA2D;AAazD,6FAbO,0BAAY,OAaP;AADZ,uFAZqB,oBAAM,OAYrB;AAGN,qFAf6B,kBAAI,OAe7B;AAbN,gEAAgC;AAc9B,kBAdK,iBAAO,CAcL;AAZT,0DAA0B;AAOxB,eAPK,cAAI,CAOL;AANN,yDAAmC;AASjC,0BAAO;AART,6DAAuC;AAYrC,4BAAQ"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;AAAA,+CAA2D;AAazD,6FAbO,0BAAY,OAaP;AADZ,uFAZqB,oBAAM,OAYrB;AAGN,qFAf6B,kBAAI,OAe7B;AAbN,gEAAgC;AAc9B,kBAdK,iBAAO,CAcL;AAZT,0DAA0B;AAOxB,eAPK,cAAI,CAOL;AANN,yDAAmC;AASjC,0BAAO;AART,6DAAuC;AAYrC,4BAAQ;AAKV,iDAAuB"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import dayjs from 'dayjs';
|
|
2
|
+
import * as articho from './types';
|
|
3
|
+
export declare const dayjsParis: (args?: dayjs.ConfigType) => dayjs.Dayjs;
|
|
4
|
+
export declare const getDateToClose: (publishDate: number, daysToClose: number, emergencyType?: articho.EmergencyType) => dayjs.Dayjs;
|
|
5
|
+
export declare const getDaysToClose: (publishDate: number, daysToClose: number, emergencyType?: articho.EmergencyType) => number;
|
|
6
|
+
//# sourceMappingURL=date.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"date.d.ts","sourceRoot":"","sources":["../../src/date.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAG1B,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AAMnC,eAAO,MAAM,UAAU,GAAI,OAAO,KAAK,CAAC,UAAU,gBAAmC,CAAC;AAEtF,eAAO,MAAM,cAAc,GACzB,aAAa,MAAM,EACnB,aAAa,MAAM,EACnB,gBAAgB,OAAO,CAAC,aAAa,KACpC,KAAK,CAAC,KA8DR,CAAC;AAEF,eAAO,MAAM,cAAc,GACzB,aAAa,MAAM,EACnB,aAAa,MAAM,EACnB,gBAAgB,OAAO,CAAC,aAAa,KACpC,MAMF,CAAC"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -8,4 +8,5 @@ import * as WhatsApp from './whatsapp';
|
|
|
8
8
|
type DeploymentEnvironment = 'development' | 'staging' | 'production';
|
|
9
9
|
export { path, getEnv, Environments, articho, ROLE, helpers, WhatsApp, };
|
|
10
10
|
export type { DeploymentEnvironment, Environment, Helpers, FactoryCreate };
|
|
11
|
+
export * from './date';
|
|
11
12
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAC3D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eA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
|
{
|
|
2
2
|
"name": "@psmarketplace/config",
|
|
3
3
|
"author": "Tech Placeshaker <sncf.tech@placeshaker.fr>",
|
|
4
|
-
"version": "11.8.0-alpha.
|
|
4
|
+
"version": "11.8.0-alpha.21",
|
|
5
5
|
"description": "Articho configuration module",
|
|
6
6
|
"homepage": "https://github.com/placeshaker/articho#readme",
|
|
7
7
|
"license": "ISC",
|
|
@@ -21,6 +21,9 @@
|
|
|
21
21
|
"url": "git+https://github.com/placeshaker/articho.git",
|
|
22
22
|
"directory": "packages/config"
|
|
23
23
|
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"dayjs": "^1.11.20"
|
|
26
|
+
},
|
|
24
27
|
"scripts": {
|
|
25
28
|
"start": "tsc --watch",
|
|
26
29
|
"prebuild": "rm -rf dist",
|
|
@@ -29,5 +32,5 @@
|
|
|
29
32
|
"lint": "eslint --fix 'src/**/*.{ts,tsx}'",
|
|
30
33
|
"prepare": "npm run build"
|
|
31
34
|
},
|
|
32
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "ad916cd6e0df9d5a41a17a3889158474fa9d13fe"
|
|
33
36
|
}
|
package/src/date.ts
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import dayjs from 'dayjs';
|
|
2
|
+
import utc from 'dayjs/plugin/utc';
|
|
3
|
+
import timezone from 'dayjs/plugin/timezone';
|
|
4
|
+
import * as articho from './types';
|
|
5
|
+
|
|
6
|
+
// Extend dayjs with plugins
|
|
7
|
+
dayjs.extend(utc);
|
|
8
|
+
dayjs.extend(timezone);
|
|
9
|
+
|
|
10
|
+
export const dayjsParis = (args?: dayjs.ConfigType) => dayjs(args).tz('Europe/Paris');
|
|
11
|
+
|
|
12
|
+
export const getDateToClose = (
|
|
13
|
+
publishDate: number,
|
|
14
|
+
daysToClose: number,
|
|
15
|
+
emergencyType?: articho.EmergencyType
|
|
16
|
+
): dayjs.Dayjs => {
|
|
17
|
+
if (emergencyType) {
|
|
18
|
+
const hoursToAdd = emergencyType === articho.EmergencyType.ASSIGN ? 4 : 24;
|
|
19
|
+
|
|
20
|
+
const published = dayjsParis(publishDate);
|
|
21
|
+
const noon = published.hour(12).minute(0).second(0).millisecond(0);
|
|
22
|
+
|
|
23
|
+
let startTime: dayjs.Dayjs;
|
|
24
|
+
|
|
25
|
+
if (published.isBefore(noon)) {
|
|
26
|
+
// Published before noon: start counting from the next full hour
|
|
27
|
+
// e.g. published at 9:35 → startTime = 10:00
|
|
28
|
+
const hasRemainingMinutes =
|
|
29
|
+
published.minute() > 0 || published.second() > 0;
|
|
30
|
+
startTime = hasRemainingMinutes
|
|
31
|
+
? published.add(1, 'hour').startOf('hour')
|
|
32
|
+
: published.startOf('hour');
|
|
33
|
+
} else {
|
|
34
|
+
// Published at or after noon: start counting from 8:00 AM next day
|
|
35
|
+
startTime = published
|
|
36
|
+
.add(1, 'day')
|
|
37
|
+
.hour(8)
|
|
38
|
+
.minute(0)
|
|
39
|
+
.second(0)
|
|
40
|
+
.millisecond(0);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Skip weekends for the start time
|
|
44
|
+
while (startTime.day() === 0 || startTime.day() === 6) {
|
|
45
|
+
startTime = startTime.add(1, 'day');
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
let result = startTime;
|
|
49
|
+
let remainingHours = hoursToAdd;
|
|
50
|
+
|
|
51
|
+
while (remainingHours > 0) {
|
|
52
|
+
result = result.add(1, 'hour');
|
|
53
|
+
while (result.day() === 0 || result.day() === 6) {
|
|
54
|
+
result = result.add(1, 'day');
|
|
55
|
+
}
|
|
56
|
+
remainingHours--;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return result;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Standard logic: count business days, closes at 12:00 the next day
|
|
63
|
+
let date = dayjsParis(publishDate).startOf('days');
|
|
64
|
+
let addedDays = 0;
|
|
65
|
+
|
|
66
|
+
while (addedDays < daysToClose) {
|
|
67
|
+
date = date.add(1, 'day');
|
|
68
|
+
if (date.day() !== 0 && date.day() !== 6) {
|
|
69
|
+
addedDays++;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
let closeDate = date.add(1, 'day');
|
|
74
|
+
while (closeDate.day() === 0 || closeDate.day() === 6) {
|
|
75
|
+
closeDate = closeDate.add(1, 'day');
|
|
76
|
+
}
|
|
77
|
+
return closeDate.hour(12).minute(0).second(0).millisecond(0);
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
export const getDaysToClose = (
|
|
81
|
+
publishDate: number,
|
|
82
|
+
daysToClose: number,
|
|
83
|
+
emergencyType?: articho.EmergencyType
|
|
84
|
+
): number => {
|
|
85
|
+
const dateToClose = getDateToClose(publishDate, daysToClose, emergencyType);
|
|
86
|
+
const now = emergencyType ? dayjsParis() : dayjsParis().startOf('days');
|
|
87
|
+
// For emergencies: return total minutes remaining (can be negative if expired)
|
|
88
|
+
// For standard: return remaining business days
|
|
89
|
+
return dateToClose.diff(now, emergencyType ? 'minute' : 'day');
|
|
90
|
+
};
|