@8ms/helpers 1.5.4 → 1.5.5

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,10 +1,12 @@
1
1
  import { DateType } from './date';
2
+ type GetDatesBetween = {
3
+ end: DateType;
4
+ start: DateType;
5
+ };
2
6
  /**
3
7
  * Similar to date-fns' eachDayOfInterval, however the timezone messes this function up.
4
8
  * https://date-fns.org/v2.28.0/docs/eachDayOfInterval
9
+ * https://www.gov.uk/when-do-the-clocks-change
5
10
  */
6
- declare const getDatesBetween: ({ end, start }: {
7
- end: DateType;
8
- start: DateType;
9
- }) => Date[];
11
+ declare const getDatesBetween: ({ end, start }: GetDatesBetween) => Date[];
10
12
  export default getDatesBetween;
@@ -6,21 +6,41 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const addDays_1 = __importDefault(require("date-fns/addDays"));
7
7
  const format_1 = __importDefault(require("./format"));
8
8
  const getDate_1 = __importDefault(require("./getDate"));
9
+ const addHours_1 = __importDefault(require("date-fns/addHours"));
9
10
  /**
10
11
  * Similar to date-fns' eachDayOfInterval, however the timezone messes this function up.
11
12
  * https://date-fns.org/v2.28.0/docs/eachDayOfInterval
13
+ * https://www.gov.uk/when-do-the-clocks-change
12
14
  */
13
15
  const getDatesBetween = ({ end, start }) => {
14
16
  let response = [];
15
- const endDate = (0, getDate_1.default)({ input: end });
17
+ let endDate = (0, getDate_1.default)({ input: end });
18
+ // Increase the end date by 2 hours so it can handle the change in hours
19
+ endDate = (0, addHours_1.default)(endDate, 2);
16
20
  // Use a string to ensure there's no changes with the timezone
17
21
  let startString = (0, format_1.default)({ input: start });
18
22
  // Create a pointer Date instance
19
23
  let pointer = (0, getDate_1.default)({ input: startString });
20
24
  // While we before the end
21
25
  while (pointer <= endDate) {
22
- response.push(pointer);
26
+ // We need to create a new date entry so its always set to 00:00:00
27
+ const entry = (0, getDate_1.default)({
28
+ input: (0, format_1.default)({
29
+ input: pointer,
30
+ dateFormat: 'yyyy-MM-dd'
31
+ }),
32
+ setMidnight: true,
33
+ });
34
+ // Add this new entry to our response
35
+ response.push(entry);
36
+ // Move to the next day
23
37
  pointer = (0, addDays_1.default)(pointer, 1);
38
+ // Daylight saving (month is 0-base)
39
+ // -1 hour between March and September, add an hour if 0 hours
40
+ // +1 hour between October and February
41
+ if (pointer.getMonth() >= 2 && pointer.getMonth() < 8 && 0 === pointer.getHours()) {
42
+ pointer = (0, addHours_1.default)(pointer, 1);
43
+ }
24
44
  }
25
45
  return response;
26
46
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@8ms/helpers",
3
3
  "license": "UNLICENSED",
4
- "version": "1.5.4",
4
+ "version": "1.5.5",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/8millionstories-organisation/8ms-helpers-ts.git"
@@ -13,7 +13,7 @@
13
13
  "jest": "jest --watch"
14
14
  },
15
15
  "dependencies": {
16
- "axios": "1.5.0",
16
+ "axios": "1.5.1",
17
17
  "crypto-js": "4.1.1",
18
18
  "date-fns": "2.30.0",
19
19
  "date-fns-tz": "2.0.0",
@@ -21,22 +21,22 @@
21
21
  "zod": "3.22.2"
22
22
  },
23
23
  "devDependencies": {
24
- "@aws-sdk/client-s3": "3.400.0",
25
- "@aws-sdk/client-ses": "3.398.0",
26
- "@aws-sdk/client-sqs": "3.398.0",
27
- "@aws-sdk/client-ssm": "3.398.0",
28
- "@aws-sdk/s3-request-presigner": "3.400.0",
29
- "@babel/preset-env": "7.22.14",
30
- "@babel/preset-flow": "7.22.5",
31
- "@babel/preset-typescript": "7.22.11",
32
- "@google-cloud/bigquery": "7.2.0",
33
- "@google-cloud/storage": "7.0.1",
34
- "@prisma/client": "5.2.0",
35
- "@types/jest": "29.5.4",
36
- "@types/lodash": "4.14.197",
37
- "@types/node": "20.5.7",
38
- "babel-jest": "29.6.4",
39
- "jest": "29.6.4",
24
+ "@aws-sdk/client-s3": "3.423.0",
25
+ "@aws-sdk/client-ses": "3.423.0",
26
+ "@aws-sdk/client-sqs": "3.423.0",
27
+ "@aws-sdk/client-ssm": "3.423.0",
28
+ "@aws-sdk/s3-request-presigner": "3.423.0",
29
+ "@babel/preset-env": "7.22.20",
30
+ "@babel/preset-flow": "7.22.15",
31
+ "@babel/preset-typescript": "7.23.0",
32
+ "@google-cloud/bigquery": "7.3.0",
33
+ "@google-cloud/storage": "7.1.0",
34
+ "@prisma/client": "5.3.1",
35
+ "@types/jest": "29.5.5",
36
+ "@types/lodash": "4.14.199",
37
+ "@types/node": "20.8.2",
38
+ "babel-jest": "29.7.0",
39
+ "jest": "29.7.0",
40
40
  "node-fetch": "3.3.2",
41
41
  "timezone-mock": "1.3.6",
42
42
  "ts-node": "10.9.1",
@@ -0,0 +1,8 @@
1
+ type GetDecimal = {
2
+ input: any;
3
+ };
4
+ /**
5
+ * Fetch the number from a prisma decimal (comes through as an object).
6
+ */
7
+ declare const getDecimal: (props: GetDecimal) => number;
8
+ export default getDecimal;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ /**
4
+ * Fetch the number from a prisma decimal (comes through as an object).
5
+ */
6
+ const getDecimal = (props) => {
7
+ let whole = props?.input?.d?.[0] || 0;
8
+ let decimal = props?.input?.d?.[1] || 0;
9
+ return Number(`${whole}.${decimal}`);
10
+ };
11
+ exports.default = getDecimal;