@pittica/google-business-intelligence-helpers 1.13.2 → 1.14.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/dist/index.js +5 -1
- package/dist/naming/date.js +32 -5
- package/package.json +8 -5
package/dist/index.js
CHANGED
|
@@ -38,7 +38,9 @@ const {
|
|
|
38
38
|
stringToDateUTC,
|
|
39
39
|
getNow,
|
|
40
40
|
formatDate,
|
|
41
|
-
|
|
41
|
+
formatDateUTC,
|
|
42
|
+
getDatesUntil,
|
|
43
|
+
getFormattedDate
|
|
42
44
|
} = require("./naming/date");
|
|
43
45
|
const {
|
|
44
46
|
isDataCsv
|
|
@@ -78,7 +80,9 @@ exports.stringToDate = stringToDate;
|
|
|
78
80
|
exports.stringToDateUTC = stringToDateUTC;
|
|
79
81
|
exports.getNow = getNow;
|
|
80
82
|
exports.formatDate = formatDate;
|
|
83
|
+
exports.formatDateUTC = formatDateUTC;
|
|
81
84
|
exports.getDatesUntil = getDatesUntil;
|
|
85
|
+
exports.getFormattedDate = getFormattedDate;
|
|
82
86
|
exports.isDataCsv = isDataCsv;
|
|
83
87
|
exports.getFilenameVersion = getFilenameVersion;
|
|
84
88
|
exports.incrementFilenameVersion = incrementFilenameVersion;
|
package/dist/naming/date.js
CHANGED
|
@@ -77,19 +77,46 @@ exports.getNow = (dateFormat = "YYYY-MM-DD") => this.formatDate(new Date(), date
|
|
|
77
77
|
*/
|
|
78
78
|
exports.formatDate = (date, dateFormat = "YYYY-MM-DD") => format(date, dateFormat);
|
|
79
79
|
|
|
80
|
+
/**
|
|
81
|
+
* Gets the given date in the given format UTC.
|
|
82
|
+
*
|
|
83
|
+
* @param {Date} date Date object.
|
|
84
|
+
* @param {string} dateFormat Format string.
|
|
85
|
+
* @returns {string} The given date in the given UTC format.
|
|
86
|
+
*/
|
|
87
|
+
exports.formatDateUTC = (date, dateFormat = "YYYY-MM-DD") => format(date, dateFormat, true);
|
|
88
|
+
|
|
80
89
|
/**
|
|
81
90
|
* Gets the dates from the beginning of the year of the given date.
|
|
82
91
|
*
|
|
83
92
|
* @param {Date} until The day at the end of the loop.
|
|
93
|
+
* @param {string} dateFormat Format string.
|
|
84
94
|
* @returns {Array} The dates from the beginning of the year of the given date.
|
|
85
95
|
*/
|
|
86
|
-
exports.getDatesUntil = (until = new Date()) => {
|
|
96
|
+
exports.getDatesUntil = (until = new Date(), dateFormat = "YYYY-MM-DD") => {
|
|
87
97
|
const dates = [];
|
|
88
|
-
const year = until.
|
|
98
|
+
const year = until.getUTCFullYear();
|
|
89
99
|
let current = new Date(Date.UTC(year, 0, 1));
|
|
90
|
-
while (current <= until && current.
|
|
91
|
-
dates.push(this.
|
|
92
|
-
current.
|
|
100
|
+
while (current <= until && current.getUTCFullYear() === year) {
|
|
101
|
+
dates.push(this.formatDateUTC(current, dateFormat));
|
|
102
|
+
current.setUTCDate(current.getUTCDate() + 1);
|
|
93
103
|
}
|
|
94
104
|
return dates;
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Gets the formatted date for the specified date or the previous day if no date is provided.
|
|
109
|
+
*
|
|
110
|
+
* @param {Date|string} date Date to format.
|
|
111
|
+
* @param {string} dateFormat Format string.
|
|
112
|
+
* @returns {string} Formatted date.
|
|
113
|
+
*/
|
|
114
|
+
exports.getFormattedDate = (date = null, dateFormat = "YYYY-MM-DD") => {
|
|
115
|
+
if (date != null) {
|
|
116
|
+
return this.formatDate(typeof date === "string" ? this.stringToDate(date) : date, dateFormat);
|
|
117
|
+
} else {
|
|
118
|
+
const now = this.stringToDate(this.getNow());
|
|
119
|
+
now.setDate(now.getDate() - 1);
|
|
120
|
+
return this.formatDate(now, dateFormat);
|
|
121
|
+
}
|
|
95
122
|
};
|
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.14.0",
|
|
5
5
|
"description": "Helpers for business intelligence for Google Cloud.",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"scripts": {
|
|
@@ -25,15 +25,18 @@
|
|
|
25
25
|
"bugs": {
|
|
26
26
|
"url": "https://github.com/pittica/google-business-intelligence-helpers/issues"
|
|
27
27
|
},
|
|
28
|
-
"homepage": "https://github.com/pittica/google-business-intelligence-helpers
|
|
28
|
+
"homepage": "https://github.com/pittica/google-business-intelligence-helpers",
|
|
29
|
+
"engines": {
|
|
30
|
+
"node": ">=24.11.0"
|
|
31
|
+
},
|
|
29
32
|
"dependencies": {
|
|
30
33
|
"@pittica/google-cloud-storage-helpers": "^1.5.0",
|
|
31
|
-
"date-and-time": "^4.
|
|
34
|
+
"date-and-time": "^4.6.0"
|
|
32
35
|
},
|
|
33
36
|
"devDependencies": {
|
|
34
|
-
"@babel/cli": "^
|
|
37
|
+
"@babel/cli": "^8.0.6",
|
|
35
38
|
"mkdirp": "^3.0.1",
|
|
36
|
-
"prettier": "^3.9.
|
|
39
|
+
"prettier": "^3.9.10",
|
|
37
40
|
"rimraf": "^6.1.3",
|
|
38
41
|
"run-func": "^3.0.0"
|
|
39
42
|
}
|