@8ms/helpers 2.1.4 → 2.2.10
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/.github/workflows/deploy_npmjs.yml +19 -14
- package/_class/BaseClass.js +43 -52
- package/_class/BaseNamespace.js +17 -20
- package/_class/index.js +2 -7
- package/adverity/getJobs.js +7 -11
- package/adverity/index.js +51 -54
- package/adverity/server.js +1 -5
- package/api/ApiResponseClass.js +84 -88
- package/api/functions.js +13 -22
- package/api/index.js +3 -19
- package/api/types.js +5 -9
- package/array/index.js +3 -11
- package/atInternet/index.js +10 -13
- package/aws/ec2/AwsEc2Namespace.js +34 -74
- package/aws/ec2/server.js +5 -9
- package/aws/ecs/AwsEcsNamespace.js +110 -150
- package/aws/ecs/server.js +5 -9
- package/aws/glue/AwsGlueNamespace.js +26 -66
- package/aws/glue/server.js +5 -9
- package/aws/isResponse200.js +3 -7
- package/aws/lambda/AwsLambdaNamespace.js +62 -102
- package/aws/lambda/server.js +6 -11
- package/aws/s3/AwsS3Namespace.js +347 -390
- package/aws/s3/payload.js +29 -32
- package/aws/s3/server.js +9 -14
- package/aws/server.js +5 -10
- package/aws/ses/AwsSesNamespace.js +36 -76
- package/aws/ses/SimpleEmail.js +267 -304
- package/aws/ses/server.js +6 -11
- package/aws/sqs/AwsSqsNamespace.js +49 -89
- package/aws/sqs/server.js +5 -9
- package/aws/ssm/AwsSsmNamespace.js +43 -79
- package/aws/ssm/server.js +5 -9
- package/axios/deleteRequest.js +8 -15
- package/axios/get.js +8 -15
- package/axios/index.js +3 -9
- package/axios/post.js +8 -15
- package/boolean/index.js +3 -10
- package/brightData/serpApi/buildGoogleSerpUrl.js +1 -5
- package/brightData/serpApi/buildGoogleTrendsUrl.js +1 -5
- package/brightData/serpApi/getAsyncRequestId.js +8 -12
- package/brightData/serpApi/getAsyncResults.js +8 -12
- package/brightData/serpApi/getRealtime.js +3 -7
- package/brightData/serpApi/server.js +6 -14
- package/brightData/server.js +2 -7
- package/brightData/webScraperIde/getBatch.js +3 -7
- package/brightData/webScraperIde/getRealtime.js +11 -15
- package/brightData/webScraperIde/server.js +2 -7
- package/cache/server.js +2 -7
- package/cache/test/cache.test.js +4 -6
- package/crud/index.js +1 -4
- package/crypto/getDecrypt.js +2 -39
- package/crypto/getEncrypt.js +2 -39
- package/crypto/getRandom.js +1 -5
- package/crypto/getSha256.js +4 -41
- package/crypto/index.js +4 -11
- package/date/calculation.js +70 -99
- package/date/financialYear.js +16 -23
- package/date/format.js +40 -61
- package/date/index.js +4 -20
- package/date/type.js +4 -7
- package/environment/index.js +15 -25
- package/eskimi/getAgeGroup.js +3 -7
- package/eskimi/getData.js +3 -7
- package/eskimi/getDevice.js +3 -7
- package/eskimi/getGender.js +3 -7
- package/eskimi/server.js +23 -26
- package/file/index.js +8 -46
- package/geo/countries.js +1 -4
- package/geo/index.js +2 -7
- package/geo/languages.js +1 -4
- package/google/bigQuery/GoogleBigQueryNamespace.js +108 -148
- package/google/bigQuery/loadData.js +1 -5
- package/google/bigQuery/server.js +8 -14
- package/google/server.js +1 -5
- package/google/sheets/GoogleSheetsNamespace.js +34 -74
- package/google/sheets/getAssociatedData.js +1 -5
- package/google/sheets/server.js +8 -14
- package/google/storage/GoogleCloudStorageNamespace.js +62 -102
- package/google/storage/server.js +6 -10
- package/googleAds/GoogleAdsNamespace.js +28 -68
- package/googleAds/keywordPlanner/server.js +32 -35
- package/googleAds/server.js +6 -10
- package/googlePageSpeed/GooglePageSpeedNamespace.js +21 -28
- package/googlePageSpeed/server.js +8 -12
- package/googleSearchIncidents/server.js +28 -32
- package/greenDomain/server.js +17 -21
- package/inngest/server.js +1 -4
- package/json/getJsonNewline.js +3 -7
- package/json/index.js +2 -7
- package/json/isJson.js +1 -5
- package/littleWarden/LittleWardenNamespace.js +24 -31
- package/littleWarden/getUrlStatus.js +3 -7
- package/littleWarden/server.js +14 -22
- package/lumar/api/buildRequest.js +14 -18
- package/lumar/api/getData.js +3 -7
- package/lumar/api/initClient.js +3 -7
- package/lumar/api/server.js +6 -12
- package/lumar/graphql/columns.js +1 -4
- package/lumar/graphql/getData.js +3 -7
- package/lumar/graphql/initClient.js +3 -7
- package/lumar/graphql/queries/crawl.js +1 -2
- package/lumar/graphql/queries/getCrawls.js +1 -3
- package/lumar/graphql/queries/getReportDifferences.js +3 -5
- package/lumar/graphql/queries/getRows.js +1 -3
- package/lumar/graphql/queries/getTotals.js +1 -3
- package/lumar/graphql/queries/row.js +1 -2
- package/lumar/graphql/reportTemplates.js +1 -4
- package/lumar/graphql/server.js +7 -15
- package/myTarget/server.js +3 -7
- package/nextAuth/index.js +2 -6
- package/nextAuth/isSessionReady.js +1 -5
- package/nextJs/client/LazyLoad.js +5 -12
- package/nextJs/client.js +1 -5
- package/nextJs/index.js +2 -7
- package/number/format.js +3 -7
- package/number/formatCurrency.js +1 -5
- package/number/getDecimal.js +3 -7
- package/number/getNumber.js +3 -7
- package/number/getPercentIncrease.js +4 -8
- package/number/getSafeDivide.js +6 -10
- package/number/index.js +6 -15
- package/object/index.js +1 -5
- package/object/replaceKeys.js +3 -7
- package/onePassword/OnePasswordNamespace.js +36 -76
- package/onePassword/server.js +3 -7
- package/openAi/OpenAiNamespace.js +32 -39
- package/openAi/server.js +6 -10
- package/package.json +136 -120
- package/prisma/PrismaNamespace.d.ts +3 -3
- package/prisma/PrismaNamespace.js +55 -81
- package/prisma/getDecimal.js +5 -12
- package/prisma/server.d.ts +13 -0
- package/prisma/server.js +6 -9
- package/snapchat/SnapchatNamespace.js +20 -27
- package/snapchat/server.js +6 -10
- package/sorting/byNumberAscending.js +1 -5
- package/sorting/byNumberDescending.js +1 -5
- package/sorting/byStringAscending.js +1 -5
- package/sorting/byStringDescending.js +1 -5
- package/sorting/index.js +4 -11
- package/stream/server.js +1 -5
- package/stream/sort.js +1 -5
- package/string/getCapitalised.js +3 -7
- package/string/getClean.js +17 -21
- package/string/getFolder.js +3 -10
- package/string/getProperCase.js +4 -8
- package/string/getString.js +8 -15
- package/string/getStringFromStream.js +1 -5
- package/string/getUnescaped.js +3 -10
- package/string/getWithoutAccents.js +1 -5
- package/string/getWithoutHtmlTags.js +1 -5
- package/string/getWithoutPunctuation.js +1 -5
- package/string/getWithoutUnderscores.js +1 -5
- package/string/getWithoutWhitespaces.js +1 -5
- package/string/index.js +12 -27
- package/string/reservedWords.js +5 -9
- package/swr/index.js +9 -18
- package/upTimeRobot/UpTimeRobotNamespace.js +32 -42
- package/upTimeRobot/server.js +11 -15
- package/url/index.js +12 -23
- package/url/server.js +1 -5
- package/url/writeUrlContents.js +6 -46
- package/util/defaultTo.js +5 -12
- package/util/getBrotliCompressed.js +3 -10
- package/util/getBrotliDecompressed.js +3 -10
- package/util/getClean.js +5 -9
- package/util/getError.js +1 -5
- package/util/getGzipCompressed.js +3 -10
- package/util/getGzipDecompressed.js +3 -10
- package/util/getWithoutHash.js +1 -5
- package/util/getWithoutParameter.js +1 -5
- package/util/index.js +7 -17
- package/util/isUndefined.js +3 -7
- package/util/promiseChunks.js +6 -10
- package/util/server.js +4 -11
- package/util/sleep.js +1 -5
- package/webWorker/index.js +1 -4
- package/xml/getXml.js +3 -7
- package/.yarn/install-state.gz +0 -0
- package/.yarn/releases/yarn-4.9.4.cjs +0 -942
- package/.yarnrc.yml +0 -3
- package/aws/athenaExpress/AwsAthenaNamespace.d.ts +0 -8
- package/aws/athenaExpress/AwsAthenaNamespace.js +0 -82
- package/aws/athenaExpress/server.d.ts +0 -10
- package/aws/athenaExpress/server.js +0 -40
package/date/calculation.js
CHANGED
|
@@ -1,25 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const luxon_1 = require("luxon");
|
|
5
|
-
const getUnix = (input) => {
|
|
6
|
-
return (0, exports.getDate)(input)
|
|
1
|
+
import { DateTime, Interval } from "luxon";
|
|
2
|
+
export const getUnix = (input) => {
|
|
3
|
+
return getDate(input)
|
|
7
4
|
.toUnixInteger();
|
|
8
5
|
};
|
|
9
|
-
exports.getUnix = getUnix;
|
|
10
6
|
/**
|
|
11
7
|
* Assume the input is always UTC.
|
|
12
8
|
*
|
|
13
9
|
* If it's not UTC, it needs to be converted to UTC before being used.
|
|
14
10
|
*/
|
|
15
|
-
const getDate = (input, setMidnight) => {
|
|
16
|
-
let instance =
|
|
11
|
+
export const getDate = (input, setMidnight) => {
|
|
12
|
+
let instance = DateTime.now()
|
|
17
13
|
.toUTC();
|
|
18
14
|
if (input) {
|
|
19
15
|
if (input instanceof Date) {
|
|
20
|
-
instance =
|
|
16
|
+
instance = DateTime.fromJSDate(input, { zone: "utc" });
|
|
21
17
|
}
|
|
22
|
-
else if (input instanceof
|
|
18
|
+
else if (input instanceof DateTime) {
|
|
23
19
|
instance = input.toUTC();
|
|
24
20
|
}
|
|
25
21
|
else if ("number" === typeof input) {
|
|
@@ -30,21 +26,21 @@ const getDate = (input, setMidnight) => {
|
|
|
30
26
|
const year = parseInt(dateStr.substring(0, 4));
|
|
31
27
|
const month = parseInt(dateStr.substring(4, 6));
|
|
32
28
|
const day = parseInt(dateStr.substring(6, 8));
|
|
33
|
-
instance =
|
|
29
|
+
instance = DateTime.fromObject({ year, month, day }, { zone: "utc" });
|
|
34
30
|
}
|
|
35
31
|
else if (input < 10000000000) {
|
|
36
32
|
// Unix timestamp in seconds
|
|
37
|
-
instance =
|
|
33
|
+
instance = DateTime.fromSeconds(input, { zone: "utc" });
|
|
38
34
|
}
|
|
39
35
|
else {
|
|
40
36
|
// Unix timestamp in milliseconds
|
|
41
|
-
instance =
|
|
37
|
+
instance = DateTime.fromMillis(input, { zone: "utc" });
|
|
42
38
|
}
|
|
43
39
|
}
|
|
44
40
|
else {
|
|
45
|
-
instance =
|
|
41
|
+
instance = DateTime.fromISO(input.toString(), { zone: "utc" });
|
|
46
42
|
if (!instance.isValid) {
|
|
47
|
-
instance =
|
|
43
|
+
instance = DateTime.fromFormat(input.toString(), "yyyy-MM-dd HH:mm:ss", { zone: "utc" });
|
|
48
44
|
}
|
|
49
45
|
}
|
|
50
46
|
}
|
|
@@ -60,69 +56,59 @@ const getDate = (input, setMidnight) => {
|
|
|
60
56
|
}
|
|
61
57
|
return instance;
|
|
62
58
|
};
|
|
63
|
-
|
|
64
|
-
const
|
|
65
|
-
const date = (0, exports.getDate)(input);
|
|
59
|
+
export const isMonday = (input) => {
|
|
60
|
+
const date = getDate(input);
|
|
66
61
|
return date.weekday === 1;
|
|
67
62
|
};
|
|
68
|
-
|
|
69
|
-
const
|
|
70
|
-
const date = (0, exports.getDate)(input);
|
|
63
|
+
export const isTuesday = (input) => {
|
|
64
|
+
const date = getDate(input);
|
|
71
65
|
return date.weekday === 2;
|
|
72
66
|
};
|
|
73
|
-
|
|
74
|
-
const
|
|
75
|
-
const date = (0, exports.getDate)(input);
|
|
67
|
+
export const isWednesday = (input) => {
|
|
68
|
+
const date = getDate(input);
|
|
76
69
|
return date.weekday === 3;
|
|
77
70
|
};
|
|
78
|
-
|
|
79
|
-
const
|
|
80
|
-
const date = (0, exports.getDate)(input);
|
|
71
|
+
export const isThursday = (input) => {
|
|
72
|
+
const date = getDate(input);
|
|
81
73
|
return date.weekday === 4;
|
|
82
74
|
};
|
|
83
|
-
|
|
84
|
-
const
|
|
85
|
-
const date = (0, exports.getDate)(input);
|
|
75
|
+
export const isFriday = (input) => {
|
|
76
|
+
const date = getDate(input);
|
|
86
77
|
return date.weekday === 6;
|
|
87
78
|
};
|
|
88
|
-
|
|
89
|
-
const
|
|
90
|
-
const date = (0, exports.getDate)(input);
|
|
79
|
+
export const isSaturday = (input) => {
|
|
80
|
+
const date = getDate(input);
|
|
91
81
|
return date.weekday === 6;
|
|
92
82
|
};
|
|
93
|
-
|
|
94
|
-
const
|
|
95
|
-
const date = (0, exports.getDate)(input);
|
|
83
|
+
export const isSunday = (input) => {
|
|
84
|
+
const date = getDate(input);
|
|
96
85
|
return date.weekday === 7;
|
|
97
86
|
};
|
|
98
|
-
exports.isSunday = isSunday;
|
|
99
87
|
/**
|
|
100
88
|
* Determines if a given date falls on a weekend.
|
|
101
89
|
*
|
|
102
90
|
* This function checks whether the day of the week for the provided input corresponds
|
|
103
91
|
* to Saturday or Sunday, where weekday values of 6 and 7 represent Saturday and Sunday, respectively.
|
|
104
92
|
*/
|
|
105
|
-
const isWeekend = (input) => {
|
|
106
|
-
const date =
|
|
93
|
+
export const isWeekend = (input) => {
|
|
94
|
+
const date = getDate(input);
|
|
107
95
|
return 6 === date.weekday || 7 === date.weekday;
|
|
108
96
|
};
|
|
109
|
-
exports.isWeekend = isWeekend;
|
|
110
97
|
/**
|
|
111
98
|
* Calculates the difference in minutes between two provided dates.
|
|
112
99
|
*/
|
|
113
|
-
const differenceInMinutes = (start, end) => {
|
|
114
|
-
const startDate =
|
|
115
|
-
const endDate =
|
|
100
|
+
export const differenceInMinutes = (start, end) => {
|
|
101
|
+
const startDate = getDate(start);
|
|
102
|
+
const endDate = getDate(end);
|
|
116
103
|
return endDate.diff(startDate, "minutes").minutes;
|
|
117
104
|
};
|
|
118
|
-
exports.differenceInMinutes = differenceInMinutes;
|
|
119
105
|
/**
|
|
120
106
|
* Calculates the difference in business days between two dates.
|
|
121
107
|
* Business days are considered as weekdays (Monday to Friday).
|
|
122
108
|
*/
|
|
123
|
-
const differenceInBusinessDays = (start, end) => {
|
|
124
|
-
const startDate =
|
|
125
|
-
const endDate =
|
|
109
|
+
export const differenceInBusinessDays = (start, end) => {
|
|
110
|
+
const startDate = getDate(start);
|
|
111
|
+
const endDate = getDate(end);
|
|
126
112
|
let businessDays = 0;
|
|
127
113
|
let current = startDate.startOf("day");
|
|
128
114
|
while (current < endDate.startOf("day")) {
|
|
@@ -134,30 +120,28 @@ const differenceInBusinessDays = (start, end) => {
|
|
|
134
120
|
}
|
|
135
121
|
return businessDays;
|
|
136
122
|
};
|
|
137
|
-
exports.differenceInBusinessDays = differenceInBusinessDays;
|
|
138
123
|
/**
|
|
139
124
|
* Similar to date-fns' eachDayOfInterval, however the timezone messes this function up.
|
|
140
125
|
* https://date-fns.org/v2.28.0/docs/eachDayOfInterval
|
|
141
126
|
* https://www.gov.uk/when-do-the-clocks-change
|
|
142
127
|
*/
|
|
143
|
-
const getDatesBetween = (start, end) => {
|
|
144
|
-
const startInstance =
|
|
145
|
-
const endInstance =
|
|
146
|
-
const response =
|
|
128
|
+
export const getDatesBetween = (start, end) => {
|
|
129
|
+
const startInstance = getDate(start);
|
|
130
|
+
const endInstance = getDate(end);
|
|
131
|
+
const response = Interval.fromDateTimes(startInstance.startOf("day"), endInstance.endOf("day"))
|
|
147
132
|
.splitBy({ day: 1 })
|
|
148
133
|
.map(d => d.start);
|
|
149
134
|
return response;
|
|
150
135
|
};
|
|
151
|
-
exports.getDatesBetween = getDatesBetween;
|
|
152
136
|
/**
|
|
153
137
|
* Get an array of DateTime objects representing the 1st of each month between start and end dates.
|
|
154
138
|
*/
|
|
155
|
-
const getMonthsBetween = (start, end) => {
|
|
139
|
+
export const getMonthsBetween = (start, end) => {
|
|
156
140
|
const months = [];
|
|
157
|
-
const endDate =
|
|
141
|
+
const endDate = getDate(end)
|
|
158
142
|
.startOf("month");
|
|
159
143
|
// Start from the 1st of the month containing startDate
|
|
160
|
-
let current =
|
|
144
|
+
let current = getDate(start)
|
|
161
145
|
.startOf("month");
|
|
162
146
|
while (current <= endDate) {
|
|
163
147
|
months.push(current);
|
|
@@ -166,28 +150,25 @@ const getMonthsBetween = (start, end) => {
|
|
|
166
150
|
}
|
|
167
151
|
return months;
|
|
168
152
|
};
|
|
169
|
-
exports.getMonthsBetween = getMonthsBetween;
|
|
170
153
|
/**
|
|
171
154
|
* If a given date is beyond the maximum, return the maximum.
|
|
172
155
|
*/
|
|
173
|
-
const getMax = (input, max) => {
|
|
156
|
+
export const getMax = (input, max) => {
|
|
174
157
|
return input > max ? max : input;
|
|
175
158
|
};
|
|
176
|
-
exports.getMax = getMax;
|
|
177
159
|
/**
|
|
178
160
|
* If a given date is before the minimum, return the minimum.
|
|
179
161
|
*/
|
|
180
|
-
const getMin = (input, min) => {
|
|
162
|
+
export const getMin = (input, min) => {
|
|
181
163
|
return input < min ? min : input;
|
|
182
164
|
};
|
|
183
|
-
exports.getMin = getMin;
|
|
184
165
|
/**
|
|
185
166
|
* Retrieve the closest last Monday relative to the input or today.
|
|
186
167
|
* 0 weeksAgo - Tuesday (10th), return Monday (8th)
|
|
187
168
|
* 1 weeksAgo - Tuesday (10th), return Monday (1st)
|
|
188
169
|
*/
|
|
189
|
-
const getMonday = (input, weeksAgo) => {
|
|
190
|
-
let instance =
|
|
170
|
+
export const getMonday = (input, weeksAgo) => {
|
|
171
|
+
let instance = getDate(input);
|
|
191
172
|
if ("Mon" !== instance.toFormat("EEE")) {
|
|
192
173
|
// Get the ISO Day of week (Monday - 1 to Sunday - 7)
|
|
193
174
|
const isoDay = Number(instance.toFormat("E")) - 1;
|
|
@@ -197,14 +178,13 @@ const getMonday = (input, weeksAgo) => {
|
|
|
197
178
|
instance = instance.minus({ weeks: weeksAgo ?? 0 });
|
|
198
179
|
return instance;
|
|
199
180
|
};
|
|
200
|
-
exports.getMonday = getMonday;
|
|
201
181
|
/**
|
|
202
182
|
* Retrieve the closest last Sunday relative to the input or today.
|
|
203
183
|
* 0 weeksAgo - Tuesday (17th), return Sunday (14th)
|
|
204
184
|
* 1 weeksAgo - Tuesday (17th), return Monday (7th)
|
|
205
185
|
*/
|
|
206
|
-
const getSunday = (input, weeksAgo) => {
|
|
207
|
-
let instance =
|
|
186
|
+
export const getSunday = (input, weeksAgo) => {
|
|
187
|
+
let instance = getDate(input);
|
|
208
188
|
if ("Sun" !== instance.toFormat("EEE")) {
|
|
209
189
|
// Get the ISO Day of week (Monday - 1 to Sunday - 7)
|
|
210
190
|
const isoDay = Number(instance.toFormat("E"));
|
|
@@ -214,90 +194,81 @@ const getSunday = (input, weeksAgo) => {
|
|
|
214
194
|
instance = instance.minus({ weeks: weeksAgo ?? 0 });
|
|
215
195
|
return instance;
|
|
216
196
|
};
|
|
217
|
-
exports.getSunday = getSunday;
|
|
218
197
|
/**
|
|
219
198
|
* Return an object of start/end predefined date of Last Week.
|
|
220
199
|
* Creating a date from scratch (no user input), thus needs to be London time.
|
|
221
200
|
*/
|
|
222
|
-
const getLastWeek = () => {
|
|
201
|
+
export const getLastWeek = () => {
|
|
223
202
|
return {
|
|
224
|
-
end:
|
|
225
|
-
start:
|
|
203
|
+
end: getMonday(undefined, 0),
|
|
204
|
+
start: getSunday(undefined, 1),
|
|
226
205
|
};
|
|
227
206
|
};
|
|
228
|
-
exports.getLastWeek = getLastWeek;
|
|
229
207
|
/**
|
|
230
208
|
* Return an object of start/end predefined date of This Week.
|
|
231
209
|
* Creating a date from scratch (no user input), thus needs to be London time.
|
|
232
210
|
*/
|
|
233
|
-
const getThisWeek = () => {
|
|
211
|
+
export const getThisWeek = () => {
|
|
234
212
|
return {
|
|
235
|
-
end:
|
|
236
|
-
start:
|
|
213
|
+
end: getMonday(undefined, 0),
|
|
214
|
+
start: getSunday(undefined, -1),
|
|
237
215
|
};
|
|
238
216
|
};
|
|
239
|
-
exports.getThisWeek = getThisWeek;
|
|
240
217
|
/**
|
|
241
218
|
* Return an object of start/end predefined date of Two Weeks Ago.
|
|
242
219
|
* Creating a date from scratch (no user input), thus needs to be London time.
|
|
243
220
|
*/
|
|
244
|
-
const getTwoWeeksAgo = () => {
|
|
221
|
+
export const getTwoWeeksAgo = () => {
|
|
245
222
|
return {
|
|
246
|
-
end:
|
|
247
|
-
start:
|
|
223
|
+
end: getMonday(undefined, 1),
|
|
224
|
+
start: getSunday(undefined, 2),
|
|
248
225
|
};
|
|
249
226
|
};
|
|
250
|
-
exports.getTwoWeeksAgo = getTwoWeeksAgo;
|
|
251
227
|
/**
|
|
252
228
|
* Shortcut to get today's date.
|
|
253
229
|
* Creating a date from scratch (no user input), thus needs to be London time.
|
|
254
230
|
*/
|
|
255
|
-
const getToday = (setMidnight) => {
|
|
256
|
-
return
|
|
231
|
+
export const getToday = (setMidnight) => {
|
|
232
|
+
return getDate(undefined, setMidnight);
|
|
257
233
|
};
|
|
258
|
-
exports.getToday = getToday;
|
|
259
234
|
/**
|
|
260
235
|
* From a given input, move the date back X weeksAgo
|
|
261
236
|
*/
|
|
262
|
-
const getWeeksAgo = (input, weeksAgo) => {
|
|
263
|
-
let instance =
|
|
237
|
+
export const getWeeksAgo = (input, weeksAgo) => {
|
|
238
|
+
let instance = getDate(input);
|
|
264
239
|
instance = instance.plus({ weeks: weeksAgo });
|
|
265
240
|
return instance;
|
|
266
241
|
};
|
|
267
|
-
exports.getWeeksAgo = getWeeksAgo;
|
|
268
242
|
/**
|
|
269
243
|
* Shortcut to get yesterday's date.
|
|
270
244
|
* Creating a date from scratch (no user input), thus needs to be London time.
|
|
271
245
|
*/
|
|
272
|
-
const getYesterday = (input) => {
|
|
273
|
-
let instance =
|
|
246
|
+
export const getYesterday = (input) => {
|
|
247
|
+
let instance = getDate(input);
|
|
274
248
|
instance = instance.minus({ days: 1 });
|
|
275
249
|
return instance;
|
|
276
250
|
};
|
|
277
|
-
exports.getYesterday = getYesterday;
|
|
278
251
|
/**
|
|
279
252
|
* Check to see if a given timeframe is This Week.
|
|
280
253
|
*/
|
|
281
|
-
const isThisWeek = (start, end) => {
|
|
254
|
+
export const isThisWeek = (start, end) => {
|
|
282
255
|
const inputWeek = {
|
|
283
|
-
start:
|
|
284
|
-
end:
|
|
256
|
+
start: getDate(start),
|
|
257
|
+
end: getDate(end),
|
|
285
258
|
};
|
|
286
|
-
const thisWeek =
|
|
259
|
+
const thisWeek = getThisWeek();
|
|
287
260
|
// Day confirms same year and month and day
|
|
288
261
|
return inputWeek.start.hasSame(thisWeek.start, "day") && inputWeek.end.hasSame(thisWeek.end, "day");
|
|
289
262
|
};
|
|
290
|
-
exports.isThisWeek = isThisWeek;
|
|
291
263
|
/**
|
|
292
264
|
* Check to see if a given timeframe is Last Week.
|
|
293
265
|
*/
|
|
294
|
-
const isLastWeek = (start, end) => {
|
|
266
|
+
export const isLastWeek = (start, end) => {
|
|
295
267
|
const inputWeek = {
|
|
296
|
-
start:
|
|
297
|
-
end:
|
|
268
|
+
start: getDate(start),
|
|
269
|
+
end: getDate(end),
|
|
298
270
|
};
|
|
299
|
-
const lastWeek =
|
|
271
|
+
const lastWeek = getLastWeek();
|
|
300
272
|
// Day confirms same year and month and day
|
|
301
273
|
return inputWeek.start.hasSame(lastWeek.start, "day") && inputWeek.end.hasSame(lastWeek.end, "day");
|
|
302
274
|
};
|
|
303
|
-
exports.isLastWeek = isLastWeek;
|
package/date/financialYear.js
CHANGED
|
@@ -1,18 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.getFinancialYearWeeks = exports.getFinancialYearToYesterday = exports.getFinancialYearToDate = exports.getFinancialYear = void 0;
|
|
4
|
-
const calculation_1 = require("./calculation");
|
|
5
|
-
const luxon_1 = require("luxon");
|
|
1
|
+
import { getDate, getToday, getYesterday } from "./calculation";
|
|
2
|
+
import { Interval } from "luxon";
|
|
6
3
|
/**
|
|
7
4
|
* Get the current financial year.
|
|
8
5
|
*/
|
|
9
|
-
const getFinancialYear = (year) => {
|
|
6
|
+
export const getFinancialYear = (year) => {
|
|
10
7
|
// Either use the current year or a specified year
|
|
11
8
|
let financialYear = year;
|
|
12
9
|
if ("undefined" === typeof year) {
|
|
13
|
-
const todayInstance =
|
|
10
|
+
const todayInstance = getToday();
|
|
14
11
|
// If today is before 1st of April, then use last year
|
|
15
|
-
if (todayInstance <
|
|
12
|
+
if (todayInstance < getDate(`${todayInstance.toFormat("yyyy")}-04-01`)) {
|
|
16
13
|
financialYear = Number(todayInstance.toFormat("yyyy")) - 1;
|
|
17
14
|
}
|
|
18
15
|
// On or after 1st of April, use this year
|
|
@@ -21,7 +18,7 @@ const getFinancialYear = (year) => {
|
|
|
21
18
|
}
|
|
22
19
|
}
|
|
23
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.
|
|
24
|
-
let yearStartInstance =
|
|
21
|
+
let yearStartInstance = getDate(`${financialYear}-04-01`);
|
|
25
22
|
// Get the previous Monday if the 1st of April isn't a Monday
|
|
26
23
|
if ("Mon" !== yearStartInstance.toFormat("EEE")) {
|
|
27
24
|
// Get the ISO Day of the week (Monday - 1 to Sunday - 7)
|
|
@@ -32,7 +29,7 @@ const getFinancialYear = (year) => {
|
|
|
32
29
|
}
|
|
33
30
|
// The year-end needs to be 31st March next year
|
|
34
31
|
// We are specifying the date, so don't change the timezone
|
|
35
|
-
let yearEndInstance =
|
|
32
|
+
let yearEndInstance = getDate(`${(financialYear + 1)}-03-31`);
|
|
36
33
|
// Get the next Sunday if the 31st of March isn't a Sunday
|
|
37
34
|
if ("Sun" !== yearEndInstance.toFormat("EEE")) {
|
|
38
35
|
// Get the ISO Day of the week (Monday - 1 to Sunday - 7)
|
|
@@ -46,40 +43,36 @@ const getFinancialYear = (year) => {
|
|
|
46
43
|
start: yearStartInstance,
|
|
47
44
|
};
|
|
48
45
|
};
|
|
49
|
-
exports.getFinancialYear = getFinancialYear;
|
|
50
46
|
/**
|
|
51
47
|
* Return the current financial year up to today.
|
|
52
48
|
*/
|
|
53
|
-
const getFinancialYearToDate = () => {
|
|
54
|
-
const todayInstance =
|
|
55
|
-
const thisFinancialYear =
|
|
49
|
+
export const getFinancialYearToDate = () => {
|
|
50
|
+
const todayInstance = getToday();
|
|
51
|
+
const thisFinancialYear = getFinancialYear();
|
|
56
52
|
return {
|
|
57
53
|
end: todayInstance,
|
|
58
54
|
start: thisFinancialYear.start,
|
|
59
55
|
};
|
|
60
56
|
};
|
|
61
|
-
exports.getFinancialYearToDate = getFinancialYearToDate;
|
|
62
57
|
/**
|
|
63
58
|
* Return the current financial year up to yesterday.
|
|
64
59
|
* Timezone should always be London based
|
|
65
60
|
*/
|
|
66
|
-
const getFinancialYearToYesterday = () => {
|
|
67
|
-
const yesterdayInstance =
|
|
68
|
-
const thisFinancialYear =
|
|
61
|
+
export const getFinancialYearToYesterday = () => {
|
|
62
|
+
const yesterdayInstance = getYesterday();
|
|
63
|
+
const thisFinancialYear = getFinancialYear();
|
|
69
64
|
return {
|
|
70
65
|
end: yesterdayInstance,
|
|
71
66
|
start: thisFinancialYear.start,
|
|
72
67
|
};
|
|
73
68
|
};
|
|
74
|
-
exports.getFinancialYearToYesterday = getFinancialYearToYesterday;
|
|
75
69
|
/**
|
|
76
70
|
* Get the current financial year.
|
|
77
71
|
*/
|
|
78
|
-
const getFinancialYearWeeks = (year) => {
|
|
79
|
-
const financialYear =
|
|
80
|
-
const response =
|
|
72
|
+
export const getFinancialYearWeeks = (year) => {
|
|
73
|
+
const financialYear = getFinancialYear(year);
|
|
74
|
+
const response = Interval
|
|
81
75
|
.fromDateTimes(financialYear.start, financialYear.end)
|
|
82
76
|
.splitBy({ weeks: 1 });
|
|
83
77
|
return response;
|
|
84
78
|
};
|
|
85
|
-
exports.getFinancialYearWeeks = getFinancialYearWeeks;
|
package/date/format.js
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.parseExcelDate = exports.getYmdString = exports.getYmdNumber = exports.getYmdHisString = exports.getYmdHisNumber = exports.getYearNumber = exports.getTodayYmdHisNumber = exports.getTodayYmdNumber = exports.getTodayYmdHisString = exports.getTodayYmdString = exports.getYearMonthString = exports.getMonthYearString = exports.getFullDateTime = exports.getFullDate = exports.getDayNumber = exports.format = exports.getDurationMinutes = exports.getDurationHours = void 0;
|
|
4
|
-
const calculation_1 = require("./calculation");
|
|
5
|
-
const luxon_1 = require("luxon");
|
|
1
|
+
import { getDate, getToday } from "./calculation";
|
|
2
|
+
import { DateTime } from "luxon";
|
|
6
3
|
/**
|
|
7
4
|
* Convert a number of seconds into HH:MM:SS
|
|
8
5
|
* https://www.codevertiser.com/convert-seconds-to-hours-and-minutes-javascript/
|
|
9
6
|
*/
|
|
10
|
-
const getDurationHours = (seconds) => {
|
|
7
|
+
export const getDurationHours = (seconds) => {
|
|
11
8
|
let response = "00:00:00";
|
|
12
9
|
if (seconds > 0) {
|
|
13
10
|
const calculated = {
|
|
@@ -24,12 +21,11 @@ const getDurationHours = (seconds) => {
|
|
|
24
21
|
}
|
|
25
22
|
return response;
|
|
26
23
|
};
|
|
27
|
-
exports.getDurationHours = getDurationHours;
|
|
28
24
|
/**
|
|
29
25
|
* Convert a number of seconds into MM:SS
|
|
30
26
|
* https://www.codevertiser.com/convert-seconds-to-hours-and-minutes-javascript/
|
|
31
27
|
*/
|
|
32
|
-
const getDurationMinutes = (seconds) => {
|
|
28
|
+
export const getDurationMinutes = (seconds) => {
|
|
33
29
|
let response = "00:00";
|
|
34
30
|
if (seconds > 0) {
|
|
35
31
|
const calculated = {
|
|
@@ -44,130 +40,114 @@ const getDurationMinutes = (seconds) => {
|
|
|
44
40
|
}
|
|
45
41
|
return response;
|
|
46
42
|
};
|
|
47
|
-
exports.getDurationMinutes = getDurationMinutes;
|
|
48
43
|
/**
|
|
49
44
|
* Simple function takes any DateTime, String or Number and formats it.
|
|
50
45
|
*/
|
|
51
|
-
const format = (input, dateFormat) => {
|
|
52
|
-
const instance =
|
|
46
|
+
export const format = (input, dateFormat) => {
|
|
47
|
+
const instance = getDate(input);
|
|
53
48
|
return instance.toFormat(dateFormat);
|
|
54
49
|
};
|
|
55
|
-
exports.format = format;
|
|
56
50
|
/**
|
|
57
51
|
* Convert a Date into a dd number.
|
|
58
52
|
*/
|
|
59
|
-
const getDayNumber = (input) => {
|
|
60
|
-
return Number(
|
|
53
|
+
export const getDayNumber = (input) => {
|
|
54
|
+
return Number(format(input, "dd"));
|
|
61
55
|
};
|
|
62
|
-
exports.getDayNumber = getDayNumber;
|
|
63
56
|
/**
|
|
64
57
|
* Whenever we are displaying a month and year date in Codex, this will be the standardised format.
|
|
65
58
|
* Example: 1901-02-03 → 3 Feb 1901
|
|
66
59
|
*/
|
|
67
|
-
const getFullDate = (input) => {
|
|
68
|
-
return
|
|
60
|
+
export const getFullDate = (input) => {
|
|
61
|
+
return format(input, "d MMM yyyy");
|
|
69
62
|
};
|
|
70
|
-
exports.getFullDate = getFullDate;
|
|
71
63
|
/**
|
|
72
64
|
* Whenever we are displaying a month and year date in Codex, this will be the standardised format.
|
|
73
65
|
* Example: 1901-02-03 01:23:45 → 1:23am 3 Feb 1901
|
|
74
66
|
*/
|
|
75
|
-
const getFullDateTime = (input) => {
|
|
76
|
-
return
|
|
67
|
+
export const getFullDateTime = (input) => {
|
|
68
|
+
return format(input, "d MMM yyyy h:mm:ss");
|
|
77
69
|
};
|
|
78
|
-
exports.getFullDateTime = getFullDateTime;
|
|
79
70
|
/**
|
|
80
71
|
* Returns a MMM YYYY value as a number for a given year.
|
|
81
72
|
* Example: 1901-02-03 → Feb 1901
|
|
82
73
|
*/
|
|
83
|
-
const getMonthYearString = (input) => {
|
|
84
|
-
return
|
|
74
|
+
export const getMonthYearString = (input) => {
|
|
75
|
+
return format(input, "MMM yyyy");
|
|
85
76
|
};
|
|
86
|
-
exports.getMonthYearString = getMonthYearString;
|
|
87
77
|
/**
|
|
88
78
|
* Returns a YYYY MMM value as a number for a given year.
|
|
89
79
|
* Example: 1901-02-03 → 1901 Feb
|
|
90
80
|
*/
|
|
91
|
-
const getYearMonthString = (input) => {
|
|
92
|
-
return
|
|
81
|
+
export const getYearMonthString = (input) => {
|
|
82
|
+
return format(input, "yyyy MMM");
|
|
93
83
|
};
|
|
94
|
-
exports.getYearMonthString = getYearMonthString;
|
|
95
84
|
/**
|
|
96
85
|
* Shorthand to get the current date.
|
|
97
86
|
*/
|
|
98
|
-
const getTodayYmdString = (setMidnight) => {
|
|
99
|
-
const today =
|
|
100
|
-
return
|
|
87
|
+
export const getTodayYmdString = (setMidnight) => {
|
|
88
|
+
const today = getToday(setMidnight);
|
|
89
|
+
return getYmdString(today);
|
|
101
90
|
};
|
|
102
|
-
exports.getTodayYmdString = getTodayYmdString;
|
|
103
91
|
/**
|
|
104
92
|
* Shorthand to get the current date.
|
|
105
93
|
*/
|
|
106
|
-
const getTodayYmdHisString = (setMidnight) => {
|
|
107
|
-
const today =
|
|
108
|
-
return
|
|
94
|
+
export const getTodayYmdHisString = (setMidnight) => {
|
|
95
|
+
const today = getToday(setMidnight);
|
|
96
|
+
return getYmdHisString(today);
|
|
109
97
|
};
|
|
110
|
-
exports.getTodayYmdHisString = getTodayYmdHisString;
|
|
111
98
|
/**
|
|
112
99
|
* Shorthand to get the current date.
|
|
113
100
|
*/
|
|
114
|
-
const getTodayYmdNumber = (setMidnight) => {
|
|
115
|
-
const today =
|
|
116
|
-
return
|
|
101
|
+
export const getTodayYmdNumber = (setMidnight) => {
|
|
102
|
+
const today = getToday(setMidnight);
|
|
103
|
+
return getYmdNumber(today);
|
|
117
104
|
};
|
|
118
|
-
exports.getTodayYmdNumber = getTodayYmdNumber;
|
|
119
105
|
/**
|
|
120
106
|
* Shorthand to get the current date.
|
|
121
107
|
*/
|
|
122
|
-
const getTodayYmdHisNumber = (setMidnight) => {
|
|
123
|
-
const today =
|
|
124
|
-
return
|
|
108
|
+
export const getTodayYmdHisNumber = (setMidnight) => {
|
|
109
|
+
const today = getToday(setMidnight);
|
|
110
|
+
return getYmdHisNumber(today);
|
|
125
111
|
};
|
|
126
|
-
exports.getTodayYmdHisNumber = getTodayYmdHisNumber;
|
|
127
112
|
/**
|
|
128
113
|
* Convert a Date into a YYYY number.
|
|
129
114
|
*/
|
|
130
|
-
const getYearNumber = (input) => {
|
|
131
|
-
return Number(
|
|
115
|
+
export const getYearNumber = (input) => {
|
|
116
|
+
return Number(format(input, "yyyy"));
|
|
132
117
|
};
|
|
133
|
-
exports.getYearNumber = getYearNumber;
|
|
134
118
|
/**
|
|
135
119
|
* Returns a YYYYMMDDHHIISS value as a number.
|
|
136
120
|
* Example: 1901-02-03 01:23:45 → 19010203012345
|
|
137
121
|
*/
|
|
138
|
-
const getYmdHisNumber = (input) => {
|
|
139
|
-
return Number(
|
|
122
|
+
export const getYmdHisNumber = (input) => {
|
|
123
|
+
return Number(format(input, "yyyyMMddHHmmss"));
|
|
140
124
|
};
|
|
141
|
-
exports.getYmdHisNumber = getYmdHisNumber;
|
|
142
125
|
/**
|
|
143
126
|
* Returns a YYYY-MM-DD HH:MM:SS value as a string.
|
|
144
127
|
* Example: 1901-02-03 → 1901-02-03 00:00:00
|
|
145
128
|
*/
|
|
146
|
-
const getYmdHisString = (input) => {
|
|
147
|
-
return
|
|
129
|
+
export const getYmdHisString = (input) => {
|
|
130
|
+
return format(input, "yyyy-MM-dd HH:mm:ss");
|
|
148
131
|
};
|
|
149
|
-
exports.getYmdHisString = getYmdHisString;
|
|
150
132
|
/**
|
|
151
133
|
* Returns a YYYYMMDD value as a number.
|
|
152
134
|
* Example: 1901-02-03 → 19010203
|
|
153
135
|
*/
|
|
154
|
-
const getYmdNumber = (input) => {
|
|
155
|
-
return Number(
|
|
136
|
+
export const getYmdNumber = (input) => {
|
|
137
|
+
return Number(format(input, "yyyyMMdd"));
|
|
156
138
|
};
|
|
157
|
-
exports.getYmdNumber = getYmdNumber;
|
|
158
139
|
/**
|
|
159
140
|
* Whenever we are displaying a YYYY-MM-DD date in Codex
|
|
160
141
|
* Example: 1901-02-03 → 1901-02-03
|
|
161
142
|
*/
|
|
162
|
-
const getYmdString = (input) => {
|
|
163
|
-
return
|
|
143
|
+
export const getYmdString = (input) => {
|
|
144
|
+
return format(input, "yyyy-MM-dd");
|
|
164
145
|
};
|
|
165
|
-
exports.getYmdString = getYmdString;
|
|
166
146
|
/**
|
|
167
147
|
* Convert an Excel date "e.g. 44216" into a JavaScript date object.
|
|
168
148
|
* https://stackoverflow.com/questions/16229494/converting-excel-date-serial-number-to-date-using-javascript
|
|
169
149
|
*/
|
|
170
|
-
const parseExcelDate = (serial) => {
|
|
150
|
+
export const parseExcelDate = (serial) => {
|
|
171
151
|
const utcDates = Math.floor(serial - 25569);
|
|
172
152
|
const utcValue = utcDates * 86400;
|
|
173
153
|
const dateInfo = new Date(utcValue * 1000);
|
|
@@ -177,6 +157,5 @@ const parseExcelDate = (serial) => {
|
|
|
177
157
|
totalSeconds -= seconds;
|
|
178
158
|
const hours = Math.floor(totalSeconds / (60 * 60));
|
|
179
159
|
const minutes = Math.floor(totalSeconds / 60) % 60;
|
|
180
|
-
return
|
|
160
|
+
return DateTime.fromISO(`${dateInfo.getFullYear()}-${dateInfo.getMonth()}-${dateInfo.getDate()}T${hours}:${minutes}:${seconds}Z`);
|
|
181
161
|
};
|
|
182
|
-
exports.parseExcelDate = parseExcelDate;
|
package/date/index.js
CHANGED
|
@@ -1,20 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./type"), exports);
|
|
18
|
-
__exportStar(require("./calculation"), exports);
|
|
19
|
-
__exportStar(require("./financialYear"), exports);
|
|
20
|
-
__exportStar(require("./format"), exports);
|
|
1
|
+
export * from "./type";
|
|
2
|
+
export * from "./calculation";
|
|
3
|
+
export * from "./financialYear";
|
|
4
|
+
export * from "./format";
|