@pittica/google-business-intelligence-helpers 1.10.0 → 1.12.0
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/README.md +0 -4
- package/dist/index.js +7 -1
- package/dist/naming/date.js +40 -1
- package/package.json +5 -5
package/README.md
CHANGED
package/dist/index.js
CHANGED
|
@@ -33,9 +33,12 @@ const {
|
|
|
33
33
|
} = require("./naming/dataset");
|
|
34
34
|
const {
|
|
35
35
|
partsToDate,
|
|
36
|
+
partsToDateUTC,
|
|
36
37
|
stringToDate,
|
|
38
|
+
stringToDateUTC,
|
|
37
39
|
getNow,
|
|
38
|
-
formatDate
|
|
40
|
+
formatDate,
|
|
41
|
+
getDatesUntil
|
|
39
42
|
} = require("./naming/date");
|
|
40
43
|
const {
|
|
41
44
|
isDataCsv
|
|
@@ -67,9 +70,12 @@ exports.getSafeFilenameFromBucket = getSafeFilenameFromBucket;
|
|
|
67
70
|
exports.getTemporaryTableName = getTemporaryTableName;
|
|
68
71
|
exports.getTemporaryTableSuffix = getTemporaryTableSuffix;
|
|
69
72
|
exports.partsToDate = partsToDate;
|
|
73
|
+
exports.partsToDateUTC = partsToDateUTC;
|
|
70
74
|
exports.stringToDate = stringToDate;
|
|
75
|
+
exports.stringToDateUTC = stringToDateUTC;
|
|
71
76
|
exports.getNow = getNow;
|
|
72
77
|
exports.formatDate = formatDate;
|
|
78
|
+
exports.getDatesUntil = getDatesUntil;
|
|
73
79
|
exports.isDataCsv = isDataCsv;
|
|
74
80
|
exports.getFilenameVersion = getFilenameVersion;
|
|
75
81
|
exports.incrementFilenameVersion = incrementFilenameVersion;
|
package/dist/naming/date.js
CHANGED
|
@@ -24,6 +24,14 @@ const {
|
|
|
24
24
|
*/
|
|
25
25
|
exports.partsToDate = parts => new Date(parseInt(parts[1]), parseInt(parts[2]) - 1, parseInt(parts[3]));
|
|
26
26
|
|
|
27
|
+
/**
|
|
28
|
+
* Converts the file name parts to an UTC date object.
|
|
29
|
+
*
|
|
30
|
+
* @param {Array} parts String array from regular expression split representing a date from file name.
|
|
31
|
+
* @returns {Date} The UTC date from the given array.
|
|
32
|
+
*/
|
|
33
|
+
exports.partsToDateUTC = parts => new Date(Date.UTC(parseInt(parts[1]), parseInt(parts[2]) - 1, parseInt(parts[3])));
|
|
34
|
+
|
|
27
35
|
/**
|
|
28
36
|
* Extracts a date from the given date representation.
|
|
29
37
|
*
|
|
@@ -38,6 +46,20 @@ exports.stringToDate = date => {
|
|
|
38
46
|
return null;
|
|
39
47
|
};
|
|
40
48
|
|
|
49
|
+
/**
|
|
50
|
+
* Extracts an UTC date from the given date representation.
|
|
51
|
+
*
|
|
52
|
+
* @param {string} date Date in string format YYYY-MM-DD.
|
|
53
|
+
* @returns {Date} An UTC date from the given date representation.
|
|
54
|
+
*/
|
|
55
|
+
exports.stringToDateUTC = date => {
|
|
56
|
+
const split = date.split(/^(\d{4})\-(\d{2})\-(\d{2})$/gis);
|
|
57
|
+
if (split.length === 5) {
|
|
58
|
+
return this.partsToDateUTC(split);
|
|
59
|
+
}
|
|
60
|
+
return null;
|
|
61
|
+
};
|
|
62
|
+
|
|
41
63
|
/**
|
|
42
64
|
* Gets the current date in the given format.
|
|
43
65
|
*
|
|
@@ -53,4 +75,21 @@ exports.getNow = (dateFormat = "YYYY-MM-DD") => this.formatDate(new Date(), date
|
|
|
53
75
|
* @param {string} dateFormat Format string.
|
|
54
76
|
* @returns {string} The given date in the given format.
|
|
55
77
|
*/
|
|
56
|
-
exports.formatDate = (date, dateFormat = "YYYY-MM-DD") => format(date, dateFormat);
|
|
78
|
+
exports.formatDate = (date, dateFormat = "YYYY-MM-DD") => format(date, dateFormat);
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Gets the dates from the beginning of the year of the given date.
|
|
82
|
+
*
|
|
83
|
+
* @param {Date} until The day at the end of the loop.
|
|
84
|
+
* @returns {Array} The dates from the beginning of the year of the given date.
|
|
85
|
+
*/
|
|
86
|
+
exports.getDatesUntil = (until = new Date()) => {
|
|
87
|
+
const dates = [];
|
|
88
|
+
const year = until.getFullYear();
|
|
89
|
+
let current = new Date(Date.UTC(year, 0, 1));
|
|
90
|
+
while (current <= until && current.getFullYear() === year) {
|
|
91
|
+
dates.push(formatDate(new Date(current)));
|
|
92
|
+
current.setDate(current.getDate() + 1);
|
|
93
|
+
}
|
|
94
|
+
return dates;
|
|
95
|
+
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pittica/google-business-intelligence-helpers",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.12.0",
|
|
5
5
|
"description": "Helpers for business intelligence for Google Cloud.",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"scripts": {
|
|
@@ -26,13 +26,13 @@
|
|
|
26
26
|
},
|
|
27
27
|
"homepage": "https://github.com/pittica/google-business-intelligence-helpers#README.md",
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@pittica/google-cloud-storage-helpers": "^1.
|
|
30
|
-
"date-and-time": "^
|
|
29
|
+
"@pittica/google-cloud-storage-helpers": "^1.3.1",
|
|
30
|
+
"date-and-time": "^4.1.0"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@babel/cli": "^7.
|
|
33
|
+
"@babel/cli": "^7.28.3",
|
|
34
34
|
"mkdirp": "^3.0.1",
|
|
35
|
-
"prettier": "^3.
|
|
35
|
+
"prettier": "^3.6.2",
|
|
36
36
|
"rimraf": "^6.0.1"
|
|
37
37
|
}
|
|
38
38
|
}
|