@awell-health/awell-extensions 1.0.221 → 1.0.222
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/src/utils/getNextDateWithinBusinessHours/getNextDateWithinBusinessHours.d.ts +9 -0
- package/dist/src/utils/getNextDateWithinBusinessHours/getNextDateWithinBusinessHours.js +31 -0
- package/dist/src/utils/getNextDateWithinBusinessHours/getNextDateWithinBusinessHours.js.map +1 -0
- package/dist/src/utils/getNextDateWithinBusinessHours/getNextDateWithinBusinessHours.test.d.ts +1 -0
- package/dist/src/utils/getNextDateWithinBusinessHours/getNextDateWithinBusinessHours.test.js +30 -0
- package/dist/src/utils/getNextDateWithinBusinessHours/getNextDateWithinBusinessHours.test.js.map +1 -0
- package/dist/src/utils/getNextDateWithinBusinessHours/index.d.ts +1 -0
- package/dist/src/utils/getNextDateWithinBusinessHours/index.js +6 -0
- package/dist/src/utils/getNextDateWithinBusinessHours/index.js.map +1 -0
- package/package.json +1 -1
@@ -0,0 +1,9 @@
|
|
1
|
+
type ISOString = string;
|
2
|
+
/**
|
3
|
+
* Function doesn't take into account weekends.
|
4
|
+
* Just checks that within any given day it's between 9 AM and 5 PM.
|
5
|
+
* - If that's the case, return the reference date
|
6
|
+
* - If not, return reference date + 1 day at 9 AM
|
7
|
+
*/
|
8
|
+
export declare const getNextDateWithinBusinessHours: (referenceDateAsISOString: ISOString) => ISOString;
|
9
|
+
export {};
|
@@ -0,0 +1,31 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.getNextDateWithinBusinessHours = void 0;
|
4
|
+
const date_fns_1 = require("date-fns");
|
5
|
+
const START_HOUR_WORKING_DAY = 9; // 9 AM
|
6
|
+
const END_HOUR_WORKING_DAY = 17; // 5 PM
|
7
|
+
/**
|
8
|
+
* Function doesn't take into account weekends.
|
9
|
+
* Just checks that within any given day it's between 9 AM and 5 PM.
|
10
|
+
* - If that's the case, return the reference date
|
11
|
+
* - If not, return reference date + 1 day at 9 AM
|
12
|
+
*/
|
13
|
+
const getNextDateWithinBusinessHours = (referenceDateAsISOString) => {
|
14
|
+
const referenceDate = new Date(referenceDateAsISOString);
|
15
|
+
if (!(0, date_fns_1.isValid)(referenceDate)) {
|
16
|
+
throw new Error('Reference date is not a valid date');
|
17
|
+
}
|
18
|
+
const hourOfReferenceDate = referenceDate.getHours();
|
19
|
+
// If before 9 AM, return 9 AM of the same day
|
20
|
+
if (hourOfReferenceDate < START_HOUR_WORKING_DAY) {
|
21
|
+
return (0, date_fns_1.formatISO)((0, date_fns_1.setHours)((0, date_fns_1.startOfDay)(referenceDate), START_HOUR_WORKING_DAY));
|
22
|
+
}
|
23
|
+
// If after 5 PM, return 9 AM of the next day
|
24
|
+
else if (hourOfReferenceDate >= END_HOUR_WORKING_DAY) {
|
25
|
+
return (0, date_fns_1.formatISO)((0, date_fns_1.setHours)((0, date_fns_1.startOfDay)((0, date_fns_1.addDays)(referenceDate, 1)), START_HOUR_WORKING_DAY));
|
26
|
+
}
|
27
|
+
// If between 9 AM and 5 PM, return the reference date
|
28
|
+
return (0, date_fns_1.formatISO)(referenceDate);
|
29
|
+
};
|
30
|
+
exports.getNextDateWithinBusinessHours = getNextDateWithinBusinessHours;
|
31
|
+
//# sourceMappingURL=getNextDateWithinBusinessHours.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"getNextDateWithinBusinessHours.js","sourceRoot":"","sources":["../../../../src/utils/getNextDateWithinBusinessHours/getNextDateWithinBusinessHours.ts"],"names":[],"mappings":";;;AAAA,uCAA4E;AAE5E,MAAM,sBAAsB,GAAG,CAAC,CAAA,CAAC,OAAO;AACxC,MAAM,oBAAoB,GAAG,EAAE,CAAA,CAAC,OAAO;AAIvC;;;;;GAKG;AACI,MAAM,8BAA8B,GAAG,CAC5C,wBAAmC,EACxB,EAAE;IACb,MAAM,aAAa,GAAG,IAAI,IAAI,CAAC,wBAAwB,CAAC,CAAA;IAExD,IAAI,CAAC,IAAA,kBAAO,EAAC,aAAa,CAAC,EAAE;QAC3B,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAA;KACtD;IAED,MAAM,mBAAmB,GAAG,aAAa,CAAC,QAAQ,EAAE,CAAA;IAEpD,8CAA8C;IAC9C,IAAI,mBAAmB,GAAG,sBAAsB,EAAE;QAChD,OAAO,IAAA,oBAAS,EACd,IAAA,mBAAQ,EAAC,IAAA,qBAAU,EAAC,aAAa,CAAC,EAAE,sBAAsB,CAAC,CAC5D,CAAA;KACF;IACD,6CAA6C;SACxC,IAAI,mBAAmB,IAAI,oBAAoB,EAAE;QACpD,OAAO,IAAA,oBAAS,EACd,IAAA,mBAAQ,EAAC,IAAA,qBAAU,EAAC,IAAA,kBAAO,EAAC,aAAa,EAAE,CAAC,CAAC,CAAC,EAAE,sBAAsB,CAAC,CACxE,CAAA;KACF;IACD,sDAAsD;IACtD,OAAO,IAAA,oBAAS,EAAC,aAAa,CAAC,CAAA;AACjC,CAAC,CAAA;AAzBY,QAAA,8BAA8B,kCAyB1C"}
|
package/dist/src/utils/getNextDateWithinBusinessHours/getNextDateWithinBusinessHours.test.d.ts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1,30 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
const getNextDateWithinBusinessHours_1 = require("./getNextDateWithinBusinessHours"); // Adjust the import path as necessary
|
4
|
+
const date_fns_1 = require("date-fns");
|
5
|
+
describe('getNextDateWithinBusinessHours', () => {
|
6
|
+
it('returns should throw an error when reference date is not a valid ISO8601 date', () => {
|
7
|
+
const mockDateString = 'hello';
|
8
|
+
expect(() => {
|
9
|
+
(0, getNextDateWithinBusinessHours_1.getNextDateWithinBusinessHours)(mockDateString);
|
10
|
+
}).toThrowError();
|
11
|
+
});
|
12
|
+
it('returns the current date in ISO format if that date is within working hours', () => {
|
13
|
+
const mockDate = (0, date_fns_1.setHours)((0, date_fns_1.startOfDay)(new Date()), 10); // 10 AM is within working hours
|
14
|
+
const mockDateString = (0, date_fns_1.formatISO)(mockDate);
|
15
|
+
expect((0, getNextDateWithinBusinessHours_1.getNextDateWithinBusinessHours)(mockDateString)).toEqual((0, date_fns_1.formatISO)(mockDate));
|
16
|
+
});
|
17
|
+
it('returns the next day at 9 AM in ISO format when the date is after working hours', () => {
|
18
|
+
const mockDate = (0, date_fns_1.setHours)((0, date_fns_1.startOfDay)(new Date()), 18); // 6 PM is after working hours
|
19
|
+
const mockDateString = (0, date_fns_1.formatISO)(mockDate);
|
20
|
+
const expectedDate = (0, date_fns_1.setHours)((0, date_fns_1.startOfDay)((0, date_fns_1.addDays)(mockDate, 1)), 9);
|
21
|
+
expect((0, getNextDateWithinBusinessHours_1.getNextDateWithinBusinessHours)(mockDateString)).toEqual((0, date_fns_1.formatISO)(expectedDate));
|
22
|
+
});
|
23
|
+
it('returns today at 9 AM in ISO format when the date is before working hours', () => {
|
24
|
+
const mockDate = (0, date_fns_1.setHours)((0, date_fns_1.startOfDay)(new Date()), 8); // 8 AM is before working hours
|
25
|
+
const mockDateString = (0, date_fns_1.formatISO)(mockDate);
|
26
|
+
const expectedDate = (0, date_fns_1.setHours)((0, date_fns_1.startOfDay)(mockDate), 9); // Should return 9 AM of the same day
|
27
|
+
expect((0, getNextDateWithinBusinessHours_1.getNextDateWithinBusinessHours)(mockDateString)).toEqual((0, date_fns_1.formatISO)(expectedDate));
|
28
|
+
});
|
29
|
+
});
|
30
|
+
//# sourceMappingURL=getNextDateWithinBusinessHours.test.js.map
|
package/dist/src/utils/getNextDateWithinBusinessHours/getNextDateWithinBusinessHours.test.js.map
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"getNextDateWithinBusinessHours.test.js","sourceRoot":"","sources":["../../../../src/utils/getNextDateWithinBusinessHours/getNextDateWithinBusinessHours.test.ts"],"names":[],"mappings":";;AAAA,qFAAiF,CAAC,sCAAsC;AACxH,uCAAmE;AAEnE,QAAQ,CAAC,gCAAgC,EAAE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U,EAAC,IAAI,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC,CAAA,CAAC,+BAA+B;QACpF,MAAM,cAAc,GAAG,IAAA,oBAAS,EAAC,QAAQ,CAAC,CAAA;QAC1C,MAAM,YAAY,GAAG,IAAA,mBAAQ,EAAC,IAAA,qBAAU,EAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAA,CAAC,qCAAqC;QAE5F,MAAM,CAAC,IAAA,+DAA8B,EAAC,cAAc,CAAC,CAAC,CAAC,OAAO,CAC5D,IAAA,oBAAS,EAAC,YAAY,CAAC,CACxB,CAAA;IACH,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
@@ -0,0 +1 @@
|
|
1
|
+
export { getNextDateWithinBusinessHours } from './getNextDateWithinBusinessHours';
|
@@ -0,0 +1,6 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.getNextDateWithinBusinessHours = void 0;
|
4
|
+
var getNextDateWithinBusinessHours_1 = require("./getNextDateWithinBusinessHours");
|
5
|
+
Object.defineProperty(exports, "getNextDateWithinBusinessHours", { enumerable: true, get: function () { return getNextDateWithinBusinessHours_1.getNextDateWithinBusinessHours; } });
|
6
|
+
//# sourceMappingURL=index.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/utils/getNextDateWithinBusinessHours/index.ts"],"names":[],"mappings":";;;AAAA,mFAAiF;AAAxE,gJAAA,8BAA8B,OAAA"}
|