@8ms/helpers 2.0.31 → 2.0.32
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/date/calculation.d.ts +1 -1
- package/date/financialYear.d.ts +1 -1
- package/date/financialYear.js +7 -7
- package/date/format.d.ts +5 -1
- package/date/format.js +12 -4
- package/date/index.d.ts +1 -35
- package/date/index.js +1 -22
- package/date/type.d.ts +35 -0
- package/date/type.js +24 -0
- package/package.json +1 -1
package/.yarn/install-state.gz
CHANGED
|
Binary file
|
package/date/calculation.d.ts
CHANGED
package/date/financialYear.d.ts
CHANGED
package/date/financialYear.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getFinancialYearWeeks = exports.getFinancialYearToYesterday = exports.getFinancialYearToDate = exports.getFinancialYear = void 0;
|
|
4
|
-
const
|
|
4
|
+
const calculation_1 = require("./calculation");
|
|
5
5
|
const luxon_1 = require("luxon");
|
|
6
6
|
/**
|
|
7
7
|
* Get the current financial year.
|
|
@@ -10,9 +10,9 @@ const getFinancialYear = (year) => {
|
|
|
10
10
|
// Either use the current year or a specified year
|
|
11
11
|
let financialYear = year;
|
|
12
12
|
if ("undefined" === typeof year) {
|
|
13
|
-
const todayInstance = (0,
|
|
13
|
+
const todayInstance = (0, calculation_1.getToday)();
|
|
14
14
|
// If today is before 1st of April, then use last year
|
|
15
|
-
if (todayInstance < (0,
|
|
15
|
+
if (todayInstance < (0, calculation_1.getDate)(`${todayInstance.toFormat("yyyy")}-04-01`)) {
|
|
16
16
|
financialYear = Number(todayInstance.toFormat("yyyy")) - 1;
|
|
17
17
|
}
|
|
18
18
|
// On or after 1st of April, use this year
|
|
@@ -21,7 +21,7 @@ const getFinancialYear = (year) => {
|
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
// 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 = (0,
|
|
24
|
+
let yearStartInstance = (0, calculation_1.getDate)(`${financialYear}-04-01`);
|
|
25
25
|
// Get the previous Monday if the 1st of April isn't a Monday
|
|
26
26
|
if ("Mon" !== yearStartInstance.toFormat("EEE")) {
|
|
27
27
|
// Get the ISO Day of the week (Monday - 1 to Sunday - 7)
|
|
@@ -32,7 +32,7 @@ const getFinancialYear = (year) => {
|
|
|
32
32
|
}
|
|
33
33
|
// The year-end needs to be 31st March next year
|
|
34
34
|
// We are specifying the date, so don't change the timezone
|
|
35
|
-
let yearEndInstance = (0,
|
|
35
|
+
let yearEndInstance = (0, calculation_1.getDate)(`${(financialYear + 1)}-03-31`);
|
|
36
36
|
// Get the next Sunday if the 31st of March isn't a Sunday
|
|
37
37
|
if ("Sun" !== yearEndInstance.toFormat("EEE")) {
|
|
38
38
|
// Get the ISO Day of the week (Monday - 1 to Sunday - 7)
|
|
@@ -51,7 +51,7 @@ exports.getFinancialYear = getFinancialYear;
|
|
|
51
51
|
* Return the current financial year up to today.
|
|
52
52
|
*/
|
|
53
53
|
const getFinancialYearToDate = () => {
|
|
54
|
-
const todayInstance = (0,
|
|
54
|
+
const todayInstance = (0, calculation_1.getToday)();
|
|
55
55
|
const thisFinancialYear = (0, exports.getFinancialYear)();
|
|
56
56
|
return {
|
|
57
57
|
end: todayInstance,
|
|
@@ -64,7 +64,7 @@ exports.getFinancialYearToDate = getFinancialYearToDate;
|
|
|
64
64
|
* Timezone should always be London based
|
|
65
65
|
*/
|
|
66
66
|
const getFinancialYearToYesterday = () => {
|
|
67
|
-
const yesterdayInstance = (0,
|
|
67
|
+
const yesterdayInstance = (0, calculation_1.getYesterday)();
|
|
68
68
|
const thisFinancialYear = (0, exports.getFinancialYear)();
|
|
69
69
|
return {
|
|
70
70
|
end: yesterdayInstance,
|
package/date/format.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { InputDate } from "./";
|
|
1
|
+
import { InputDate } from "./type";
|
|
2
2
|
import { DateTime } from "luxon";
|
|
3
3
|
/**
|
|
4
4
|
* Convert a number of seconds into HH:MM:SS
|
|
@@ -37,6 +37,10 @@ export declare const getMonthYearString: (input: InputDate) => string;
|
|
|
37
37
|
* Shorthand to get the current date.
|
|
38
38
|
*/
|
|
39
39
|
export declare const getTodayYmdString: () => string;
|
|
40
|
+
/**
|
|
41
|
+
* Shorthand to get the current date.
|
|
42
|
+
*/
|
|
43
|
+
export declare const getTodayYmdNumber: () => number;
|
|
40
44
|
/**
|
|
41
45
|
* Convert a Date into a YYYY number.
|
|
42
46
|
*/
|
package/date/format.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseExcelDate = exports.getYmdString = exports.getYmdNumber = exports.getYmdHisString = exports.getYmdHisNumber = exports.getYearNumber = exports.getTodayYmdString = exports.getMonthYearString = exports.getFullDateTime = exports.getFullDate = exports.getDayNumber = exports.format = exports.getDurationMinutes = exports.getDurationHours = void 0;
|
|
4
|
-
const
|
|
3
|
+
exports.parseExcelDate = exports.getYmdString = exports.getYmdNumber = exports.getYmdHisString = exports.getYmdHisNumber = exports.getYearNumber = exports.getTodayYmdNumber = exports.getTodayYmdString = exports.getMonthYearString = exports.getFullDateTime = exports.getFullDate = exports.getDayNumber = exports.format = exports.getDurationMinutes = exports.getDurationHours = void 0;
|
|
4
|
+
const calculation_1 = require("./calculation");
|
|
5
5
|
const luxon_1 = require("luxon");
|
|
6
6
|
/**
|
|
7
7
|
* Convert a number of seconds into HH:MM:SS
|
|
@@ -49,7 +49,7 @@ exports.getDurationMinutes = getDurationMinutes;
|
|
|
49
49
|
* Simple function takes any DateTime, String or Number and formats it.
|
|
50
50
|
*/
|
|
51
51
|
const format = (input, dateFormat) => {
|
|
52
|
-
const instance = (0,
|
|
52
|
+
const instance = (0, calculation_1.getDate)(input);
|
|
53
53
|
return instance.toFormat(dateFormat);
|
|
54
54
|
};
|
|
55
55
|
exports.format = format;
|
|
@@ -88,10 +88,18 @@ exports.getMonthYearString = getMonthYearString;
|
|
|
88
88
|
* Shorthand to get the current date.
|
|
89
89
|
*/
|
|
90
90
|
const getTodayYmdString = () => {
|
|
91
|
-
const today = (0,
|
|
91
|
+
const today = (0, calculation_1.getToday)();
|
|
92
92
|
return (0, exports.getYmdString)(today);
|
|
93
93
|
};
|
|
94
94
|
exports.getTodayYmdString = getTodayYmdString;
|
|
95
|
+
/**
|
|
96
|
+
* Shorthand to get the current date.
|
|
97
|
+
*/
|
|
98
|
+
const getTodayYmdNumber = () => {
|
|
99
|
+
const today = (0, calculation_1.getToday)();
|
|
100
|
+
return (0, exports.getYmdNumber)(today);
|
|
101
|
+
};
|
|
102
|
+
exports.getTodayYmdNumber = getTodayYmdNumber;
|
|
95
103
|
/**
|
|
96
104
|
* Convert a Date into a YYYY number.
|
|
97
105
|
*/
|
package/date/index.d.ts
CHANGED
|
@@ -1,38 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
export type InputDate = Date | DateTime | string | number;
|
|
3
|
-
export type FinancialWeek = {
|
|
4
|
-
end: DateTime;
|
|
5
|
-
start: DateTime;
|
|
6
|
-
weekNumber: number;
|
|
7
|
-
year: number;
|
|
8
|
-
};
|
|
9
|
-
/**
|
|
10
|
-
* A timeframe has a start and an end date.
|
|
11
|
-
*/
|
|
12
|
-
export type Timeframe = {
|
|
13
|
-
end: DateTime;
|
|
14
|
-
start: DateTime;
|
|
15
|
-
};
|
|
16
|
-
export declare const defaultDate: "1901-01-01";
|
|
17
|
-
export declare const defaultDateNumber: 19010101;
|
|
18
|
-
export declare const defaultDateTime: "1901-01-01 00:00:00";
|
|
19
|
-
/**
|
|
20
|
-
* Used by Google Ads API.
|
|
21
|
-
*/
|
|
22
|
-
export declare enum Month {
|
|
23
|
-
JANUARY = "JANUARY",
|
|
24
|
-
FEBRUARY = "FEBRUARY",
|
|
25
|
-
MARCH = "MARCH",
|
|
26
|
-
APRIL = "APRIL",
|
|
27
|
-
MAY = "MAY",
|
|
28
|
-
JUNE = "JUNE",
|
|
29
|
-
JULY = "JULY",
|
|
30
|
-
AUGUST = "AUGUST",
|
|
31
|
-
SEPTEMBER = "SEPTEMBER",
|
|
32
|
-
OCTOBER = "OCTOBER",
|
|
33
|
-
NOVEMBER = "NOVEMBER",
|
|
34
|
-
DECEMBER = "DECEMBER"
|
|
35
|
-
}
|
|
1
|
+
export * from "./type";
|
|
36
2
|
export * from "./calculation";
|
|
37
3
|
export * from "./financialYear";
|
|
38
4
|
export * from "./format";
|
package/date/index.js
CHANGED
|
@@ -14,28 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
|
|
18
|
-
exports.defaultDate = "1901-01-01";
|
|
19
|
-
exports.defaultDateNumber = 19010101;
|
|
20
|
-
exports.defaultDateTime = "1901-01-01 00:00:00";
|
|
21
|
-
/**
|
|
22
|
-
* Used by Google Ads API.
|
|
23
|
-
*/
|
|
24
|
-
var Month;
|
|
25
|
-
(function (Month) {
|
|
26
|
-
Month["JANUARY"] = "JANUARY";
|
|
27
|
-
Month["FEBRUARY"] = "FEBRUARY";
|
|
28
|
-
Month["MARCH"] = "MARCH";
|
|
29
|
-
Month["APRIL"] = "APRIL";
|
|
30
|
-
Month["MAY"] = "MAY";
|
|
31
|
-
Month["JUNE"] = "JUNE";
|
|
32
|
-
Month["JULY"] = "JULY";
|
|
33
|
-
Month["AUGUST"] = "AUGUST";
|
|
34
|
-
Month["SEPTEMBER"] = "SEPTEMBER";
|
|
35
|
-
Month["OCTOBER"] = "OCTOBER";
|
|
36
|
-
Month["NOVEMBER"] = "NOVEMBER";
|
|
37
|
-
Month["DECEMBER"] = "DECEMBER";
|
|
38
|
-
})(Month || (exports.Month = Month = {}));
|
|
17
|
+
__exportStar(require("./type"), exports);
|
|
39
18
|
__exportStar(require("./calculation"), exports);
|
|
40
19
|
__exportStar(require("./financialYear"), exports);
|
|
41
20
|
__exportStar(require("./format"), exports);
|
package/date/type.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { DateTime } from "luxon";
|
|
2
|
+
export type InputDate = Date | DateTime | string | number;
|
|
3
|
+
export type FinancialWeek = {
|
|
4
|
+
end: DateTime;
|
|
5
|
+
start: DateTime;
|
|
6
|
+
weekNumber: number;
|
|
7
|
+
year: number;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* A timeframe has a start and an end date.
|
|
11
|
+
*/
|
|
12
|
+
export type Timeframe = {
|
|
13
|
+
end: DateTime;
|
|
14
|
+
start: DateTime;
|
|
15
|
+
};
|
|
16
|
+
export declare const defaultDate: "1901-01-01";
|
|
17
|
+
export declare const defaultDateNumber: 19010101;
|
|
18
|
+
export declare const defaultDateTime: "1901-01-01 00:00:00";
|
|
19
|
+
/**
|
|
20
|
+
* Used by Google Ads API.
|
|
21
|
+
*/
|
|
22
|
+
export declare enum Month {
|
|
23
|
+
JANUARY = "JANUARY",
|
|
24
|
+
FEBRUARY = "FEBRUARY",
|
|
25
|
+
MARCH = "MARCH",
|
|
26
|
+
APRIL = "APRIL",
|
|
27
|
+
MAY = "MAY",
|
|
28
|
+
JUNE = "JUNE",
|
|
29
|
+
JULY = "JULY",
|
|
30
|
+
AUGUST = "AUGUST",
|
|
31
|
+
SEPTEMBER = "SEPTEMBER",
|
|
32
|
+
OCTOBER = "OCTOBER",
|
|
33
|
+
NOVEMBER = "NOVEMBER",
|
|
34
|
+
DECEMBER = "DECEMBER"
|
|
35
|
+
}
|
package/date/type.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Month = exports.defaultDateTime = exports.defaultDateNumber = exports.defaultDate = void 0;
|
|
4
|
+
exports.defaultDate = "1901-01-01";
|
|
5
|
+
exports.defaultDateNumber = 19010101;
|
|
6
|
+
exports.defaultDateTime = "1901-01-01 00:00:00";
|
|
7
|
+
/**
|
|
8
|
+
* Used by Google Ads API.
|
|
9
|
+
*/
|
|
10
|
+
var Month;
|
|
11
|
+
(function (Month) {
|
|
12
|
+
Month["JANUARY"] = "JANUARY";
|
|
13
|
+
Month["FEBRUARY"] = "FEBRUARY";
|
|
14
|
+
Month["MARCH"] = "MARCH";
|
|
15
|
+
Month["APRIL"] = "APRIL";
|
|
16
|
+
Month["MAY"] = "MAY";
|
|
17
|
+
Month["JUNE"] = "JUNE";
|
|
18
|
+
Month["JULY"] = "JULY";
|
|
19
|
+
Month["AUGUST"] = "AUGUST";
|
|
20
|
+
Month["SEPTEMBER"] = "SEPTEMBER";
|
|
21
|
+
Month["OCTOBER"] = "OCTOBER";
|
|
22
|
+
Month["NOVEMBER"] = "NOVEMBER";
|
|
23
|
+
Month["DECEMBER"] = "DECEMBER";
|
|
24
|
+
})(Month || (exports.Month = Month = {}));
|