@capillarytech/cap-ui-utils 1.3.5 → 1.3.6
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/package.json +1 -1
- package/utils/date/dateHelper.js +33 -23
- package/utils/date/messages.js +1 -1
package/package.json
CHANGED
package/utils/date/dateHelper.js
CHANGED
|
@@ -15,28 +15,28 @@ let _intl = {
|
|
|
15
15
|
formatNumer: () => {},
|
|
16
16
|
};
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
const initializeIntl = (intl) => {
|
|
19
19
|
_intl = intl;
|
|
20
20
|
};
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
const isPreviousDate = (current) =>
|
|
23
23
|
current < moment().subtract(1, "days").endOf("day");
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
const getPreviousHours = (date) => {
|
|
26
26
|
const momentDate = date ? moment(date) : moment();
|
|
27
27
|
return range(momentDate.hour());
|
|
28
28
|
};
|
|
29
29
|
|
|
30
|
-
|
|
30
|
+
const getPreviousMinutes = (date) => {
|
|
31
31
|
const momentDate = date ? moment(date) : moment();
|
|
32
32
|
return range(momentDate.minute());
|
|
33
33
|
};
|
|
34
34
|
|
|
35
|
-
|
|
35
|
+
const disableDateRange = (startDate, endDate) => (current) =>
|
|
36
36
|
moment(endDate).endOf("day") < current ||
|
|
37
37
|
current < moment(startDate).startOf("day");
|
|
38
38
|
|
|
39
|
-
|
|
39
|
+
const getRelativeDay = (date) => {
|
|
40
40
|
const selectedFormat = "Do MMM";
|
|
41
41
|
const todayDate = moment().format(selectedFormat);
|
|
42
42
|
const yesterdayDate = moment().subtract(1, "days").format(selectedFormat);
|
|
@@ -51,11 +51,8 @@ export const getRelativeDay = (date) => {
|
|
|
51
51
|
lastWeek: DATE_DISPLAY_FORMAT,
|
|
52
52
|
});
|
|
53
53
|
};
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
date,
|
|
57
|
-
withMilliSeconds = true,
|
|
58
|
-
}) => {
|
|
54
|
+
|
|
55
|
+
const getEpochTimeStamp = ({ timezone, date, withMilliSeconds = true }) => {
|
|
59
56
|
let method = "valueOf"; // Unix time in milliseconds: http://momentjs.com/docs/#/displaying/unix-timestamp-milliseconds/
|
|
60
57
|
if (!withMilliSeconds) {
|
|
61
58
|
method = "unix"; // unix time in seconds: http://momentjs.com/docs/#/displaying/unix-timestamp/
|
|
@@ -73,7 +70,7 @@ export const getEpochTimeStamp = ({
|
|
|
73
70
|
* @param weekDay
|
|
74
71
|
* @returns {number}
|
|
75
72
|
*/
|
|
76
|
-
|
|
73
|
+
function getISOWeekDayNumberForOrgSetting(weekDay) {
|
|
77
74
|
if (isNaN(Number(weekDay)) || Number(weekDay) > 6 || Number(weekDay) < 0) {
|
|
78
75
|
return 1;
|
|
79
76
|
}
|
|
@@ -89,7 +86,7 @@ export function getISOWeekDayNumberForOrgSetting(weekDay) {
|
|
|
89
86
|
* @param weekStart
|
|
90
87
|
* @returns {{start, end}}
|
|
91
88
|
*/
|
|
92
|
-
|
|
89
|
+
function getDateRangeForPeriod(
|
|
93
90
|
lastSyncDate,
|
|
94
91
|
baseFilter,
|
|
95
92
|
periodValue,
|
|
@@ -123,16 +120,14 @@ export function getDateRangeForPeriod(
|
|
|
123
120
|
* @param dateFormat
|
|
124
121
|
* @returns {{start, end}}
|
|
125
122
|
*/
|
|
126
|
-
|
|
127
|
-
dateRange,
|
|
128
|
-
dateFormat = STANDARD_DATE_FORMAT
|
|
129
|
-
) {
|
|
123
|
+
function getFormattedDateRange(dateRange, dateFormat = STANDARD_DATE_FORMAT) {
|
|
130
124
|
return {
|
|
131
125
|
start: dateRange.start.clone().format(dateFormat),
|
|
132
126
|
end: dateRange.end.clone().format(dateFormat),
|
|
133
127
|
};
|
|
134
128
|
}
|
|
135
|
-
|
|
129
|
+
|
|
130
|
+
const getDayDifference = (currentDate, compareDate) => {
|
|
136
131
|
// startDate, endDate can't be epoch time in seconds, as the parsing is different for that
|
|
137
132
|
const formattedCurrentDate = moment(currentDate).format(DATE_FORMAT);
|
|
138
133
|
const formattedCompareDate = moment(compareDate).format(DATE_FORMAT);
|
|
@@ -142,16 +137,31 @@ export const getDayDifference = (currentDate, compareDate) => {
|
|
|
142
137
|
);
|
|
143
138
|
};
|
|
144
139
|
|
|
145
|
-
|
|
146
|
-
moment(date).format(DATE_DISPLAY_FORMAT);
|
|
140
|
+
const msToDateFormat = (date) => moment(date).format(DATE_DISPLAY_FORMAT);
|
|
147
141
|
|
|
148
|
-
|
|
149
|
-
moment(date).format(TIME_DISPLAY_FORMAT);
|
|
142
|
+
const msToTimeFormat = (date) => moment(date).format(TIME_DISPLAY_FORMAT);
|
|
150
143
|
|
|
151
144
|
/* unix() function gives number of seconds since epoch time,
|
|
152
145
|
but for the api need to app number of days since epoch time.
|
|
153
146
|
so deviding number of seconds since epoch with number of seconds a day to get number of days since epoch
|
|
154
147
|
*/
|
|
155
148
|
|
|
156
|
-
|
|
149
|
+
const getEpochDays = (date) =>
|
|
157
150
|
date && Math.floor(moment(date.clone()).unix() / 86400); // 86400 === number of seconds a day
|
|
151
|
+
|
|
152
|
+
export default {
|
|
153
|
+
initializeIntl,
|
|
154
|
+
isPreviousDate,
|
|
155
|
+
getPreviousHours,
|
|
156
|
+
getPreviousMinutes,
|
|
157
|
+
disableDateRange,
|
|
158
|
+
getRelativeDay,
|
|
159
|
+
getEpochTimeStamp,
|
|
160
|
+
getISOWeekDayNumberForOrgSetting,
|
|
161
|
+
getDateRangeForPeriod,
|
|
162
|
+
getFormattedDateRange,
|
|
163
|
+
getDayDifference,
|
|
164
|
+
msToDateFormat,
|
|
165
|
+
msToTimeFormat,
|
|
166
|
+
getEpochDays,
|
|
167
|
+
};
|