@8ms/helpers 2.2.22 → 2.2.24
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/.yarn/install-state.gz +0 -0
- package/adverity/server/getJobs.js +3 -3
- package/date/calculation.d.ts +1 -1
- package/date/calculation.js +31 -36
- package/date/financialYear.js +4 -4
- package/date/format.d.ts +1 -1
- package/date/format.js +3 -4
- package/number/getPercent.d.ts +1 -0
- package/number/getPercent.js +11 -0
- package/number/index.d.ts +1 -0
- package/number/index.js +1 -0
- package/package.json +1 -1
package/.yarn/install-state.gz
CHANGED
|
Binary file
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getLuxonDate, getToday, getYesterday, getYmdString } from "../../date";
|
|
2
2
|
import { get } from "../../axios";
|
|
3
3
|
/**
|
|
4
4
|
* Fetch all the jobs that ran yesterday by default.
|
|
@@ -6,8 +6,8 @@ import { get } from "../../axios";
|
|
|
6
6
|
* As a result, we only store the Transfer jobs as this is when it gets moved into Bigquery. If it's not in Bigquery we cant use it anyway.
|
|
7
7
|
*/
|
|
8
8
|
export const getJobs = async (apiKey, start, end, url) => {
|
|
9
|
-
const startYmd = getYmdString(start ?
|
|
10
|
-
const endYmd = getYmdString(end ?
|
|
9
|
+
const startYmd = getYmdString(start ? getLuxonDate(start) : getYesterday());
|
|
10
|
+
const endYmd = getYmdString(end ? getLuxonDate(end) : getToday());
|
|
11
11
|
const finalUrl = "undefined" !== typeof url ? url : `https://8ms.datatap.adverity.com/api/jobs/?start=${startYmd}&end=${endYmd}&page_size=300`;
|
|
12
12
|
let response = [];
|
|
13
13
|
const apiResponse = await get(finalUrl, {
|
package/date/calculation.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export declare const getUnix: (input?: InputDate) => number;
|
|
|
6
6
|
*
|
|
7
7
|
* If it's not UTC, it needs to be converted to UTC before being used.
|
|
8
8
|
*/
|
|
9
|
-
export declare const
|
|
9
|
+
export declare const getLuxonDate: (input?: InputDate, setMidnight?: boolean) => DateTime<boolean>;
|
|
10
10
|
export declare const isMonday: (input?: InputDate) => boolean;
|
|
11
11
|
export declare const isTuesday: (input?: InputDate) => boolean;
|
|
12
12
|
export declare const isWednesday: (input?: InputDate) => boolean;
|
package/date/calculation.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DateTime, Interval } from "luxon";
|
|
2
2
|
export const getUnix = (input) => {
|
|
3
|
-
return
|
|
3
|
+
return getLuxonDate(input)
|
|
4
4
|
.toUnixInteger();
|
|
5
5
|
};
|
|
6
6
|
/**
|
|
@@ -8,7 +8,7 @@ export const getUnix = (input) => {
|
|
|
8
8
|
*
|
|
9
9
|
* If it's not UTC, it needs to be converted to UTC before being used.
|
|
10
10
|
*/
|
|
11
|
-
export const
|
|
11
|
+
export const getLuxonDate = (input, setMidnight) => {
|
|
12
12
|
let instance = DateTime.now()
|
|
13
13
|
.toUTC();
|
|
14
14
|
if (input) {
|
|
@@ -57,32 +57,25 @@ export const getDate = (input, setMidnight) => {
|
|
|
57
57
|
return instance;
|
|
58
58
|
};
|
|
59
59
|
export const isMonday = (input) => {
|
|
60
|
-
|
|
61
|
-
return date.weekday === 1;
|
|
60
|
+
return getLuxonDate(input).weekday === 1;
|
|
62
61
|
};
|
|
63
62
|
export const isTuesday = (input) => {
|
|
64
|
-
|
|
65
|
-
return date.weekday === 2;
|
|
63
|
+
return getLuxonDate(input).weekday === 2;
|
|
66
64
|
};
|
|
67
65
|
export const isWednesday = (input) => {
|
|
68
|
-
|
|
69
|
-
return date.weekday === 3;
|
|
66
|
+
return getLuxonDate(input).weekday === 3;
|
|
70
67
|
};
|
|
71
68
|
export const isThursday = (input) => {
|
|
72
|
-
|
|
73
|
-
return date.weekday === 4;
|
|
69
|
+
return getLuxonDate(input).weekday === 4;
|
|
74
70
|
};
|
|
75
71
|
export const isFriday = (input) => {
|
|
76
|
-
|
|
77
|
-
return date.weekday === 6;
|
|
72
|
+
return getLuxonDate(input).weekday === 6;
|
|
78
73
|
};
|
|
79
74
|
export const isSaturday = (input) => {
|
|
80
|
-
|
|
81
|
-
return date.weekday === 6;
|
|
75
|
+
return getLuxonDate(input).weekday === 6;
|
|
82
76
|
};
|
|
83
77
|
export const isSunday = (input) => {
|
|
84
|
-
|
|
85
|
-
return date.weekday === 7;
|
|
78
|
+
return getLuxonDate(input).weekday === 7;
|
|
86
79
|
};
|
|
87
80
|
/**
|
|
88
81
|
* Determines if a given date falls on a weekend.
|
|
@@ -91,15 +84,15 @@ export const isSunday = (input) => {
|
|
|
91
84
|
* to Saturday or Sunday, where weekday values of 6 and 7 represent Saturday and Sunday, respectively.
|
|
92
85
|
*/
|
|
93
86
|
export const isWeekend = (input) => {
|
|
94
|
-
const
|
|
95
|
-
return 6 ===
|
|
87
|
+
const luxonDate = getLuxonDate(input);
|
|
88
|
+
return 6 === luxonDate.weekday || 7 === luxonDate.weekday;
|
|
96
89
|
};
|
|
97
90
|
/**
|
|
98
91
|
* Calculates the difference in minutes between two provided dates.
|
|
99
92
|
*/
|
|
100
93
|
export const differenceInMinutes = (start, end) => {
|
|
101
|
-
const startDate =
|
|
102
|
-
const endDate =
|
|
94
|
+
const startDate = getLuxonDate(start);
|
|
95
|
+
const endDate = getLuxonDate(end);
|
|
103
96
|
return endDate.diff(startDate, "minutes").minutes;
|
|
104
97
|
};
|
|
105
98
|
/**
|
|
@@ -107,8 +100,8 @@ export const differenceInMinutes = (start, end) => {
|
|
|
107
100
|
* Business days are considered as weekdays (Monday to Friday).
|
|
108
101
|
*/
|
|
109
102
|
export const differenceInBusinessDays = (start, end) => {
|
|
110
|
-
const startDate =
|
|
111
|
-
const endDate =
|
|
103
|
+
const startDate = getLuxonDate(start);
|
|
104
|
+
const endDate = getLuxonDate(end);
|
|
112
105
|
let businessDays = 0;
|
|
113
106
|
let current = startDate.startOf("day");
|
|
114
107
|
while (current < endDate.startOf("day")) {
|
|
@@ -126,10 +119,12 @@ export const differenceInBusinessDays = (start, end) => {
|
|
|
126
119
|
* https://www.gov.uk/when-do-the-clocks-change
|
|
127
120
|
*/
|
|
128
121
|
export const getDatesBetween = (start, end) => {
|
|
129
|
-
const startInstance =
|
|
130
|
-
const endInstance =
|
|
122
|
+
const startInstance = getLuxonDate(start);
|
|
123
|
+
const endInstance = getLuxonDate(end);
|
|
131
124
|
const response = Interval.fromDateTimes(startInstance.startOf("day"), endInstance.endOf("day"))
|
|
132
|
-
.splitBy({
|
|
125
|
+
.splitBy({
|
|
126
|
+
day: 1
|
|
127
|
+
})
|
|
133
128
|
.map(d => d.start);
|
|
134
129
|
return response;
|
|
135
130
|
};
|
|
@@ -138,10 +133,10 @@ export const getDatesBetween = (start, end) => {
|
|
|
138
133
|
*/
|
|
139
134
|
export const getMonthsBetween = (start, end) => {
|
|
140
135
|
const months = [];
|
|
141
|
-
const endDate =
|
|
136
|
+
const endDate = getLuxonDate(end)
|
|
142
137
|
.startOf("month");
|
|
143
138
|
// Start from the 1st of the month containing startDate
|
|
144
|
-
let current =
|
|
139
|
+
let current = getLuxonDate(start)
|
|
145
140
|
.startOf("month");
|
|
146
141
|
while (current <= endDate) {
|
|
147
142
|
months.push(current);
|
|
@@ -168,7 +163,7 @@ export const getMin = (input, min) => {
|
|
|
168
163
|
* 1 weeksAgo - Tuesday (10th), return Monday (1st)
|
|
169
164
|
*/
|
|
170
165
|
export const getMonday = (input, weeksAgo) => {
|
|
171
|
-
let instance =
|
|
166
|
+
let instance = getLuxonDate(input);
|
|
172
167
|
if ("Mon" !== instance.toFormat("EEE")) {
|
|
173
168
|
// Get the ISO Day of week (Monday - 1 to Sunday - 7)
|
|
174
169
|
const isoDay = Number(instance.toFormat("E")) - 1;
|
|
@@ -184,7 +179,7 @@ export const getMonday = (input, weeksAgo) => {
|
|
|
184
179
|
* 1 weeksAgo - Tuesday (17th), return Monday (7th)
|
|
185
180
|
*/
|
|
186
181
|
export const getSunday = (input, weeksAgo) => {
|
|
187
|
-
let instance =
|
|
182
|
+
let instance = getLuxonDate(input);
|
|
188
183
|
if ("Sun" !== instance.toFormat("EEE")) {
|
|
189
184
|
// Get the ISO Day of week (Monday - 1 to Sunday - 7)
|
|
190
185
|
const isoDay = Number(instance.toFormat("E"));
|
|
@@ -229,13 +224,13 @@ export const getTwoWeeksAgo = () => {
|
|
|
229
224
|
* Creating a date from scratch (no user input), thus needs to be London time.
|
|
230
225
|
*/
|
|
231
226
|
export const getToday = (setMidnight) => {
|
|
232
|
-
return
|
|
227
|
+
return getLuxonDate(undefined, setMidnight);
|
|
233
228
|
};
|
|
234
229
|
/**
|
|
235
230
|
* From a given input, move the date back X weeksAgo
|
|
236
231
|
*/
|
|
237
232
|
export const getWeeksAgo = (input, weeksAgo) => {
|
|
238
|
-
let instance =
|
|
233
|
+
let instance = getLuxonDate(input);
|
|
239
234
|
instance = instance.plus({ weeks: weeksAgo });
|
|
240
235
|
return instance;
|
|
241
236
|
};
|
|
@@ -244,7 +239,7 @@ export const getWeeksAgo = (input, weeksAgo) => {
|
|
|
244
239
|
* Creating a date from scratch (no user input), thus needs to be London time.
|
|
245
240
|
*/
|
|
246
241
|
export const getYesterday = (input) => {
|
|
247
|
-
let instance =
|
|
242
|
+
let instance = getLuxonDate(input);
|
|
248
243
|
instance = instance.minus({ days: 1 });
|
|
249
244
|
return instance;
|
|
250
245
|
};
|
|
@@ -253,8 +248,8 @@ export const getYesterday = (input) => {
|
|
|
253
248
|
*/
|
|
254
249
|
export const isThisWeek = (start, end) => {
|
|
255
250
|
const inputWeek = {
|
|
256
|
-
start:
|
|
257
|
-
end:
|
|
251
|
+
start: getLuxonDate(start),
|
|
252
|
+
end: getLuxonDate(end),
|
|
258
253
|
};
|
|
259
254
|
const thisWeek = getThisWeek();
|
|
260
255
|
// Day confirms same year and month and day
|
|
@@ -265,8 +260,8 @@ export const isThisWeek = (start, end) => {
|
|
|
265
260
|
*/
|
|
266
261
|
export const isLastWeek = (start, end) => {
|
|
267
262
|
const inputWeek = {
|
|
268
|
-
start:
|
|
269
|
-
end:
|
|
263
|
+
start: getLuxonDate(start),
|
|
264
|
+
end: getLuxonDate(end),
|
|
270
265
|
};
|
|
271
266
|
const lastWeek = getLastWeek();
|
|
272
267
|
// Day confirms same year and month and day
|
package/date/financialYear.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getLuxonDate, getToday, getYesterday } from "./calculation";
|
|
2
2
|
import { Interval } from "luxon";
|
|
3
3
|
/**
|
|
4
4
|
* Get the current financial year.
|
|
@@ -9,7 +9,7 @@ export const getFinancialYear = (year) => {
|
|
|
9
9
|
if ("undefined" === typeof year) {
|
|
10
10
|
const todayInstance = getToday();
|
|
11
11
|
// If today is before 1st of April, then use last year
|
|
12
|
-
if (todayInstance <
|
|
12
|
+
if (todayInstance < getLuxonDate(`${todayInstance.toFormat("yyyy")}-04-01`)) {
|
|
13
13
|
financialYear = Number(todayInstance.toFormat("yyyy")) - 1;
|
|
14
14
|
}
|
|
15
15
|
// On or after 1st of April, use this year
|
|
@@ -18,7 +18,7 @@ export const getFinancialYear = (year) => {
|
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
// The year start needs to be 1st April this year - if its not a monday we need to shift this to the next monday.
|
|
21
|
-
let yearStartInstance =
|
|
21
|
+
let yearStartInstance = getLuxonDate(`${financialYear}-04-01`);
|
|
22
22
|
// Get the previous Monday if the 1st of April isn't a Monday
|
|
23
23
|
if ("Mon" !== yearStartInstance.toFormat("EEE")) {
|
|
24
24
|
// Get the ISO Day of the week (Monday - 1 to Sunday - 7)
|
|
@@ -29,7 +29,7 @@ export const getFinancialYear = (year) => {
|
|
|
29
29
|
}
|
|
30
30
|
// The year-end needs to be 31st March next year
|
|
31
31
|
// We are specifying the date, so don't change the timezone
|
|
32
|
-
let yearEndInstance =
|
|
32
|
+
let yearEndInstance = getLuxonDate(`${(financialYear + 1)}-03-31`);
|
|
33
33
|
// Get the next Sunday if the 31st of March isn't a Sunday
|
|
34
34
|
if ("Sun" !== yearEndInstance.toFormat("EEE")) {
|
|
35
35
|
// Get the ISO Day of the week (Monday - 1 to Sunday - 7)
|
package/date/format.d.ts
CHANGED
|
@@ -82,4 +82,4 @@ export declare const getYmdString: (input: InputDate) => string;
|
|
|
82
82
|
* Convert an Excel date "e.g. 44216" into a JavaScript date object.
|
|
83
83
|
* https://stackoverflow.com/questions/16229494/converting-excel-date-serial-number-to-date-using-javascript
|
|
84
84
|
*/
|
|
85
|
-
export declare const
|
|
85
|
+
export declare const getLuxonDateFromExcel: (serial: number) => DateTime<true> | DateTime<false>;
|
package/date/format.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getLuxonDate, getToday } from "./calculation";
|
|
2
2
|
import { DateTime } from "luxon";
|
|
3
3
|
/**
|
|
4
4
|
* Convert a number of seconds into HH:MM:SS
|
|
@@ -44,8 +44,7 @@ export const getDurationMinutes = (seconds) => {
|
|
|
44
44
|
* Simple function takes any DateTime, String or Number and formats it.
|
|
45
45
|
*/
|
|
46
46
|
export const format = (input, dateFormat) => {
|
|
47
|
-
|
|
48
|
-
return instance.toFormat(dateFormat);
|
|
47
|
+
return getLuxonDate(input).toFormat(dateFormat);
|
|
49
48
|
};
|
|
50
49
|
/**
|
|
51
50
|
* Convert a Date into a dd number.
|
|
@@ -147,7 +146,7 @@ export const getYmdString = (input) => {
|
|
|
147
146
|
* Convert an Excel date "e.g. 44216" into a JavaScript date object.
|
|
148
147
|
* https://stackoverflow.com/questions/16229494/converting-excel-date-serial-number-to-date-using-javascript
|
|
149
148
|
*/
|
|
150
|
-
export const
|
|
149
|
+
export const getLuxonDateFromExcel = (serial) => {
|
|
151
150
|
const utcDates = Math.floor(serial - 25569);
|
|
152
151
|
const utcValue = utcDates * 86400;
|
|
153
152
|
const dateInfo = new Date(utcValue * 1000);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const getPercent: (numerator: any, divisor: any, dp?: number) => number;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { getSafeDivide } from "./getSafeDivide";
|
|
2
|
+
export const getPercent = (numerator, divisor, dp) => {
|
|
3
|
+
const finalNumerator = Number(numerator);
|
|
4
|
+
const finalDivisor = Number(divisor);
|
|
5
|
+
const finalDp = Number(dp || 1);
|
|
6
|
+
return Number((getSafeDivide({
|
|
7
|
+
defaultValue: 0,
|
|
8
|
+
numerator: finalNumerator,
|
|
9
|
+
divisor: finalDivisor,
|
|
10
|
+
}) * 100).toFixed(finalDp));
|
|
11
|
+
};
|
package/number/index.d.ts
CHANGED
package/number/index.js
CHANGED