@chayns-components/date 5.0.0-beta.769 → 5.0.0-beta.772
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/lib/cjs/components/date-info/DateInfo.js +13 -87
- package/lib/cjs/components/date-info/DateInfo.js.map +1 -1
- package/lib/cjs/hooks/useDateInfo.js +103 -0
- package/lib/cjs/hooks/useDateInfo.js.map +1 -0
- package/lib/cjs/utils/dateInfo.js +2 -7
- package/lib/cjs/utils/dateInfo.js.map +1 -1
- package/lib/esm/components/date-info/DateInfo.js +14 -88
- package/lib/esm/components/date-info/DateInfo.js.map +1 -1
- package/lib/esm/hooks/useDateInfo.js +97 -0
- package/lib/esm/hooks/useDateInfo.js.map +1 -0
- package/lib/esm/utils/dateInfo.js +2 -5
- package/lib/esm/utils/dateInfo.js.map +1 -1
- package/lib/types/components/date-info/DateInfo.d.ts +2 -34
- package/lib/types/hooks/useDateInfo.d.ts +35 -0
- package/lib/types/utils/dateInfo.d.ts +2 -2
- package/package.json +3 -3
|
@@ -4,105 +4,31 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
var _dateFns = require("date-fns");
|
|
8
7
|
var _react = _interopRequireWildcard(require("react"));
|
|
9
|
-
var
|
|
8
|
+
var _useDateInfo = require("../../hooks/useDateInfo");
|
|
10
9
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
11
10
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
12
11
|
const DateInfo = ({
|
|
13
12
|
date,
|
|
14
13
|
preText = '',
|
|
15
|
-
|
|
14
|
+
shouldShowYear,
|
|
16
15
|
shouldShowTime,
|
|
17
16
|
shouldShowRelativeDayOfWeek,
|
|
18
17
|
shouldUseShortText,
|
|
19
18
|
shouldShowDayOfWeek,
|
|
20
19
|
shouldShowDateToNowDifference
|
|
21
20
|
}) => {
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
shouldUseShortText,
|
|
34
|
-
date: formattedDate,
|
|
35
|
-
language
|
|
36
|
-
});
|
|
37
|
-
let formatString = 'dd. ';
|
|
38
|
-
formatString += `${(0, _dateInfo.getMonthFormat)({
|
|
39
|
-
shouldUseShortText
|
|
40
|
-
})}`;
|
|
41
|
-
formatString += `${(0, _dateInfo.getYearFormat)({
|
|
42
|
-
date: formattedDate,
|
|
43
|
-
shouldShowThisYear
|
|
44
|
-
})}`;
|
|
45
|
-
newFormattedDateString += (0, _dateFns.format)(formattedDate, formatString, {
|
|
46
|
-
locale: language
|
|
47
|
-
});
|
|
48
|
-
newFormattedDateString += (0, _dateInfo.getFormattedTime)({
|
|
49
|
-
date: formattedDate,
|
|
50
|
-
shouldShowTime,
|
|
51
|
-
language
|
|
52
|
-
});
|
|
53
|
-
setFormattedDateString(newFormattedDateString);
|
|
54
|
-
}, [date, formattedDate, language, shouldShowDateToNowDifference, shouldShowDayOfWeek, shouldShowRelativeDayOfWeek, shouldShowThisYear, shouldShowTime, shouldUseShortText]);
|
|
55
|
-
|
|
56
|
-
// Calculate remaining time till next minute to update time according to time left
|
|
57
|
-
const [currentDate, setCurrentDate] = (0, _react.useState)(new Date());
|
|
58
|
-
(0, _react.useEffect)(() => {
|
|
59
|
-
// This useEffect is for calculating the current date for shouldShowDateToNowDifference option
|
|
60
|
-
if (!shouldShowDateToNowDifference) {
|
|
61
|
-
return () => {};
|
|
62
|
-
}
|
|
63
|
-
let timeoutTime = formattedDate.getSeconds() - new Date().getSeconds();
|
|
64
|
-
|
|
65
|
-
// If the seconds of date are after seconds of current time, the timeoutTime has to be calculated differently
|
|
66
|
-
if (timeoutTime < 0) {
|
|
67
|
-
timeoutTime = 60 - new Date().getSeconds() + formattedDate.getSeconds();
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// initialized with remaining time
|
|
71
|
-
let timeDiffInMs = formattedDate.getTime() - currentDate.getTime();
|
|
72
|
-
|
|
73
|
-
// set to elapsed time
|
|
74
|
-
if ((0, _dateFns.isPast)(formattedDate)) {
|
|
75
|
-
timeDiffInMs = currentDate.getTime() - formattedDate.getTime();
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
// time difference is less than a minute, time should be updated every second
|
|
79
|
-
if (timeDiffInMs < 60000) {
|
|
80
|
-
timeoutTime = 1;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// Set timeoutTime to at least 1000ms
|
|
84
|
-
timeoutTime = Math.max(timeoutTime * 1000, 1000);
|
|
85
|
-
const timeout = setTimeout(() => {
|
|
86
|
-
setCurrentDate(new Date());
|
|
87
|
-
}, timeoutTime);
|
|
88
|
-
return () => {
|
|
89
|
-
clearTimeout(timeout);
|
|
90
|
-
};
|
|
91
|
-
}, [currentDate, date, formattedDate, shouldShowDateToNowDifference]);
|
|
92
|
-
(0, _react.useEffect)(() => {
|
|
93
|
-
// This useEffect is for showing the difference of the date to now
|
|
94
|
-
if (shouldShowDateToNowDifference) {
|
|
95
|
-
setFormattedDateString((0, _dateInfo.getTimeTillNow)({
|
|
96
|
-
date: formattedDate,
|
|
97
|
-
currentDate,
|
|
98
|
-
language
|
|
99
|
-
}));
|
|
100
|
-
}
|
|
101
|
-
}, [currentDate, date, formattedDate, language, shouldShowDateToNowDifference]);
|
|
102
|
-
(0, _react.useEffect)(() => {
|
|
103
|
-
setFormattedDate(new Date(date));
|
|
104
|
-
}, [date]);
|
|
105
|
-
return (0, _react.useMemo)(() => /*#__PURE__*/_react.default.createElement("span", null, preText.trim(), " ", formattedDateString), [formattedDateString, preText]);
|
|
21
|
+
const formattedDate = (0, _useDateInfo.useDateInfo)({
|
|
22
|
+
date,
|
|
23
|
+
preText,
|
|
24
|
+
shouldShowYear,
|
|
25
|
+
shouldShowTime,
|
|
26
|
+
shouldUseShortText,
|
|
27
|
+
shouldShowDayOfWeek,
|
|
28
|
+
shouldShowRelativeDayOfWeek,
|
|
29
|
+
shouldShowDateToNowDifference
|
|
30
|
+
});
|
|
31
|
+
return (0, _react.useMemo)(() => /*#__PURE__*/_react.default.createElement("span", null, formattedDate), [formattedDate]);
|
|
106
32
|
};
|
|
107
33
|
DateInfo.displayName = 'DateInfo';
|
|
108
34
|
var _default = exports.default = DateInfo;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DateInfo.js","names":["_dateFns","require","_react","_interopRequireWildcard","_dateInfo","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","DateInfo","date","preText","shouldShowThisYear","shouldShowTime","shouldShowRelativeDayOfWeek","shouldUseShortText","shouldShowDayOfWeek","shouldShowDateToNowDifference","formattedDate","setFormattedDate","useState","Date","formattedDateString","setFormattedDateString","language","getLanguage","useEffect","newFormattedDateString","getFormattedDayOfWeek","formatString","getMonthFormat","getYearFormat","format","locale","getFormattedTime","currentDate","setCurrentDate","timeoutTime","getSeconds","timeDiffInMs","getTime","isPast","Math","max","timeout","setTimeout","clearTimeout","getTimeTillNow","useMemo","createElement","trim","displayName","_default","exports"],"sources":["../../../../src/components/date-info/DateInfo.tsx"],"sourcesContent":["import { format, isPast } from 'date-fns';\nimport React, { FC, useEffect, useMemo, useState } from 'react';\nimport {\n getFormattedDayOfWeek,\n getFormattedTime,\n getLanguage,\n getMonthFormat,\n getTimeTillNow,\n getYearFormat,\n} from '../../utils/dateInfo';\n\nexport type DateInfoProps = {\n /**\n * The date, that should be displayed\n */\n date: Date | string;\n /**\n * Additional text for \"shouldShowDateToNowDifference\" prop. Writes a text before the calculated time\n */\n preText?: string;\n /**\n * Adds the current year to the display\n */\n shouldShowThisYear?: boolean;\n /**\n * Adds the time to the display.\n */\n shouldShowTime?: boolean;\n /**\n * Whether the relative day of week to today should be shown (today, yesterday or tomorrow).\n */\n shouldShowRelativeDayOfWeek?: boolean;\n /**\n * Shortens the day and month text to maximum three digits\n */\n shouldUseShortText?: boolean;\n /**\n * Adds the day of week to the display\n */\n shouldShowDayOfWeek?: boolean;\n /**\n * Shows the difference from the date to now. The component handles updates itself.\n */\n shouldShowDateToNowDifference?: boolean;\n};\n\nconst DateInfo: FC<DateInfoProps> = ({\n date,\n preText = '',\n shouldShowThisYear,\n shouldShowTime,\n shouldShowRelativeDayOfWeek,\n shouldUseShortText,\n shouldShowDayOfWeek,\n shouldShowDateToNowDifference,\n}) => {\n const [formattedDate, setFormattedDate] = useState(new Date(date));\n const [formattedDateString, setFormattedDateString] = useState<string>('');\n const [language] = useState(getLanguage());\n\n useEffect(() => {\n // This useEffect is used for normal date formation\n if (shouldShowDateToNowDifference) {\n return;\n }\n\n let newFormattedDateString = getFormattedDayOfWeek({\n shouldShowDayOfWeek,\n shouldShowRelativeDayOfWeek,\n shouldUseShortText,\n date: formattedDate,\n language,\n });\n\n let formatString = 'dd. ';\n\n formatString += `${getMonthFormat({ shouldUseShortText })}`;\n\n formatString += `${getYearFormat({\n date: formattedDate,\n shouldShowThisYear,\n })}`;\n\n newFormattedDateString += format(formattedDate, formatString, { locale: language });\n\n newFormattedDateString += getFormattedTime({\n date: formattedDate,\n shouldShowTime,\n language,\n });\n\n setFormattedDateString(newFormattedDateString);\n }, [\n date,\n formattedDate,\n language,\n shouldShowDateToNowDifference,\n shouldShowDayOfWeek,\n shouldShowRelativeDayOfWeek,\n shouldShowThisYear,\n shouldShowTime,\n shouldUseShortText,\n ]);\n\n // Calculate remaining time till next minute to update time according to time left\n const [currentDate, setCurrentDate] = useState(new Date());\n\n useEffect(() => {\n // This useEffect is for calculating the current date for shouldShowDateToNowDifference option\n if (!shouldShowDateToNowDifference) {\n return () => {};\n }\n\n let timeoutTime = formattedDate.getSeconds() - new Date().getSeconds();\n\n // If the seconds of date are after seconds of current time, the timeoutTime has to be calculated differently\n if (timeoutTime < 0) {\n timeoutTime = 60 - new Date().getSeconds() + formattedDate.getSeconds();\n }\n\n // initialized with remaining time\n let timeDiffInMs = formattedDate.getTime() - currentDate.getTime();\n\n // set to elapsed time\n if (isPast(formattedDate)) {\n timeDiffInMs = currentDate.getTime() - formattedDate.getTime();\n }\n\n // time difference is less than a minute, time should be updated every second\n if (timeDiffInMs < 60000) {\n timeoutTime = 1;\n }\n\n // Set timeoutTime to at least 1000ms\n timeoutTime = Math.max(timeoutTime * 1000, 1000);\n\n const timeout = setTimeout(() => {\n setCurrentDate(new Date());\n }, timeoutTime);\n\n return () => {\n clearTimeout(timeout);\n };\n }, [currentDate, date, formattedDate, shouldShowDateToNowDifference]);\n\n useEffect(() => {\n // This useEffect is for showing the difference of the date to now\n if (shouldShowDateToNowDifference) {\n setFormattedDateString(getTimeTillNow({ date: formattedDate, currentDate, language }));\n }\n }, [currentDate, date, formattedDate, language, shouldShowDateToNowDifference]);\n\n useEffect(() => {\n setFormattedDate(new Date(date));\n }, [date]);\n\n return useMemo(\n () => (\n <span>\n {preText.trim()} {formattedDateString}\n </span>\n ),\n [formattedDateString, preText],\n );\n};\n\nDateInfo.displayName = 'DateInfo';\n\nexport default DateInfo;\n"],"mappings":";;;;;;AAAA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAC,uBAAA,CAAAF,OAAA;AACA,IAAAG,SAAA,GAAAH,OAAA;AAO8B,S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EAAC;QAAErC,IAAI,EAAEQ,aAAa;QAAEiB,WAAW;QAAEX;MAAS,CAAC,CAAC,CAAC;IAC1F;EACJ,CAAC,EAAE,CAACW,WAAW,EAAEzB,IAAI,EAAEQ,aAAa,EAAEM,QAAQ,EAAEP,6BAA6B,CAAC,CAAC;EAE/E,IAAAS,gBAAS,EAAC,MAAM;IACZP,gBAAgB,CAAC,IAAIE,IAAI,CAACX,IAAI,CAAC,CAAC;EACpC,CAAC,EAAE,CAACA,IAAI,CAAC,CAAC;EAEV,OAAO,IAAAsC,cAAO,EACV,mBACI9D,MAAA,CAAAS,OAAA,CAAAsD,aAAA,eACKtC,OAAO,CAACuC,IAAI,CAAC,CAAC,EAAC,GAAC,EAAC5B,mBAChB,CACT,EACD,CAACA,mBAAmB,EAAEX,OAAO,CACjC,CAAC;AACL,CAAC;AAEDF,QAAQ,CAAC0C,WAAW,GAAG,UAAU;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAA1D,OAAA,GAEnBc,QAAQ","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"DateInfo.js","names":["_react","_interopRequireWildcard","require","_useDateInfo","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","DateInfo","date","preText","shouldShowYear","shouldShowTime","shouldShowRelativeDayOfWeek","shouldUseShortText","shouldShowDayOfWeek","shouldShowDateToNowDifference","formattedDate","useDateInfo","useMemo","createElement","displayName","_default","exports"],"sources":["../../../../src/components/date-info/DateInfo.tsx"],"sourcesContent":["import React, { FC, useMemo } from 'react';\nimport { useDateInfo, type UseDateInfoOptions } from '../../hooks/useDateInfo';\n\nexport type DateInfoProps = UseDateInfoOptions;\n\nconst DateInfo: FC<DateInfoProps> = ({\n date,\n preText = '',\n shouldShowYear,\n shouldShowTime,\n shouldShowRelativeDayOfWeek,\n shouldUseShortText,\n shouldShowDayOfWeek,\n shouldShowDateToNowDifference,\n}) => {\n const formattedDate = useDateInfo({\n date,\n preText,\n shouldShowYear,\n shouldShowTime,\n shouldUseShortText,\n shouldShowDayOfWeek,\n shouldShowRelativeDayOfWeek,\n shouldShowDateToNowDifference,\n });\n\n return useMemo(() => <span>{formattedDate}</span>, [formattedDate]);\n};\n\nDateInfo.displayName = 'DateInfo';\n\nexport default DateInfo;\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AAA+E,SAAAE,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,KAAAF,CAAA;AAAA,SAAAJ,wBAAAI,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAI,UAAA,SAAAJ,CAAA,eAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,WAAAK,OAAA,EAAAL,CAAA,QAAAG,CAAA,GAAAJ,wBAAA,CAAAG,CAAA,OAAAC,CAAA,IAAAA,CAAA,CAAAG,GAAA,CAAAN,CAAA,UAAAG,CAAA,CAAAI,GAAA,CAAAP,CAAA,OAAAQ,CAAA,KAAAC,SAAA,UAAAC,CAAA,GAAAC,MAAA,CAAAC,cAAA,IAAAD,MAAA,CAAAE,wBAAA,WAAAC,CAAA,IAAAd,CAAA,oBAAAc,CAAA,OAAAC,cAAA,CAAAC,IAAA,CAAAhB,CAAA,EAAAc,CAAA,SAAAG,CAAA,GAAAP,CAAA,GAAAC,MAAA,CAAAE,wBAAA,CAAAb,CAAA,EAAAc,CAAA,UAAAG,CAAA,KAAAA,CAAA,CAAAV,GAAA,IAAAU,CAAA,CAAAC,GAAA,IAAAP,MAAA,CAAAC,cAAA,CAAAJ,CAAA,EAAAM,CAAA,EAAAG,CAAA,IAAAT,CAAA,CAAAM,CAAA,IAAAd,CAAA,CAAAc,CAAA,YAAAN,CAAA,CAAAH,OAAA,GAAAL,CAAA,EAAAG,CAAA,IAAAA,CAAA,CAAAe,GAAA,CAAAlB,CAAA,EAAAQ,CAAA,GAAAA,CAAA;AAI/E,MAAMW,QAA2B,GAAGA,CAAC;EACjCC,IAAI;EACJC,OAAO,GAAG,EAAE;EACZC,cAAc;EACdC,cAAc;EACdC,2BAA2B;EAC3BC,kBAAkB;EAClBC,mBAAmB;EACnBC;AACJ,CAAC,KAAK;EACF,MAAMC,aAAa,GAAG,IAAAC,wBAAW,EAAC;IAC9BT,IAAI;IACJC,OAAO;IACPC,cAAc;IACdC,cAAc;IACdE,kBAAkB;IAClBC,mBAAmB;IACnBF,2BAA2B;IAC3BG;EACJ,CAAC,CAAC;EAEF,OAAO,IAAAG,cAAO,EAAC,mBAAMnC,MAAA,CAAAU,OAAA,CAAA0B,aAAA,eAAOH,aAAoB,CAAC,EAAE,CAACA,aAAa,CAAC,CAAC;AACvE,CAAC;AAEDT,QAAQ,CAACa,WAAW,GAAG,UAAU;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAA7B,OAAA,GAEnBc,QAAQ","ignoreList":[]}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useDateInfo = void 0;
|
|
7
|
+
var _dateFns = require("date-fns");
|
|
8
|
+
var _react = require("react");
|
|
9
|
+
var _dateInfo = require("../utils/dateInfo");
|
|
10
|
+
const useDateInfo = ({
|
|
11
|
+
date,
|
|
12
|
+
shouldShowDateToNowDifference,
|
|
13
|
+
shouldShowRelativeDayOfWeek,
|
|
14
|
+
shouldShowDayOfWeek,
|
|
15
|
+
shouldShowTime,
|
|
16
|
+
shouldUseShortText,
|
|
17
|
+
shouldShowYear,
|
|
18
|
+
preText
|
|
19
|
+
}) => {
|
|
20
|
+
const [formattedDateString, setFormattedDateString] = (0, _react.useState)('');
|
|
21
|
+
const [language] = (0, _react.useState)((0, _dateInfo.getLanguage)());
|
|
22
|
+
const formattedDate = (0, _react.useMemo)(() => new Date(date), [date]);
|
|
23
|
+
(0, _react.useEffect)(() => {
|
|
24
|
+
// This useEffect is used for normal date formation
|
|
25
|
+
if (shouldShowDateToNowDifference) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
let newFormattedDateString = (0, _dateInfo.getFormattedDayOfWeek)({
|
|
29
|
+
shouldShowDayOfWeek,
|
|
30
|
+
shouldShowRelativeDayOfWeek,
|
|
31
|
+
shouldUseShortText,
|
|
32
|
+
date: formattedDate,
|
|
33
|
+
language
|
|
34
|
+
});
|
|
35
|
+
let formatString = 'dd. ';
|
|
36
|
+
formatString += `${(0, _dateInfo.getMonthFormat)({
|
|
37
|
+
shouldUseShortText
|
|
38
|
+
})}`;
|
|
39
|
+
formatString += `${(0, _dateInfo.getYearFormat)({
|
|
40
|
+
date: formattedDate,
|
|
41
|
+
shouldShowYear
|
|
42
|
+
})}`;
|
|
43
|
+
newFormattedDateString += (0, _dateFns.format)(formattedDate, formatString, {
|
|
44
|
+
locale: language
|
|
45
|
+
});
|
|
46
|
+
newFormattedDateString += (0, _dateInfo.getFormattedTime)({
|
|
47
|
+
date: formattedDate,
|
|
48
|
+
shouldShowTime,
|
|
49
|
+
language
|
|
50
|
+
});
|
|
51
|
+
setFormattedDateString(newFormattedDateString);
|
|
52
|
+
}, [date, formattedDate, language, shouldShowDateToNowDifference, shouldShowDayOfWeek, shouldShowRelativeDayOfWeek, shouldShowYear, shouldShowTime, shouldUseShortText]);
|
|
53
|
+
|
|
54
|
+
// Calculate remaining time till next minute to update time according to time left
|
|
55
|
+
const [currentDate, setCurrentDate] = (0, _react.useState)(new Date());
|
|
56
|
+
(0, _react.useEffect)(() => {
|
|
57
|
+
// This useEffect is for calculating the current date for shouldShowDateToNowDifference option
|
|
58
|
+
if (!shouldShowDateToNowDifference) {
|
|
59
|
+
return () => {};
|
|
60
|
+
}
|
|
61
|
+
let timeoutTime = formattedDate.getSeconds() - new Date().getSeconds();
|
|
62
|
+
|
|
63
|
+
// If the seconds of date are after seconds of current time, the timeoutTime has to be calculated differently
|
|
64
|
+
if (timeoutTime < 0) {
|
|
65
|
+
timeoutTime = 60 - new Date().getSeconds() + formattedDate.getSeconds();
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// initialized with remaining time
|
|
69
|
+
let timeDiffInMs = formattedDate.getTime() - currentDate.getTime();
|
|
70
|
+
|
|
71
|
+
// set to elapsed time
|
|
72
|
+
if ((0, _dateFns.isPast)(formattedDate)) {
|
|
73
|
+
timeDiffInMs = currentDate.getTime() - formattedDate.getTime();
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// time difference is less than a minute, time should be updated every second
|
|
77
|
+
if (timeDiffInMs < 60000) {
|
|
78
|
+
timeoutTime = 1;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Set timeoutTime to at least 1000ms
|
|
82
|
+
timeoutTime = Math.max(timeoutTime * 1000, 1000);
|
|
83
|
+
const timeout = setTimeout(() => {
|
|
84
|
+
setCurrentDate(new Date());
|
|
85
|
+
}, timeoutTime);
|
|
86
|
+
return () => {
|
|
87
|
+
clearTimeout(timeout);
|
|
88
|
+
};
|
|
89
|
+
}, [currentDate, date, formattedDate, shouldShowDateToNowDifference]);
|
|
90
|
+
(0, _react.useEffect)(() => {
|
|
91
|
+
// This useEffect is for showing the difference of the date to now
|
|
92
|
+
if (shouldShowDateToNowDifference) {
|
|
93
|
+
setFormattedDateString((0, _dateInfo.getTimeTillNow)({
|
|
94
|
+
date: formattedDate,
|
|
95
|
+
currentDate,
|
|
96
|
+
language
|
|
97
|
+
}));
|
|
98
|
+
}
|
|
99
|
+
}, [currentDate, date, formattedDate, language, shouldShowDateToNowDifference]);
|
|
100
|
+
return (0, _react.useMemo)(() => `${preText ? `${preText.trim()} ` : ''}${formattedDateString}`, [formattedDateString, preText]);
|
|
101
|
+
};
|
|
102
|
+
exports.useDateInfo = useDateInfo;
|
|
103
|
+
//# sourceMappingURL=useDateInfo.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useDateInfo.js","names":["_dateFns","require","_react","_dateInfo","useDateInfo","date","shouldShowDateToNowDifference","shouldShowRelativeDayOfWeek","shouldShowDayOfWeek","shouldShowTime","shouldUseShortText","shouldShowYear","preText","formattedDateString","setFormattedDateString","useState","language","getLanguage","formattedDate","useMemo","Date","useEffect","newFormattedDateString","getFormattedDayOfWeek","formatString","getMonthFormat","getYearFormat","format","locale","getFormattedTime","currentDate","setCurrentDate","timeoutTime","getSeconds","timeDiffInMs","getTime","isPast","Math","max","timeout","setTimeout","clearTimeout","getTimeTillNow","trim","exports"],"sources":["../../../src/hooks/useDateInfo.ts"],"sourcesContent":["import { format, isPast } from 'date-fns';\nimport { useEffect, useMemo, useState } from 'react';\nimport {\n getFormattedDayOfWeek,\n getFormattedTime,\n getLanguage,\n getMonthFormat,\n getTimeTillNow,\n getYearFormat,\n} from '../utils/dateInfo';\n\nexport interface UseDateInfoOptions {\n /**\n * The date, that should be displayed\n */\n date: Date | string;\n /**\n * Additional text for \"shouldShowDateToNowDifference\" prop. Writes a text before the calculated time\n */\n preText?: string;\n /**\n * Adds the current year to the display\n */\n shouldShowYear?: boolean;\n /**\n * Adds the time to the display.\n */\n shouldShowTime?: boolean;\n /**\n * Whether the relative day of week to today should be shown (today, yesterday or tomorrow).\n */\n shouldShowRelativeDayOfWeek?: boolean;\n /**\n * Shortens the day and month text to maximum three digits\n */\n shouldUseShortText?: boolean;\n /**\n * Adds the day of week to the display\n */\n shouldShowDayOfWeek?: boolean;\n /**\n * Shows the difference from the date to now. The component handles updates itself.\n */\n shouldShowDateToNowDifference?: boolean;\n}\n\nexport const useDateInfo = ({\n date,\n shouldShowDateToNowDifference,\n shouldShowRelativeDayOfWeek,\n shouldShowDayOfWeek,\n shouldShowTime,\n shouldUseShortText,\n shouldShowYear,\n preText,\n}: UseDateInfoOptions) => {\n const [formattedDateString, setFormattedDateString] = useState<string>('');\n const [language] = useState(getLanguage());\n\n const formattedDate = useMemo(() => new Date(date), [date]);\n\n useEffect(() => {\n // This useEffect is used for normal date formation\n if (shouldShowDateToNowDifference) {\n return;\n }\n\n let newFormattedDateString = getFormattedDayOfWeek({\n shouldShowDayOfWeek,\n shouldShowRelativeDayOfWeek,\n shouldUseShortText,\n date: formattedDate,\n language,\n });\n\n let formatString = 'dd. ';\n\n formatString += `${getMonthFormat({ shouldUseShortText })}`;\n\n formatString += `${getYearFormat({\n date: formattedDate,\n shouldShowYear,\n })}`;\n\n newFormattedDateString += format(formattedDate, formatString, { locale: language });\n\n newFormattedDateString += getFormattedTime({\n date: formattedDate,\n shouldShowTime,\n language,\n });\n\n setFormattedDateString(newFormattedDateString);\n }, [\n date,\n formattedDate,\n language,\n shouldShowDateToNowDifference,\n shouldShowDayOfWeek,\n shouldShowRelativeDayOfWeek,\n shouldShowYear,\n shouldShowTime,\n shouldUseShortText,\n ]);\n\n // Calculate remaining time till next minute to update time according to time left\n const [currentDate, setCurrentDate] = useState(new Date());\n\n useEffect(() => {\n // This useEffect is for calculating the current date for shouldShowDateToNowDifference option\n if (!shouldShowDateToNowDifference) {\n return () => {};\n }\n\n let timeoutTime = formattedDate.getSeconds() - new Date().getSeconds();\n\n // If the seconds of date are after seconds of current time, the timeoutTime has to be calculated differently\n if (timeoutTime < 0) {\n timeoutTime = 60 - new Date().getSeconds() + formattedDate.getSeconds();\n }\n\n // initialized with remaining time\n let timeDiffInMs = formattedDate.getTime() - currentDate.getTime();\n\n // set to elapsed time\n if (isPast(formattedDate)) {\n timeDiffInMs = currentDate.getTime() - formattedDate.getTime();\n }\n\n // time difference is less than a minute, time should be updated every second\n if (timeDiffInMs < 60000) {\n timeoutTime = 1;\n }\n\n // Set timeoutTime to at least 1000ms\n timeoutTime = Math.max(timeoutTime * 1000, 1000);\n\n const timeout = setTimeout(() => {\n setCurrentDate(new Date());\n }, timeoutTime);\n\n return () => {\n clearTimeout(timeout);\n };\n }, [currentDate, date, formattedDate, shouldShowDateToNowDifference]);\n\n useEffect(() => {\n // This useEffect is for showing the difference of the date to now\n if (shouldShowDateToNowDifference) {\n setFormattedDateString(getTimeTillNow({ date: formattedDate, currentDate, language }));\n }\n }, [currentDate, date, formattedDate, language, shouldShowDateToNowDifference]);\n\n return useMemo(\n () => `${preText ? `${preText.trim()} ` : ''}${formattedDateString}`,\n [formattedDateString, preText],\n );\n};\n"],"mappings":";;;;;;AAAA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AACA,IAAAE,SAAA,GAAAF,OAAA;AA4CO,MAAMG,WAAW,GAAGA,CAAC;EACxBC,IAAI;EACJC,6BAA6B;EAC7BC,2BAA2B;EAC3BC,mBAAmB;EACnBC,cAAc;EACdC,kBAAkB;EAClBC,cAAc;EACdC;AACgB,CAAC,KAAK;EACtB,MAAM,CAACC,mBAAmB,EAAEC,sBAAsB,CAAC,GAAG,IAAAC,eAAQ,EAAS,EAAE,CAAC;EAC1E,MAAM,CAACC,QAAQ,CAAC,GAAG,IAAAD,eAAQ,EAAC,IAAAE,qBAAW,EAAC,CAAC,CAAC;EAE1C,MAAMC,aAAa,GAAG,IAAAC,cAAO,EAAC,MAAM,IAAIC,IAAI,CAACf,IAAI,CAAC,EAAE,CAACA,IAAI,CAAC,CAAC;EAE3D,IAAAgB,gBAAS,EAAC,MAAM;IACZ;IACA,IAAIf,6BAA6B,EAAE;MAC/B;IACJ;IAEA,IAAIgB,sBAAsB,GAAG,IAAAC,+BAAqB,EAAC;MAC/Cf,mBAAmB;MACnBD,2BAA2B;MAC3BG,kBAAkB;MAClBL,IAAI,EAAEa,aAAa;MACnBF;IACJ,CAAC,CAAC;IAEF,IAAIQ,YAAY,GAAG,MAAM;IAEzBA,YAAY,IAAI,GAAG,IAAAC,wBAAc,EAAC;MAAEf;IAA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OAAO,CAAC,CAAC,GAAGjB,aAAa,CAACiB,OAAO,CAAC,CAAC;IAClE;;IAEA;IACA,IAAID,YAAY,GAAG,KAAK,EAAE;MACtBF,WAAW,GAAG,CAAC;IACnB;;IAEA;IACAA,WAAW,GAAGK,IAAI,CAACC,GAAG,CAACN,WAAW,GAAG,IAAI,EAAE,IAAI,CAAC;IAEhD,MAAMO,OAAO,GAAGC,UAAU,CAAC,MAAM;MAC7BT,cAAc,CAAC,IAAIX,IAAI,CAAC,CAAC,CAAC;IAC9B,CAAC,EAAEY,WAAW,CAAC;IAEf,OAAO,MAAM;MACTS,YAAY,CAACF,OAAO,CAAC;IACzB,CAAC;EACL,CAAC,EAAE,CAACT,WAAW,EAAEzB,IAAI,EAAEa,aAAa,EAAEZ,6BAA6B,CAAC,CAAC;EAErE,IAAAe,gBAAS,EAAC,MAAM;IACZ;IACA,IAAIf,6BAA6B,EAAE;MAC/BQ,sBAAsB,CAAC,IAAA4B,wBAAc,EAAC;QAAErC,IAAI,EAAEa,aAAa;QAAEY,WAAW;QAAEd;MAAS,CAAC,CAAC,CAAC;IAC1F;EACJ,CAAC,EAAE,CAACc,WAAW,EAAEzB,IAAI,EAAEa,aAAa,EAAEF,QAAQ,EAAEV,6BAA6B,CAAC,CAAC;EAE/E,OAAO,IAAAa,cAAO,EACV,MAAM,GAAGP,OAAO,GAAG,GAAGA,OAAO,CAAC+B,IAAI,CAAC,CAAC,GAAG,GAAG,EAAE,GAAG9B,mBAAmB,EAAE,EACpE,CAACA,mBAAmB,EAAED,OAAO,CACjC,CAAC;AACL,CAAC;AAACgC,OAAA,CAAAxC,WAAA,GAAAA,WAAA","ignoreList":[]}
|
|
@@ -57,13 +57,8 @@ const getTimeString = ({
|
|
|
57
57
|
exports.getTimeString = getTimeString;
|
|
58
58
|
const getYearFormat = ({
|
|
59
59
|
date,
|
|
60
|
-
|
|
61
|
-
}) =>
|
|
62
|
-
if (shouldShowThisYear) {
|
|
63
|
-
return ' yyyy';
|
|
64
|
-
}
|
|
65
|
-
return (0, _dateFns.isThisYear)(date) ? '' : ' yyyy';
|
|
66
|
-
};
|
|
60
|
+
shouldShowYear
|
|
61
|
+
}) => typeof shouldShowYear === 'boolean' && !shouldShowYear || (0, _dateFns.isThisYear)(date) ? '' : ' yyyy';
|
|
67
62
|
exports.getYearFormat = getYearFormat;
|
|
68
63
|
const getMonthFormat = ({
|
|
69
64
|
shouldUseShortText
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dateInfo.js","names":["_chaynsApi","require","_dateFns","_locale","_dateInfo","getLanguage","getChaynsLanguage","translation","site","enGB","nl","fr","it","pl","pt","es","tr","uk","de","exports","getTimeString","language","isMorning","getYearFormat","date","shouldShowThisYear","isThisYear","getMonthFormat","shouldUseShortText","getFormattedDayOfWeek","shouldShowRelativeDayOfWeek","shouldShowDayOfWeek","isToday","code","isTomorrow","isYesterday","format","locale","getFormattedTime","shouldShowTime","timeFormat","hours","getHours","TimeType","getTimeTypeStrings","TIME_TYPE_STRINGS","getTimeTillNow","currentDate","time","value","type","Years","isPast","elapsedMilliseconds","getTime","Math","floor","Seconds","Minutes","Hours","Days","Weeks","Months","getFormattedPastTimeString","remainingMilliseconds","getFormattedFutureTimeString","timeTypeStrings","isSingular","seconds","days","weeks","months","years","minutes","past","singular","plural","future"],"sources":["../../../src/utils/dateInfo.ts"],"sourcesContent":["import { getLanguage as getChaynsLanguage } from 'chayns-api';\nimport {\n format,\n isPast,\n isThisYear,\n isToday,\n isTomorrow,\n isYesterday,\n type Locale,\n} from 'date-fns';\nimport { de, enGB, es, fr, it, nl, pl, pt, tr, uk } from 'date-fns/locale';\nimport { TIME_TYPE_STRINGS, type TimeTypeStringsRecord } from '../constants/dateInfo';\n\nexport const getLanguage = (): Locale => {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n switch (getChaynsLanguage().translation || getChaynsLanguage().site) {\n case 'en':\n return enGB;\n case 'nl':\n return nl;\n case 'fr':\n return fr;\n case 'it':\n return it;\n case 'pl':\n return pl;\n case 'pt':\n return pt;\n case 'es':\n return es;\n case 'tr':\n return tr;\n case 'uk':\n return uk;\n default:\n return de;\n }\n};\n\ninterface GetTimeStringProps {\n language?: string;\n isMorning?: boolean;\n}\n\nexport const getTimeString = ({ language, isMorning }: GetTimeStringProps) => {\n switch (language) {\n case 'en-GB':\n case 'pt':\n return isMorning ? 'AM' : 'PM';\n case 'nl':\n return 'uur';\n case 'fr':\n return 'heures';\n case 'de':\n return 'Uhr';\n case 'es':\n return 'h';\n default:\n return '';\n }\n};\n\ninterface GetFormattedYearOptions {\n date: Date;\n shouldShowThisYear?: boolean;\n}\n\nexport const getYearFormat = ({ date, shouldShowThisYear }: GetFormattedYearOptions) => {\n if (shouldShowThisYear) {\n return ' yyyy';\n }\n\n return isThisYear(date) ? '' : ' yyyy';\n};\n\ninterface GetFormattedMonthOptions {\n shouldUseShortText?: boolean;\n}\n\nexport const getMonthFormat = ({ shouldUseShortText }: GetFormattedMonthOptions) => {\n if (shouldUseShortText) {\n return 'LLL.';\n }\n\n return 'LLLL';\n};\n\ninterface GetFormattedDayOfWeekOptions {\n shouldShowDayOfWeek?: boolean;\n shouldShowRelativeDayOfWeek?: boolean;\n shouldUseShortText?: boolean;\n date: Date;\n language?: Locale;\n}\n\nexport const getFormattedDayOfWeek = ({\n shouldShowRelativeDayOfWeek,\n shouldShowDayOfWeek,\n shouldUseShortText,\n date,\n language,\n}: GetFormattedDayOfWeekOptions) => {\n if (!shouldShowDayOfWeek && !shouldShowRelativeDayOfWeek) {\n return '';\n }\n\n if (shouldShowRelativeDayOfWeek) {\n if (isToday(date)) {\n switch (language?.code) {\n case 'en-GB':\n return 'Today, ';\n case 'nl':\n return 'Vandaag, ';\n case 'fr':\n return \"Aujourd'hui, \";\n case 'it':\n return 'Oggi, ';\n case 'pl':\n return 'Dzisiaj, ';\n case 'pt':\n return 'Hoje, ';\n case 'es':\n return 'Hoy, ';\n case 'tr':\n return 'Bugün, ';\n case 'uk':\n return 'Сьогодні, ';\n default:\n return 'Heute, ';\n }\n }\n\n if (isTomorrow(date)) {\n switch (language?.code) {\n case 'en-GB':\n return 'Tomorrow, ';\n case 'nl':\n return 'Morgen, ';\n case 'fr':\n return 'Demain, ';\n case 'it':\n return 'Domani, ';\n case 'pl':\n return 'Jutro, ';\n case 'pt':\n return 'Amanhã, ';\n case 'es':\n return 'Mañana, ';\n case 'tr':\n return 'Yarın, ';\n case 'uk':\n return 'Завтра, ';\n default:\n return 'Morgen, ';\n }\n }\n\n if (isYesterday(date)) {\n switch (language?.code) {\n case 'en-GB':\n return 'Yesterday, ';\n case 'nl':\n return 'Gisteren, ';\n case 'fr':\n return 'Hier, ';\n case 'it':\n return 'Ieri, ';\n case 'pl':\n return 'Wczoraj, ';\n case 'pt':\n return 'Ontem, ';\n case 'es':\n return 'Ayer, ';\n case 'tr':\n return 'Dün, ';\n case 'uk':\n return 'Вчора, ';\n default:\n return 'Gestern, ';\n }\n }\n }\n\n if (shouldUseShortText) {\n return format(date, 'E., ', { locale: language });\n }\n\n return format(date, 'EEEE, ', { locale: language });\n};\n\ninterface GetFormattedTimeOptions {\n shouldShowTime?: boolean;\n date: Date;\n language: Locale;\n}\n\nexport const getFormattedTime = ({ shouldShowTime, date, language }: GetFormattedTimeOptions) => {\n if (!shouldShowTime) {\n return '';\n }\n\n let timeFormat = 'HH:mm';\n\n if (language.code === 'en-GB' || language.code === 'pt') {\n timeFormat = 'KK:mm';\n }\n\n return `, ${format(date, timeFormat)} ${getTimeString({\n language: language.code,\n isMorning: isMorning(date),\n })}`;\n};\n\nexport const isMorning = (date: Date) => {\n const hours = date.getHours();\n\n return hours >= 0 && hours < 12;\n};\n\nexport interface Time {\n value: number;\n type: TimeType;\n isPast: boolean;\n}\n\nexport enum TimeType {\n Seconds,\n Minutes,\n Hours,\n Days,\n Weeks,\n Months,\n Years,\n}\n\nexport const getTimeTypeStrings = (language: string): TimeTypeStringsRecord | undefined =>\n TIME_TYPE_STRINGS[language === 'en-GB' ? 'en' : language];\n\ninterface GetTimeTillNowOptions {\n date: Date;\n currentDate: Date;\n language: Locale;\n}\n\nexport const getTimeTillNow = ({ date, currentDate, language }: GetTimeTillNowOptions): string => {\n const time: Time = {\n value: 0,\n type: TimeType.Years,\n isPast: false,\n };\n\n if (isPast(date)) {\n const elapsedMilliseconds = currentDate.getTime() - date.getTime();\n\n switch (true) {\n case elapsedMilliseconds < 60000:\n time.value = Math.floor(elapsedMilliseconds / 1000);\n time.type = TimeType.Seconds;\n break;\n case elapsedMilliseconds < 3600000:\n time.value = Math.floor(elapsedMilliseconds / 60000);\n time.type = TimeType.Minutes;\n break;\n case elapsedMilliseconds < 86400000:\n time.value = Math.floor(elapsedMilliseconds / 3600000);\n time.type = TimeType.Hours;\n break;\n case elapsedMilliseconds < 604800000:\n time.value = Math.floor(elapsedMilliseconds / 86400000);\n time.type = TimeType.Days;\n break;\n case elapsedMilliseconds < 2592000000:\n time.value = Math.floor(elapsedMilliseconds / 604800000);\n time.type = TimeType.Weeks;\n break;\n case elapsedMilliseconds < 31536000000:\n time.value = Math.floor(elapsedMilliseconds / 2592000000);\n time.type = TimeType.Months;\n break;\n default:\n time.value = Math.floor(elapsedMilliseconds / 31536000000);\n time.type = TimeType.Years;\n break;\n }\n\n return `${time.value} ${getFormattedPastTimeString(time, language)}`;\n }\n\n const remainingMilliseconds = date.getTime() - currentDate.getTime();\n\n switch (true) {\n case remainingMilliseconds < 60000:\n time.value = Math.floor(remainingMilliseconds / 1000);\n time.type = TimeType.Seconds;\n break;\n case remainingMilliseconds < 3600000:\n time.value = Math.floor(remainingMilliseconds / 60000);\n time.type = TimeType.Minutes;\n break;\n case remainingMilliseconds < 86400000:\n time.value = Math.floor(remainingMilliseconds / 3600000);\n time.type = TimeType.Hours;\n break;\n case remainingMilliseconds < 604800000:\n time.value = Math.floor(remainingMilliseconds / 86400000);\n time.type = TimeType.Days;\n break;\n case remainingMilliseconds < 2592000000:\n time.value = Math.floor(remainingMilliseconds / 604800000);\n time.type = TimeType.Weeks;\n break;\n case remainingMilliseconds < 31536000000:\n time.value = Math.floor(remainingMilliseconds / 2592000000);\n time.type = TimeType.Months;\n break;\n default:\n time.value = Math.floor(remainingMilliseconds / 31536000000);\n time.type = TimeType.Years;\n break;\n }\n\n return `${time.value} ${getFormattedFutureTimeString(time, language)}`;\n};\n\nexport const getFormattedPastTimeString = (time: Time, language: Locale): string => {\n const { value, type } = time;\n\n const timeTypeStrings = getTimeTypeStrings(language.code ?? 'de');\n const isSingular = value === 1;\n\n if (!timeTypeStrings) {\n return '';\n }\n\n const { seconds, days, weeks, months, years, minutes, hours } = timeTypeStrings.past;\n\n switch (true) {\n case type === TimeType.Seconds:\n return isSingular ? seconds.singular : seconds.plural;\n case type === TimeType.Minutes:\n return isSingular ? minutes.singular : minutes.plural;\n case type === TimeType.Hours:\n return isSingular ? hours.singular : hours.plural;\n case type === TimeType.Days:\n return isSingular ? days.singular : days.plural;\n case type === TimeType.Weeks:\n return isSingular ? weeks.singular : weeks.plural;\n case type === TimeType.Months:\n return isSingular ? months.singular : months.plural;\n default:\n return isSingular ? years.singular : years.plural;\n }\n};\n\nexport const getFormattedFutureTimeString = (time: Time, language: Locale): string => {\n const { value, type } = time;\n const timeTypeStrings = getTimeTypeStrings(language.code ?? 'de');\n const isSingular = value === 1;\n\n if (!timeTypeStrings) {\n return '';\n }\n\n const { seconds, days, weeks, months, years, minutes, hours } = timeTypeStrings.future;\n\n switch (true) {\n case type === TimeType.Seconds:\n return isSingular ? seconds.singular : seconds.plural;\n case type === TimeType.Minutes:\n return isSingular ? minutes.singular : minutes.plural;\n case type === TimeType.Hours:\n return isSingular ? hours.singular : hours.plural;\n case type === TimeType.Days:\n return isSingular ? days.singular : days.plural;\n case type === TimeType.Weeks:\n return isSingular ? weeks.singular : weeks.plural;\n case type === TimeType.Months:\n return isSingular ? months.singular : months.plural;\n default:\n return isSingular ? years.singular : years.plural;\n }\n};\n"],"mappings":";;;;;;AAAA,IAAAA,UAA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,KAAK,CAACkC,QAAQ,GAAGlC,KAAK,CAACmC,MAAM;IACrD,KAAK1B,IAAI,KAAKP,QAAQ,CAACiB,IAAI;MACvB,OAAOO,UAAU,GAAGE,IAAI,CAACM,QAAQ,GAAGN,IAAI,CAACO,MAAM;IACnD,KAAK1B,IAAI,KAAKP,QAAQ,CAACkB,KAAK;MACxB,OAAOM,UAAU,GAAGG,KAAK,CAACK,QAAQ,GAAGL,KAAK,CAACM,MAAM;IACrD,KAAK1B,IAAI,KAAKP,QAAQ,CAACmB,MAAM;MACzB,OAAOK,UAAU,GAAGI,MAAM,CAACI,QAAQ,GAAGJ,MAAM,CAACK,MAAM;IACvD;MACI,OAAOT,UAAU,GAAGK,KAAK,CAACG,QAAQ,GAAGH,KAAK,CAACI,MAAM;EACzD;AACJ,CAAC;AAACzD,OAAA,CAAA8C,4BAAA,GAAAA,4BAAA","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"dateInfo.js","names":["_chaynsApi","require","_dateFns","_locale","_dateInfo","getLanguage","getChaynsLanguage","translation","site","enGB","nl","fr","it","pl","pt","es","tr","uk","de","exports","getTimeString","language","isMorning","getYearFormat","date","shouldShowYear","isThisYear","getMonthFormat","shouldUseShortText","getFormattedDayOfWeek","shouldShowRelativeDayOfWeek","shouldShowDayOfWeek","isToday","code","isTomorrow","isYesterday","format","locale","getFormattedTime","shouldShowTime","timeFormat","hours","getHours","TimeType","getTimeTypeStrings","TIME_TYPE_STRINGS","getTimeTillNow","currentDate","time","value","type","Years","isPast","elapsedMilliseconds","getTime","Math","floor","Seconds","Minutes","Hours","Days","Weeks","Months","getFormattedPastTimeString","remainingMilliseconds","getFormattedFutureTimeString","timeTypeStrings","isSingular","seconds","days","weeks","months","years","minutes","past","singular","plural","future"],"sources":["../../../src/utils/dateInfo.ts"],"sourcesContent":["import { getLanguage as getChaynsLanguage } from 'chayns-api';\nimport {\n format,\n isPast,\n isThisYear,\n isToday,\n isTomorrow,\n isYesterday,\n type Locale,\n} from 'date-fns';\nimport { de, enGB, es, fr, it, nl, pl, pt, tr, uk } from 'date-fns/locale';\nimport { TIME_TYPE_STRINGS, type TimeTypeStringsRecord } from '../constants/dateInfo';\n\nexport const getLanguage = (): Locale => {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n switch (getChaynsLanguage().translation || getChaynsLanguage().site) {\n case 'en':\n return enGB;\n case 'nl':\n return nl;\n case 'fr':\n return fr;\n case 'it':\n return it;\n case 'pl':\n return pl;\n case 'pt':\n return pt;\n case 'es':\n return es;\n case 'tr':\n return tr;\n case 'uk':\n return uk;\n default:\n return de;\n }\n};\n\ninterface GetTimeStringProps {\n language?: string;\n isMorning?: boolean;\n}\n\nexport const getTimeString = ({ language, isMorning }: GetTimeStringProps) => {\n switch (language) {\n case 'en-GB':\n case 'pt':\n return isMorning ? 'AM' : 'PM';\n case 'nl':\n return 'uur';\n case 'fr':\n return 'heures';\n case 'de':\n return 'Uhr';\n case 'es':\n return 'h';\n default:\n return '';\n }\n};\n\ninterface GetFormattedYearOptions {\n date: Date;\n shouldShowYear?: boolean;\n}\n\nexport const getYearFormat = ({ date, shouldShowYear }: GetFormattedYearOptions) =>\n (typeof shouldShowYear === 'boolean' && !shouldShowYear) || isThisYear(date) ? '' : ' yyyy';\n\ninterface GetFormattedMonthOptions {\n shouldUseShortText?: boolean;\n}\n\nexport const getMonthFormat = ({ shouldUseShortText }: GetFormattedMonthOptions) => {\n if (shouldUseShortText) {\n return 'LLL.';\n }\n\n return 'LLLL';\n};\n\ninterface GetFormattedDayOfWeekOptions {\n shouldShowDayOfWeek?: boolean;\n shouldShowRelativeDayOfWeek?: boolean;\n shouldUseShortText?: boolean;\n date: Date;\n language?: Locale;\n}\n\nexport const getFormattedDayOfWeek = ({\n shouldShowRelativeDayOfWeek,\n shouldShowDayOfWeek,\n shouldUseShortText,\n date,\n language,\n}: GetFormattedDayOfWeekOptions) => {\n if (!shouldShowDayOfWeek && !shouldShowRelativeDayOfWeek) {\n return '';\n }\n\n if (shouldShowRelativeDayOfWeek) {\n if (isToday(date)) {\n switch (language?.code) {\n case 'en-GB':\n return 'Today, ';\n case 'nl':\n return 'Vandaag, ';\n case 'fr':\n return \"Aujourd'hui, \";\n case 'it':\n return 'Oggi, ';\n case 'pl':\n return 'Dzisiaj, ';\n case 'pt':\n return 'Hoje, ';\n case 'es':\n return 'Hoy, ';\n case 'tr':\n return 'Bugün, ';\n case 'uk':\n return 'Сьогодні, ';\n default:\n return 'Heute, ';\n }\n }\n\n if (isTomorrow(date)) {\n switch (language?.code) {\n case 'en-GB':\n return 'Tomorrow, ';\n case 'nl':\n return 'Morgen, ';\n case 'fr':\n return 'Demain, ';\n case 'it':\n return 'Domani, ';\n case 'pl':\n return 'Jutro, ';\n case 'pt':\n return 'Amanhã, ';\n case 'es':\n return 'Mañana, ';\n case 'tr':\n return 'Yarın, ';\n case 'uk':\n return 'Завтра, ';\n default:\n return 'Morgen, ';\n }\n }\n\n if (isYesterday(date)) {\n switch (language?.code) {\n case 'en-GB':\n return 'Yesterday, ';\n case 'nl':\n return 'Gisteren, ';\n case 'fr':\n return 'Hier, ';\n case 'it':\n return 'Ieri, ';\n case 'pl':\n return 'Wczoraj, ';\n case 'pt':\n return 'Ontem, ';\n case 'es':\n return 'Ayer, ';\n case 'tr':\n return 'Dün, ';\n case 'uk':\n return 'Вчора, ';\n default:\n return 'Gestern, ';\n }\n }\n }\n\n if (shouldUseShortText) {\n return format(date, 'E., ', { locale: language });\n }\n\n return format(date, 'EEEE, ', { locale: language });\n};\n\ninterface GetFormattedTimeOptions {\n shouldShowTime?: boolean;\n date: Date;\n language: Locale;\n}\n\nexport const getFormattedTime = ({ shouldShowTime, date, language }: GetFormattedTimeOptions) => {\n if (!shouldShowTime) {\n return '';\n }\n\n let timeFormat = 'HH:mm';\n\n if (language.code === 'en-GB' || language.code === 'pt') {\n timeFormat = 'KK:mm';\n }\n\n return `, ${format(date, timeFormat)} ${getTimeString({\n language: language.code,\n isMorning: isMorning(date),\n })}`;\n};\n\nexport const isMorning = (date: Date) => {\n const hours = date.getHours();\n\n return hours >= 0 && hours < 12;\n};\n\nexport interface Time {\n value: number;\n type: TimeType;\n isPast: boolean;\n}\n\nexport enum TimeType {\n Seconds,\n Minutes,\n Hours,\n Days,\n Weeks,\n Months,\n Years,\n}\n\nexport const getTimeTypeStrings = (language: string): TimeTypeStringsRecord | undefined =>\n TIME_TYPE_STRINGS[language === 'en-GB' ? 'en' : language];\n\ninterface GetTimeTillNowOptions {\n date: Date;\n currentDate: Date;\n language: Locale;\n}\n\nexport const getTimeTillNow = ({ date, currentDate, language }: GetTimeTillNowOptions): string => {\n const time: Time = {\n value: 0,\n type: TimeType.Years,\n isPast: false,\n };\n\n if (isPast(date)) {\n const elapsedMilliseconds = currentDate.getTime() - date.getTime();\n\n switch (true) {\n case elapsedMilliseconds < 60000:\n time.value = Math.floor(elapsedMilliseconds / 1000);\n time.type = TimeType.Seconds;\n break;\n case elapsedMilliseconds < 3600000:\n time.value = Math.floor(elapsedMilliseconds / 60000);\n time.type = TimeType.Minutes;\n break;\n case elapsedMilliseconds < 86400000:\n time.value = Math.floor(elapsedMilliseconds / 3600000);\n time.type = TimeType.Hours;\n break;\n case elapsedMilliseconds < 604800000:\n time.value = Math.floor(elapsedMilliseconds / 86400000);\n time.type = TimeType.Days;\n break;\n case elapsedMilliseconds < 2592000000:\n time.value = Math.floor(elapsedMilliseconds / 604800000);\n time.type = TimeType.Weeks;\n break;\n case elapsedMilliseconds < 31536000000:\n time.value = Math.floor(elapsedMilliseconds / 2592000000);\n time.type = TimeType.Months;\n break;\n default:\n time.value = Math.floor(elapsedMilliseconds / 31536000000);\n time.type = TimeType.Years;\n break;\n }\n\n return `${time.value} ${getFormattedPastTimeString(time, language)}`;\n }\n\n const remainingMilliseconds = date.getTime() - currentDate.getTime();\n\n switch (true) {\n case remainingMilliseconds < 60000:\n time.value = Math.floor(remainingMilliseconds / 1000);\n time.type = TimeType.Seconds;\n break;\n case remainingMilliseconds < 3600000:\n time.value = Math.floor(remainingMilliseconds / 60000);\n time.type = TimeType.Minutes;\n break;\n case remainingMilliseconds < 86400000:\n time.value = Math.floor(remainingMilliseconds / 3600000);\n time.type = TimeType.Hours;\n break;\n case remainingMilliseconds < 604800000:\n time.value = Math.floor(remainingMilliseconds / 86400000);\n time.type = TimeType.Days;\n break;\n case remainingMilliseconds < 2592000000:\n time.value = Math.floor(remainingMilliseconds / 604800000);\n time.type = TimeType.Weeks;\n break;\n case remainingMilliseconds < 31536000000:\n time.value = Math.floor(remainingMilliseconds / 2592000000);\n time.type = TimeType.Months;\n break;\n default:\n time.value = Math.floor(remainingMilliseconds / 31536000000);\n time.type = TimeType.Years;\n break;\n }\n\n return `${time.value} ${getFormattedFutureTimeString(time, language)}`;\n};\n\nexport const getFormattedPastTimeString = (time: Time, language: Locale): string => {\n const { value, type } = time;\n\n const timeTypeStrings = getTimeTypeStrings(language.code ?? 'de');\n const isSingular = value === 1;\n\n if (!timeTypeStrings) {\n return '';\n }\n\n const { seconds, days, weeks, months, years, minutes, hours } = timeTypeStrings.past;\n\n switch (true) {\n case type === TimeType.Seconds:\n return isSingular ? seconds.singular : seconds.plural;\n case type === TimeType.Minutes:\n return isSingular ? minutes.singular : minutes.plural;\n case type === TimeType.Hours:\n return isSingular ? hours.singular : hours.plural;\n case type === TimeType.Days:\n return isSingular ? days.singular : days.plural;\n case type === TimeType.Weeks:\n return isSingular ? weeks.singular : weeks.plural;\n case type === TimeType.Months:\n return isSingular ? months.singular : months.plural;\n default:\n return isSingular ? years.singular : years.plural;\n }\n};\n\nexport const getFormattedFutureTimeString = (time: Time, language: Locale): string => {\n const { value, type } = time;\n const timeTypeStrings = getTimeTypeStrings(language.code ?? 'de');\n const isSingular = value === 1;\n\n if (!timeTypeStrings) {\n return '';\n }\n\n const { seconds, days, weeks, months, years, minutes, hours } = timeTypeStrings.future;\n\n switch (true) {\n case type === TimeType.Seconds:\n return isSingular ? seconds.singular : seconds.plural;\n case type === TimeType.Minutes:\n return isSingular ? minutes.singular : minutes.plural;\n case type === TimeType.Hours:\n return isSingular ? hours.singular : hours.plural;\n case type === TimeType.Days:\n return isSingular ? days.singular : days.plural;\n case type === TimeType.Weeks:\n return isSingular ? weeks.singular : weeks.plural;\n case type === TimeType.Months:\n return isSingular ? months.singular : months.plural;\n default:\n return isSingular ? years.singular : years.plural;\n }\n};\n"],"mappings":";;;;;;AAAA,IAAAA,UAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AASA,IAAAE,OAAA,GAAAF,OAAA;AACA,IAAAG,SAAA,GAAAH,OAAA;AAEO,MAAMI,WAAW,GAAGA,CAAA,KAAc;EACrC;EACA,QAAQ,IAAAC,sBAAiB,EAAC,CAAC,CAACC,WAAW,IAAI,IAAAD,sBAAiB,EAAC,CAAC,CAACE,IAAI;IAC/D,KAAK,IAAI;MACL,OAAOC,YAAI;IACf,KAAK,IAAI;MACL,OAAOC,UAAE;IACb,KAAK,IAAI;MACL,OAAOC,UAAE;IACb,KAAK,IAAI;MACL,OAAOC,UAAE;IACb,KAAK,IAAI;MACL,OAAOC,UAAE;IACb,KAAK,IAAI;MACL,OAAOC,UAAE;IACb,KAAK,IAAI;MACL,OAAOC,UAAE;IACb,KAAK,IAAI;MACL,OAAOC,UAAE;IACb,KAAK,IAAI;MACL,OAAOC,UAAE;IACb;MACI,OAAOC,UAAE;EACjB;AACJ,CAAC;AAACC,OAAA,CAAAd,WAAA,GAAAA,WAAA;AAOK,MAAMe,aAAa,GAAGA,CAAC;EAAEC,QAAQ;EAAEC;AAA8B,CAAC,KAAK;EAC1E,QAAQD,QAAQ;IACZ,KAAK,OAAO;IACZ,KAAK,IAAI;MACL,OAAOC,SAAS,GAAG,IAAI,GAAG,IAAI;IAClC,KAAK,IAAI;MACL,OAAO,KAAK;IAChB,KAAK,IAAI;MACL,OAAO,QAAQ;IACnB,KAAK,IAAI;MACL,OAAO,KAAK;IAChB,KAAK,IAAI;MACL,OAAO,GAAG;IACd;MACI,OA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AACO,QAAQ,GAAGP,OAAO,CAACQ,MAAM;IACzD,KAAK1B,IAAI,KAAKP,QAAQ,CAACe,OAAO;MAC1B,OAAOS,UAAU,GAAGM,OAAO,CAACE,QAAQ,GAAGF,OAAO,CAACG,MAAM;IACzD,KAAK1B,IAAI,KAAKP,QAAQ,CAACgB,KAAK;MACxB,OAAOQ,UAAU,GAAG1B,KAAK,CAACkC,QAAQ,GAAGlC,KAAK,CAACmC,MAAM;IACrD,KAAK1B,IAAI,KAAKP,QAAQ,CAACiB,IAAI;MACvB,OAAOO,UAAU,GAAGE,IAAI,CAACM,QAAQ,GAAGN,IAAI,CAACO,MAAM;IACnD,KAAK1B,IAAI,KAAKP,QAAQ,CAACkB,KAAK;MACxB,OAAOM,UAAU,GAAGG,KAAK,CAACK,QAAQ,GAAGL,KAAK,CAACM,MAAM;IACrD,KAAK1B,IAAI,KAAKP,QAAQ,CAACmB,MAAM;MACzB,OAAOK,UAAU,GAAGI,MAAM,CAACI,QAAQ,GAAGJ,MAAM,CAACK,MAAM;IACvD;MACI,OAAOT,UAAU,GAAGK,KAAK,CAACG,QAAQ,GAAGH,KAAK,CAACI,MAAM;EACzD;AACJ,CAAC;AAACzD,OAAA,CAAA8C,4BAAA,GAAAA,4BAAA","ignoreList":[]}
|
|
@@ -1,101 +1,27 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import { getFormattedDayOfWeek, getFormattedTime, getLanguage, getMonthFormat, getTimeTillNow, getYearFormat } from '../../utils/dateInfo';
|
|
1
|
+
import React, { useMemo } from 'react';
|
|
2
|
+
import { useDateInfo } from '../../hooks/useDateInfo';
|
|
4
3
|
const DateInfo = _ref => {
|
|
5
4
|
let {
|
|
6
5
|
date,
|
|
7
6
|
preText = '',
|
|
8
|
-
|
|
7
|
+
shouldShowYear,
|
|
9
8
|
shouldShowTime,
|
|
10
9
|
shouldShowRelativeDayOfWeek,
|
|
11
10
|
shouldUseShortText,
|
|
12
11
|
shouldShowDayOfWeek,
|
|
13
12
|
shouldShowDateToNowDifference
|
|
14
13
|
} = _ref;
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
shouldUseShortText,
|
|
27
|
-
date: formattedDate,
|
|
28
|
-
language
|
|
29
|
-
});
|
|
30
|
-
let formatString = 'dd. ';
|
|
31
|
-
formatString += `${getMonthFormat({
|
|
32
|
-
shouldUseShortText
|
|
33
|
-
})}`;
|
|
34
|
-
formatString += `${getYearFormat({
|
|
35
|
-
date: formattedDate,
|
|
36
|
-
shouldShowThisYear
|
|
37
|
-
})}`;
|
|
38
|
-
newFormattedDateString += format(formattedDate, formatString, {
|
|
39
|
-
locale: language
|
|
40
|
-
});
|
|
41
|
-
newFormattedDateString += getFormattedTime({
|
|
42
|
-
date: formattedDate,
|
|
43
|
-
shouldShowTime,
|
|
44
|
-
language
|
|
45
|
-
});
|
|
46
|
-
setFormattedDateString(newFormattedDateString);
|
|
47
|
-
}, [date, formattedDate, language, shouldShowDateToNowDifference, shouldShowDayOfWeek, shouldShowRelativeDayOfWeek, shouldShowThisYear, shouldShowTime, shouldUseShortText]);
|
|
48
|
-
|
|
49
|
-
// Calculate remaining time till next minute to update time according to time left
|
|
50
|
-
const [currentDate, setCurrentDate] = useState(new Date());
|
|
51
|
-
useEffect(() => {
|
|
52
|
-
// This useEffect is for calculating the current date for shouldShowDateToNowDifference option
|
|
53
|
-
if (!shouldShowDateToNowDifference) {
|
|
54
|
-
return () => {};
|
|
55
|
-
}
|
|
56
|
-
let timeoutTime = formattedDate.getSeconds() - new Date().getSeconds();
|
|
57
|
-
|
|
58
|
-
// If the seconds of date are after seconds of current time, the timeoutTime has to be calculated differently
|
|
59
|
-
if (timeoutTime < 0) {
|
|
60
|
-
timeoutTime = 60 - new Date().getSeconds() + formattedDate.getSeconds();
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// initialized with remaining time
|
|
64
|
-
let timeDiffInMs = formattedDate.getTime() - currentDate.getTime();
|
|
65
|
-
|
|
66
|
-
// set to elapsed time
|
|
67
|
-
if (isPast(formattedDate)) {
|
|
68
|
-
timeDiffInMs = currentDate.getTime() - formattedDate.getTime();
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
// time difference is less than a minute, time should be updated every second
|
|
72
|
-
if (timeDiffInMs < 60000) {
|
|
73
|
-
timeoutTime = 1;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
// Set timeoutTime to at least 1000ms
|
|
77
|
-
timeoutTime = Math.max(timeoutTime * 1000, 1000);
|
|
78
|
-
const timeout = setTimeout(() => {
|
|
79
|
-
setCurrentDate(new Date());
|
|
80
|
-
}, timeoutTime);
|
|
81
|
-
return () => {
|
|
82
|
-
clearTimeout(timeout);
|
|
83
|
-
};
|
|
84
|
-
}, [currentDate, date, formattedDate, shouldShowDateToNowDifference]);
|
|
85
|
-
useEffect(() => {
|
|
86
|
-
// This useEffect is for showing the difference of the date to now
|
|
87
|
-
if (shouldShowDateToNowDifference) {
|
|
88
|
-
setFormattedDateString(getTimeTillNow({
|
|
89
|
-
date: formattedDate,
|
|
90
|
-
currentDate,
|
|
91
|
-
language
|
|
92
|
-
}));
|
|
93
|
-
}
|
|
94
|
-
}, [currentDate, date, formattedDate, language, shouldShowDateToNowDifference]);
|
|
95
|
-
useEffect(() => {
|
|
96
|
-
setFormattedDate(new Date(date));
|
|
97
|
-
}, [date]);
|
|
98
|
-
return useMemo(() => /*#__PURE__*/React.createElement("span", null, preText.trim(), " ", formattedDateString), [formattedDateString, preText]);
|
|
14
|
+
const formattedDate = useDateInfo({
|
|
15
|
+
date,
|
|
16
|
+
preText,
|
|
17
|
+
shouldShowYear,
|
|
18
|
+
shouldShowTime,
|
|
19
|
+
shouldUseShortText,
|
|
20
|
+
shouldShowDayOfWeek,
|
|
21
|
+
shouldShowRelativeDayOfWeek,
|
|
22
|
+
shouldShowDateToNowDifference
|
|
23
|
+
});
|
|
24
|
+
return useMemo(() => /*#__PURE__*/React.createElement("span", null, formattedDate), [formattedDate]);
|
|
99
25
|
};
|
|
100
26
|
DateInfo.displayName = 'DateInfo';
|
|
101
27
|
export default DateInfo;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DateInfo.js","names":["
|
|
1
|
+
{"version":3,"file":"DateInfo.js","names":["React","useMemo","useDateInfo","DateInfo","_ref","date","preText","shouldShowYear","shouldShowTime","shouldShowRelativeDayOfWeek","shouldUseShortText","shouldShowDayOfWeek","shouldShowDateToNowDifference","formattedDate","createElement","displayName"],"sources":["../../../../src/components/date-info/DateInfo.tsx"],"sourcesContent":["import React, { FC, useMemo } from 'react';\nimport { useDateInfo, type UseDateInfoOptions } from '../../hooks/useDateInfo';\n\nexport type DateInfoProps = UseDateInfoOptions;\n\nconst DateInfo: FC<DateInfoProps> = ({\n date,\n preText = '',\n shouldShowYear,\n shouldShowTime,\n shouldShowRelativeDayOfWeek,\n shouldUseShortText,\n shouldShowDayOfWeek,\n shouldShowDateToNowDifference,\n}) => {\n const formattedDate = useDateInfo({\n date,\n preText,\n shouldShowYear,\n shouldShowTime,\n shouldUseShortText,\n shouldShowDayOfWeek,\n shouldShowRelativeDayOfWeek,\n shouldShowDateToNowDifference,\n });\n\n return useMemo(() => <span>{formattedDate}</span>, [formattedDate]);\n};\n\nDateInfo.displayName = 'DateInfo';\n\nexport default DateInfo;\n"],"mappings":"AAAA,OAAOA,KAAK,IAAQC,OAAO,QAAQ,OAAO;AAC1C,SAASC,WAAW,QAAiC,yBAAyB;AAI9E,MAAMC,QAA2B,GAAGC,IAAA,IAS9B;EAAA,IAT+B;IACjCC,IAAI;IACJC,OAAO,GAAG,EAAE;IACZC,cAAc;IACdC,cAAc;IACdC,2BAA2B;IAC3BC,kBAAkB;IAClBC,mBAAmB;IACnBC;EACJ,CAAC,GAAAR,IAAA;EACG,MAAMS,aAAa,GAAGX,WAAW,CAAC;IAC9BG,IAAI;IACJC,OAAO;IACPC,cAAc;IACdC,cAAc;IACdE,kBAAkB;IAClBC,mBAAmB;IACnBF,2BAA2B;IAC3BG;EACJ,CAAC,CAAC;EAEF,OAAOX,OAAO,CAAC,mBAAMD,KAAA,CAAAc,aAAA,eAAOD,aAAoB,CAAC,EAAE,CAACA,aAAa,CAAC,CAAC;AACvE,CAAC;AAEDV,QAAQ,CAACY,WAAW,GAAG,UAAU;AAEjC,eAAeZ,QAAQ","ignoreList":[]}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { format, isPast } from 'date-fns';
|
|
2
|
+
import { useEffect, useMemo, useState } from 'react';
|
|
3
|
+
import { getFormattedDayOfWeek, getFormattedTime, getLanguage, getMonthFormat, getTimeTillNow, getYearFormat } from '../utils/dateInfo';
|
|
4
|
+
export const useDateInfo = _ref => {
|
|
5
|
+
let {
|
|
6
|
+
date,
|
|
7
|
+
shouldShowDateToNowDifference,
|
|
8
|
+
shouldShowRelativeDayOfWeek,
|
|
9
|
+
shouldShowDayOfWeek,
|
|
10
|
+
shouldShowTime,
|
|
11
|
+
shouldUseShortText,
|
|
12
|
+
shouldShowYear,
|
|
13
|
+
preText
|
|
14
|
+
} = _ref;
|
|
15
|
+
const [formattedDateString, setFormattedDateString] = useState('');
|
|
16
|
+
const [language] = useState(getLanguage());
|
|
17
|
+
const formattedDate = useMemo(() => new Date(date), [date]);
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
// This useEffect is used for normal date formation
|
|
20
|
+
if (shouldShowDateToNowDifference) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
let newFormattedDateString = getFormattedDayOfWeek({
|
|
24
|
+
shouldShowDayOfWeek,
|
|
25
|
+
shouldShowRelativeDayOfWeek,
|
|
26
|
+
shouldUseShortText,
|
|
27
|
+
date: formattedDate,
|
|
28
|
+
language
|
|
29
|
+
});
|
|
30
|
+
let formatString = 'dd. ';
|
|
31
|
+
formatString += `${getMonthFormat({
|
|
32
|
+
shouldUseShortText
|
|
33
|
+
})}`;
|
|
34
|
+
formatString += `${getYearFormat({
|
|
35
|
+
date: formattedDate,
|
|
36
|
+
shouldShowYear
|
|
37
|
+
})}`;
|
|
38
|
+
newFormattedDateString += format(formattedDate, formatString, {
|
|
39
|
+
locale: language
|
|
40
|
+
});
|
|
41
|
+
newFormattedDateString += getFormattedTime({
|
|
42
|
+
date: formattedDate,
|
|
43
|
+
shouldShowTime,
|
|
44
|
+
language
|
|
45
|
+
});
|
|
46
|
+
setFormattedDateString(newFormattedDateString);
|
|
47
|
+
}, [date, formattedDate, language, shouldShowDateToNowDifference, shouldShowDayOfWeek, shouldShowRelativeDayOfWeek, shouldShowYear, shouldShowTime, shouldUseShortText]);
|
|
48
|
+
|
|
49
|
+
// Calculate remaining time till next minute to update time according to time left
|
|
50
|
+
const [currentDate, setCurrentDate] = useState(new Date());
|
|
51
|
+
useEffect(() => {
|
|
52
|
+
// This useEffect is for calculating the current date for shouldShowDateToNowDifference option
|
|
53
|
+
if (!shouldShowDateToNowDifference) {
|
|
54
|
+
return () => {};
|
|
55
|
+
}
|
|
56
|
+
let timeoutTime = formattedDate.getSeconds() - new Date().getSeconds();
|
|
57
|
+
|
|
58
|
+
// If the seconds of date are after seconds of current time, the timeoutTime has to be calculated differently
|
|
59
|
+
if (timeoutTime < 0) {
|
|
60
|
+
timeoutTime = 60 - new Date().getSeconds() + formattedDate.getSeconds();
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// initialized with remaining time
|
|
64
|
+
let timeDiffInMs = formattedDate.getTime() - currentDate.getTime();
|
|
65
|
+
|
|
66
|
+
// set to elapsed time
|
|
67
|
+
if (isPast(formattedDate)) {
|
|
68
|
+
timeDiffInMs = currentDate.getTime() - formattedDate.getTime();
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// time difference is less than a minute, time should be updated every second
|
|
72
|
+
if (timeDiffInMs < 60000) {
|
|
73
|
+
timeoutTime = 1;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Set timeoutTime to at least 1000ms
|
|
77
|
+
timeoutTime = Math.max(timeoutTime * 1000, 1000);
|
|
78
|
+
const timeout = setTimeout(() => {
|
|
79
|
+
setCurrentDate(new Date());
|
|
80
|
+
}, timeoutTime);
|
|
81
|
+
return () => {
|
|
82
|
+
clearTimeout(timeout);
|
|
83
|
+
};
|
|
84
|
+
}, [currentDate, date, formattedDate, shouldShowDateToNowDifference]);
|
|
85
|
+
useEffect(() => {
|
|
86
|
+
// This useEffect is for showing the difference of the date to now
|
|
87
|
+
if (shouldShowDateToNowDifference) {
|
|
88
|
+
setFormattedDateString(getTimeTillNow({
|
|
89
|
+
date: formattedDate,
|
|
90
|
+
currentDate,
|
|
91
|
+
language
|
|
92
|
+
}));
|
|
93
|
+
}
|
|
94
|
+
}, [currentDate, date, formattedDate, language, shouldShowDateToNowDifference]);
|
|
95
|
+
return useMemo(() => `${preText ? `${preText.trim()} ` : ''}${formattedDateString}`, [formattedDateString, preText]);
|
|
96
|
+
};
|
|
97
|
+
//# sourceMappingURL=useDateInfo.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useDateInfo.js","names":["format","isPast","useEffect","useMemo","useState","getFormattedDayOfWeek","getFormattedTime","getLanguage","getMonthFormat","getTimeTillNow","getYearFormat","useDateInfo","_ref","date","shouldShowDateToNowDifference","shouldShowRelativeDayOfWeek","shouldShowDayOfWeek","shouldShowTime","shouldUseShortText","shouldShowYear","preText","formattedDateString","setFormattedDateString","language","formattedDate","Date","newFormattedDateString","formatString","locale","currentDate","setCurrentDate","timeoutTime","getSeconds","timeDiffInMs","getTime","Math","max","timeout","setTimeout","clearTimeout","trim"],"sources":["../../../src/hooks/useDateInfo.ts"],"sourcesContent":["import { format, isPast } from 'date-fns';\nimport { useEffect, useMemo, useState } from 'react';\nimport {\n getFormattedDayOfWeek,\n getFormattedTime,\n getLanguage,\n getMonthFormat,\n getTimeTillNow,\n getYearFormat,\n} from '../utils/dateInfo';\n\nexport interface UseDateInfoOptions {\n /**\n * The date, that should be displayed\n */\n date: Date | string;\n /**\n * Additional text for \"shouldShowDateToNowDifference\" prop. Writes a text before the calculated time\n */\n preText?: string;\n /**\n * Adds the current year to the display\n */\n shouldShowYear?: boolean;\n /**\n * Adds the time to the display.\n */\n shouldShowTime?: boolean;\n /**\n * Whether the relative day of week to today should be shown (today, yesterday or tomorrow).\n */\n shouldShowRelativeDayOfWeek?: boolean;\n /**\n * Shortens the day and month text to maximum three digits\n */\n shouldUseShortText?: boolean;\n /**\n * Adds the day of week to the display\n */\n shouldShowDayOfWeek?: boolean;\n /**\n * Shows the difference from the date to now. The component handles updates itself.\n */\n shouldShowDateToNowDifference?: boolean;\n}\n\nexport const useDateInfo = ({\n date,\n shouldShowDateToNowDifference,\n shouldShowRelativeDayOfWeek,\n shouldShowDayOfWeek,\n shouldShowTime,\n shouldUseShortText,\n shouldShowYear,\n preText,\n}: UseDateInfoOptions) => {\n const [formattedDateString, setFormattedDateString] = useState<string>('');\n const [language] = useState(getLanguage());\n\n const formattedDate = useMemo(() => new Date(date), [date]);\n\n useEffect(() => {\n // This useEffect is used for normal date formation\n if (shouldShowDateToNowDifference) {\n return;\n }\n\n let newFormattedDateString = getFormattedDayOfWeek({\n shouldShowDayOfWeek,\n shouldShowRelativeDayOfWeek,\n shouldUseShortText,\n date: formattedDate,\n language,\n });\n\n let formatString = 'dd. ';\n\n formatString += `${getMonthFormat({ shouldUseShortText })}`;\n\n formatString += `${getYearFormat({\n date: formattedDate,\n shouldShowYear,\n })}`;\n\n newFormattedDateString += format(formattedDate, formatString, { locale: language });\n\n newFormattedDateString += getFormattedTime({\n date: formattedDate,\n shouldShowTime,\n language,\n });\n\n setFormattedDateString(newFormattedDateString);\n }, [\n date,\n formattedDate,\n language,\n shouldShowDateToNowDifference,\n shouldShowDayOfWeek,\n shouldShowRelativeDayOfWeek,\n shouldShowYear,\n shouldShowTime,\n shouldUseShortText,\n ]);\n\n // Calculate remaining time till next minute to update time according to time left\n const [currentDate, setCurrentDate] = useState(new Date());\n\n useEffect(() => {\n // This useEffect is for calculating the current date for shouldShowDateToNowDifference option\n if (!shouldShowDateToNowDifference) {\n return () => {};\n }\n\n let timeoutTime = formattedDate.getSeconds() - new Date().getSeconds();\n\n // If the seconds of date are after seconds of current time, the timeoutTime has to be calculated differently\n if (timeoutTime < 0) {\n timeoutTime = 60 - new Date().getSeconds() + formattedDate.getSeconds();\n }\n\n // initialized with remaining time\n let timeDiffInMs = formattedDate.getTime() - currentDate.getTime();\n\n // set to elapsed time\n if (isPast(formattedDate)) {\n timeDiffInMs = currentDate.getTime() - formattedDate.getTime();\n }\n\n // time difference is less than a minute, time should be updated every second\n if (timeDiffInMs < 60000) {\n timeoutTime = 1;\n }\n\n // Set timeoutTime to at least 1000ms\n timeoutTime = Math.max(timeoutTime * 1000, 1000);\n\n const timeout = setTimeout(() => {\n setCurrentDate(new Date());\n }, timeoutTime);\n\n return () => {\n clearTimeout(timeout);\n };\n }, [currentDate, date, formattedDate, shouldShowDateToNowDifference]);\n\n useEffect(() => {\n // This useEffect is for showing the difference of the date to now\n if (shouldShowDateToNowDifference) {\n setFormattedDateString(getTimeTillNow({ date: formattedDate, currentDate, language }));\n }\n }, [currentDate, date, formattedDate, language, shouldShowDateToNowDifference]);\n\n return useMemo(\n () => `${preText ? `${preText.trim()} ` : ''}${formattedDateString}`,\n [formattedDateString, preText],\n );\n};\n"],"mappings":"AAAA,SAASA,MAAM,EAAEC,MAAM,QAAQ,UAAU;AACzC,SAASC,SAAS,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,OAAO;AACpD,SACIC,qBAAqB,EACrBC,gBAAgB,EAChBC,WAAW,EACXC,cAAc,EACdC,cAAc,EACdC,aAAa,QACV,mBAAmB;AAqC1B,OAAO,MAAMC,WAAW,GAAGC,IAAA,IASD;EAAA,IATE;IACxBC,IAAI;IACJC,6BAA6B;IAC7BC,2BAA2B;IAC3BC,mBAAmB;IACn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QAAEN;MAAS,CAAC,CAAC,CAAC;IAC1F;EACJ,CAAC,EAAE,CAACM,WAAW,EAAEhB,IAAI,EAAEW,aAAa,EAAED,QAAQ,EAAET,6BAA6B,CAAC,CAAC;EAE/E,OAAOX,OAAO,CACV,MAAM,GAAGiB,OAAO,GAAG,GAAGA,OAAO,CAACoB,IAAI,CAAC,CAAC,GAAG,GAAG,EAAE,GAAGnB,mBAAmB,EAAE,EACpE,CAACA,mBAAmB,EAAED,OAAO,CACjC,CAAC;AACL,CAAC","ignoreList":[]}
|
|
@@ -51,12 +51,9 @@ export const getTimeString = _ref => {
|
|
|
51
51
|
export const getYearFormat = _ref2 => {
|
|
52
52
|
let {
|
|
53
53
|
date,
|
|
54
|
-
|
|
54
|
+
shouldShowYear
|
|
55
55
|
} = _ref2;
|
|
56
|
-
|
|
57
|
-
return ' yyyy';
|
|
58
|
-
}
|
|
59
|
-
return isThisYear(date) ? '' : ' yyyy';
|
|
56
|
+
return typeof shouldShowYear === 'boolean' && !shouldShowYear || isThisYear(date) ? '' : ' yyyy';
|
|
60
57
|
};
|
|
61
58
|
export const getMonthFormat = _ref3 => {
|
|
62
59
|
let {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dateInfo.js","names":["getLanguage","getChaynsLanguage","format","isPast","isThisYear","isToday","isTomorrow","isYesterday","de","enGB","es","fr","it","nl","pl","pt","tr","uk","TIME_TYPE_STRINGS","translation","site","getTimeString","_ref","language","isMorning","getYearFormat","_ref2","date","shouldShowThisYear","getMonthFormat","_ref3","shouldUseShortText","getFormattedDayOfWeek","_ref4","shouldShowRelativeDayOfWeek","shouldShowDayOfWeek","code","locale","getFormattedTime","_ref5","shouldShowTime","timeFormat","hours","getHours","TimeType","getTimeTypeStrings","getTimeTillNow","_ref6","currentDate","time","value","type","Years","elapsedMilliseconds","getTime","Math","floor","Seconds","Minutes","Hours","Days","Weeks","Months","getFormattedPastTimeString","remainingMilliseconds","getFormattedFutureTimeString","timeTypeStrings","isSingular","seconds","days","weeks","months","years","minutes","past","singular","plural","future"],"sources":["../../../src/utils/dateInfo.ts"],"sourcesContent":["import { getLanguage as getChaynsLanguage } from 'chayns-api';\nimport {\n format,\n isPast,\n isThisYear,\n isToday,\n isTomorrow,\n isYesterday,\n type Locale,\n} from 'date-fns';\nimport { de, enGB, es, fr, it, nl, pl, pt, tr, uk } from 'date-fns/locale';\nimport { TIME_TYPE_STRINGS, type TimeTypeStringsRecord } from '../constants/dateInfo';\n\nexport const getLanguage = (): Locale => {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n switch (getChaynsLanguage().translation || getChaynsLanguage().site) {\n case 'en':\n return enGB;\n case 'nl':\n return nl;\n case 'fr':\n return fr;\n case 'it':\n return it;\n case 'pl':\n return pl;\n case 'pt':\n return pt;\n case 'es':\n return es;\n case 'tr':\n return tr;\n case 'uk':\n return uk;\n default:\n return de;\n }\n};\n\ninterface GetTimeStringProps {\n language?: string;\n isMorning?: boolean;\n}\n\nexport const getTimeString = ({ language, isMorning }: GetTimeStringProps) => {\n switch (language) {\n case 'en-GB':\n case 'pt':\n return isMorning ? 'AM' : 'PM';\n case 'nl':\n return 'uur';\n case 'fr':\n return 'heures';\n case 'de':\n return 'Uhr';\n case 'es':\n return 'h';\n default:\n return '';\n }\n};\n\ninterface GetFormattedYearOptions {\n date: Date;\n shouldShowThisYear?: boolean;\n}\n\nexport const getYearFormat = ({ date, shouldShowThisYear }: GetFormattedYearOptions) => {\n if (shouldShowThisYear) {\n return ' yyyy';\n }\n\n return isThisYear(date) ? '' : ' yyyy';\n};\n\ninterface GetFormattedMonthOptions {\n shouldUseShortText?: boolean;\n}\n\nexport const getMonthFormat = ({ shouldUseShortText }: GetFormattedMonthOptions) => {\n if (shouldUseShortText) {\n return 'LLL.';\n }\n\n return 'LLLL';\n};\n\ninterface GetFormattedDayOfWeekOptions {\n shouldShowDayOfWeek?: boolean;\n shouldShowRelativeDayOfWeek?: boolean;\n shouldUseShortText?: boolean;\n date: Date;\n language?: Locale;\n}\n\nexport const getFormattedDayOfWeek = ({\n shouldShowRelativeDayOfWeek,\n shouldShowDayOfWeek,\n shouldUseShortText,\n date,\n language,\n}: GetFormattedDayOfWeekOptions) => {\n if (!shouldShowDayOfWeek && !shouldShowRelativeDayOfWeek) {\n return '';\n }\n\n if (shouldShowRelativeDayOfWeek) {\n if (isToday(date)) {\n switch (language?.code) {\n case 'en-GB':\n return 'Today, ';\n case 'nl':\n return 'Vandaag, ';\n case 'fr':\n return \"Aujourd'hui, \";\n case 'it':\n return 'Oggi, ';\n case 'pl':\n return 'Dzisiaj, ';\n case 'pt':\n return 'Hoje, ';\n case 'es':\n return 'Hoy, ';\n case 'tr':\n return 'Bugün, ';\n case 'uk':\n return 'Сьогодні, ';\n default:\n return 'Heute, ';\n }\n }\n\n if (isTomorrow(date)) {\n switch (language?.code) {\n case 'en-GB':\n return 'Tomorrow, ';\n case 'nl':\n return 'Morgen, ';\n case 'fr':\n return 'Demain, ';\n case 'it':\n return 'Domani, ';\n case 'pl':\n return 'Jutro, ';\n case 'pt':\n return 'Amanhã, ';\n case 'es':\n return 'Mañana, ';\n case 'tr':\n return 'Yarın, ';\n case 'uk':\n return 'Завтра, ';\n default:\n return 'Morgen, ';\n }\n }\n\n if (isYesterday(date)) {\n switch (language?.code) {\n case 'en-GB':\n return 'Yesterday, ';\n case 'nl':\n return 'Gisteren, ';\n case 'fr':\n return 'Hier, ';\n case 'it':\n return 'Ieri, ';\n case 'pl':\n return 'Wczoraj, ';\n case 'pt':\n return 'Ontem, ';\n case 'es':\n return 'Ayer, ';\n case 'tr':\n return 'Dün, ';\n case 'uk':\n return 'Вчора, ';\n default:\n return 'Gestern, ';\n }\n }\n }\n\n if (shouldUseShortText) {\n return format(date, 'E., ', { locale: language });\n }\n\n return format(date, 'EEEE, ', { locale: language });\n};\n\ninterface GetFormattedTimeOptions {\n shouldShowTime?: boolean;\n date: Date;\n language: Locale;\n}\n\nexport const getFormattedTime = ({ shouldShowTime, date, language }: GetFormattedTimeOptions) => {\n if (!shouldShowTime) {\n return '';\n }\n\n let timeFormat = 'HH:mm';\n\n if (language.code === 'en-GB' || language.code === 'pt') {\n timeFormat = 'KK:mm';\n }\n\n return `, ${format(date, timeFormat)} ${getTimeString({\n language: language.code,\n isMorning: isMorning(date),\n })}`;\n};\n\nexport const isMorning = (date: Date) => {\n const hours = date.getHours();\n\n return hours >= 0 && hours < 12;\n};\n\nexport interface Time {\n value: number;\n type: TimeType;\n isPast: boolean;\n}\n\nexport enum TimeType {\n Seconds,\n Minutes,\n Hours,\n Days,\n Weeks,\n Months,\n Years,\n}\n\nexport const getTimeTypeStrings = (language: string): TimeTypeStringsRecord | undefined =>\n TIME_TYPE_STRINGS[language === 'en-GB' ? 'en' : language];\n\ninterface GetTimeTillNowOptions {\n date: Date;\n currentDate: Date;\n language: Locale;\n}\n\nexport const getTimeTillNow = ({ date, currentDate, language }: GetTimeTillNowOptions): string => {\n const time: Time = {\n value: 0,\n type: TimeType.Years,\n isPast: false,\n };\n\n if (isPast(date)) {\n const elapsedMilliseconds = currentDate.getTime() - date.getTime();\n\n switch (true) {\n case elapsedMilliseconds < 60000:\n time.value = Math.floor(elapsedMilliseconds / 1000);\n time.type = TimeType.Seconds;\n break;\n case elapsedMilliseconds < 3600000:\n time.value = Math.floor(elapsedMilliseconds / 60000);\n time.type = TimeType.Minutes;\n break;\n case elapsedMilliseconds < 86400000:\n time.value = Math.floor(elapsedMilliseconds / 3600000);\n time.type = TimeType.Hours;\n break;\n case elapsedMilliseconds < 604800000:\n time.value = Math.floor(elapsedMilliseconds / 86400000);\n time.type = TimeType.Days;\n break;\n case elapsedMilliseconds < 2592000000:\n time.value = Math.floor(elapsedMilliseconds / 604800000);\n time.type = TimeType.Weeks;\n break;\n case elapsedMilliseconds < 31536000000:\n time.value = Math.floor(elapsedMilliseconds / 2592000000);\n time.type = TimeType.Months;\n break;\n default:\n time.value = Math.floor(elapsedMilliseconds / 31536000000);\n time.type = TimeType.Years;\n break;\n }\n\n return `${time.value} ${getFormattedPastTimeString(time, language)}`;\n }\n\n const remainingMilliseconds = date.getTime() - currentDate.getTime();\n\n switch (true) {\n case remainingMilliseconds < 60000:\n time.value = Math.floor(remainingMilliseconds / 1000);\n time.type = TimeType.Seconds;\n break;\n case remainingMilliseconds < 3600000:\n time.value = Math.floor(remainingMilliseconds / 60000);\n time.type = TimeType.Minutes;\n break;\n case remainingMilliseconds < 86400000:\n time.value = Math.floor(remainingMilliseconds / 3600000);\n time.type = TimeType.Hours;\n break;\n case remainingMilliseconds < 604800000:\n time.value = Math.floor(remainingMilliseconds / 86400000);\n time.type = TimeType.Days;\n break;\n case remainingMilliseconds < 2592000000:\n time.value = Math.floor(remainingMilliseconds / 604800000);\n time.type = TimeType.Weeks;\n break;\n case remainingMilliseconds < 31536000000:\n time.value = Math.floor(remainingMilliseconds / 2592000000);\n time.type = TimeType.Months;\n break;\n default:\n time.value = Math.floor(remainingMilliseconds / 31536000000);\n time.type = TimeType.Years;\n break;\n }\n\n return `${time.value} ${getFormattedFutureTimeString(time, language)}`;\n};\n\nexport const getFormattedPastTimeString = (time: Time, language: Locale): string => {\n const { value, type } = time;\n\n const timeTypeStrings = getTimeTypeStrings(language.code ?? 'de');\n const isSingular = value === 1;\n\n if (!timeTypeStrings) {\n return '';\n }\n\n const { seconds, days, weeks, months, years, minutes, hours } = timeTypeStrings.past;\n\n switch (true) {\n case type === TimeType.Seconds:\n return isSingular ? seconds.singular : seconds.plural;\n case type === TimeType.Minutes:\n return isSingular ? minutes.singular : minutes.plural;\n case type === TimeType.Hours:\n return isSingular ? hours.singular : hours.plural;\n case type === TimeType.Days:\n return isSingular ? days.singular : days.plural;\n case type === TimeType.Weeks:\n return isSingular ? weeks.singular : weeks.plural;\n case type === TimeType.Months:\n return isSingular ? months.singular : months.plural;\n default:\n return isSingular ? years.singular : years.plural;\n }\n};\n\nexport const getFormattedFutureTimeString = (time: Time, language: Locale): string => {\n const { value, type } = time;\n const timeTypeStrings = getTimeTypeStrings(language.code ?? 'de');\n const isSingular = value === 1;\n\n if (!timeTypeStrings) {\n return '';\n }\n\n const { seconds, days, weeks, months, years, minutes, hours } = timeTypeStrings.future;\n\n switch (true) {\n case type === TimeType.Seconds:\n return isSingular ? seconds.singular : seconds.plural;\n case type === TimeType.Minutes:\n return isSingular ? minutes.singular : minutes.plural;\n case type === TimeType.Hours:\n return isSingular ? hours.singular : hours.plural;\n case type === TimeType.Days:\n return isSingular ? days.singular : days.plural;\n case type === TimeType.Weeks:\n return isSingular ? weeks.singular : weeks.plural;\n case type === TimeType.Months:\n return isSingular ? months.singular : months.plural;\n default:\n return isSingular ? years.singular : years.plural;\n }\n};\n"],"mappings":"AAAA,SAASA,WAAW,IAAIC,iBAAiB,QAAQ,YAAY;AAC7D,SACIC,MAAM,EACNC,MAAM,EACNC,UAAU,EACVC,OAAO,EACPC,UAAU,EACVC,WAAW,QAER,UAAU;AACjB,SAASC,EAAE,EAAEC,IAAI,EAAEC,EAAE,EAAEC,EAAE,EAAEC,EAAE,EAAEC,EAAE,EAAEC,EAAE,EAAEC,EAAE,EAAEC,EAAE,EAAEC,EAAE,QAAQ,iBAAiB;AAC1E,SAASC,iBAAiB,QAAoC,uBAAuB;AAErF,OAAO,MAAMlB,WAAW,GAAGA,CAAA,KAAc;EACrC;EACA,QAAQC,iBAAiB,CAAC,CAAC,CAACkB,WAAW,IAAIlB,iBAAiB,CAAC,CAAC,CAACmB,IAAI;IAC/D,KAAK,IAAI;MACL,OAAOX,IAAI;IACf,KAAK,IAAI;MACL,OAAOI,EAAE;IACb,KAAK,IAAI;MACL,OAAOF,EAAE;IACb,KAAK,IAAI;MACL,OAAOC,EAAE;IACb,KAAK,IAAI;MACL,OAAOE,EAAE;IACb,KAAK,IAAI;MACL,OAAOC,EAAE;IACb,KAAK,IAAI;MACL,OAAOL,EAAE;IACb,KAAK,IAAI;MACL,OAAOM,EAAE;IACb,KAAK,IAAI;MACL,OAAOC,EAAE;IACb;MACI,OAAOT,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IACR,KAAK1B,IAAI,KAAKP,QAAQ,CAACa,OAAO;MAC1B,OAAOU,UAAU,GAAGC,OAAO,CAACO,QAAQ,GAAGP,OAAO,CAACQ,MAAM;IACzD,KAAKzB,IAAI,KAAKP,QAAQ,CAACc,OAAO;MAC1B,OAAOS,UAAU,GAAGM,OAAO,CAACE,QAAQ,GAAGF,OAAO,CAACG,MAAM;IACzD,KAAKzB,IAAI,KAAKP,QAAQ,CAACe,KAAK;MACxB,OAAOQ,UAAU,GAAGzB,KAAK,CAACiC,QAAQ,GAAGjC,KAAK,CAACkC,MAAM;IACrD,KAAKzB,IAAI,KAAKP,QAAQ,CAACgB,IAAI;MACvB,OAAOO,UAAU,GAAGE,IAAI,CAACM,QAAQ,GAAGN,IAAI,CAACO,MAAM;IACnD,KAAKzB,IAAI,KAAKP,QAAQ,CAACiB,KAAK;MACxB,OAAOM,UAAU,GAAGG,KAAK,CAACK,QAAQ,GAAGL,KAAK,CAACM,MAAM;IACrD,KAAKzB,IAAI,KAAKP,QAAQ,CAACkB,MAAM;MACzB,OAAOK,UAAU,GAAGI,MAAM,CAACI,QAAQ,GAAGJ,MAAM,CAACK,MAAM;IACvD;MACI,OAAOT,UAAU,GAAGK,KAAK,CAACG,QAAQ,GAAGH,KAAK,CAACI,MAAM;EACzD;AACJ,CAAC","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"dateInfo.js","names":["getLanguage","getChaynsLanguage","format","isPast","isThisYear","isToday","isTomorrow","isYesterday","de","enGB","es","fr","it","nl","pl","pt","tr","uk","TIME_TYPE_STRINGS","translation","site","getTimeString","_ref","language","isMorning","getYearFormat","_ref2","date","shouldShowYear","getMonthFormat","_ref3","shouldUseShortText","getFormattedDayOfWeek","_ref4","shouldShowRelativeDayOfWeek","shouldShowDayOfWeek","code","locale","getFormattedTime","_ref5","shouldShowTime","timeFormat","hours","getHours","TimeType","getTimeTypeStrings","getTimeTillNow","_ref6","currentDate","time","value","type","Years","elapsedMilliseconds","getTime","Math","floor","Seconds","Minutes","Hours","Days","Weeks","Months","getFormattedPastTimeString","remainingMilliseconds","getFormattedFutureTimeString","timeTypeStrings","isSingular","seconds","days","weeks","months","years","minutes","past","singular","plural","future"],"sources":["../../../src/utils/dateInfo.ts"],"sourcesContent":["import { getLanguage as getChaynsLanguage } from 'chayns-api';\nimport {\n format,\n isPast,\n isThisYear,\n isToday,\n isTomorrow,\n isYesterday,\n type Locale,\n} from 'date-fns';\nimport { de, enGB, es, fr, it, nl, pl, pt, tr, uk } from 'date-fns/locale';\nimport { TIME_TYPE_STRINGS, type TimeTypeStringsRecord } from '../constants/dateInfo';\n\nexport const getLanguage = (): Locale => {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n switch (getChaynsLanguage().translation || getChaynsLanguage().site) {\n case 'en':\n return enGB;\n case 'nl':\n return nl;\n case 'fr':\n return fr;\n case 'it':\n return it;\n case 'pl':\n return pl;\n case 'pt':\n return pt;\n case 'es':\n return es;\n case 'tr':\n return tr;\n case 'uk':\n return uk;\n default:\n return de;\n }\n};\n\ninterface GetTimeStringProps {\n language?: string;\n isMorning?: boolean;\n}\n\nexport const getTimeString = ({ language, isMorning }: GetTimeStringProps) => {\n switch (language) {\n case 'en-GB':\n case 'pt':\n return isMorning ? 'AM' : 'PM';\n case 'nl':\n return 'uur';\n case 'fr':\n return 'heures';\n case 'de':\n return 'Uhr';\n case 'es':\n return 'h';\n default:\n return '';\n }\n};\n\ninterface GetFormattedYearOptions {\n date: Date;\n shouldShowYear?: boolean;\n}\n\nexport const getYearFormat = ({ date, shouldShowYear }: GetFormattedYearOptions) =>\n (typeof shouldShowYear === 'boolean' && !shouldShowYear) || isThisYear(date) ? '' : ' yyyy';\n\ninterface GetFormattedMonthOptions {\n shouldUseShortText?: boolean;\n}\n\nexport const getMonthFormat = ({ shouldUseShortText }: GetFormattedMonthOptions) => {\n if (shouldUseShortText) {\n return 'LLL.';\n }\n\n return 'LLLL';\n};\n\ninterface GetFormattedDayOfWeekOptions {\n shouldShowDayOfWeek?: boolean;\n shouldShowRelativeDayOfWeek?: boolean;\n shouldUseShortText?: boolean;\n date: Date;\n language?: Locale;\n}\n\nexport const getFormattedDayOfWeek = ({\n shouldShowRelativeDayOfWeek,\n shouldShowDayOfWeek,\n shouldUseShortText,\n date,\n language,\n}: GetFormattedDayOfWeekOptions) => {\n if (!shouldShowDayOfWeek && !shouldShowRelativeDayOfWeek) {\n return '';\n }\n\n if (shouldShowRelativeDayOfWeek) {\n if (isToday(date)) {\n switch (language?.code) {\n case 'en-GB':\n return 'Today, ';\n case 'nl':\n return 'Vandaag, ';\n case 'fr':\n return \"Aujourd'hui, \";\n case 'it':\n return 'Oggi, ';\n case 'pl':\n return 'Dzisiaj, ';\n case 'pt':\n return 'Hoje, ';\n case 'es':\n return 'Hoy, ';\n case 'tr':\n return 'Bugün, ';\n case 'uk':\n return 'Сьогодні, ';\n default:\n return 'Heute, ';\n }\n }\n\n if (isTomorrow(date)) {\n switch (language?.code) {\n case 'en-GB':\n return 'Tomorrow, ';\n case 'nl':\n return 'Morgen, ';\n case 'fr':\n return 'Demain, ';\n case 'it':\n return 'Domani, ';\n case 'pl':\n return 'Jutro, ';\n case 'pt':\n return 'Amanhã, ';\n case 'es':\n return 'Mañana, ';\n case 'tr':\n return 'Yarın, ';\n case 'uk':\n return 'Завтра, ';\n default:\n return 'Morgen, ';\n }\n }\n\n if (isYesterday(date)) {\n switch (language?.code) {\n case 'en-GB':\n return 'Yesterday, ';\n case 'nl':\n return 'Gisteren, ';\n case 'fr':\n return 'Hier, ';\n case 'it':\n return 'Ieri, ';\n case 'pl':\n return 'Wczoraj, ';\n case 'pt':\n return 'Ontem, ';\n case 'es':\n return 'Ayer, ';\n case 'tr':\n return 'Dün, ';\n case 'uk':\n return 'Вчора, ';\n default:\n return 'Gestern, ';\n }\n }\n }\n\n if (shouldUseShortText) {\n return format(date, 'E., ', { locale: language });\n }\n\n return format(date, 'EEEE, ', { locale: language });\n};\n\ninterface GetFormattedTimeOptions {\n shouldShowTime?: boolean;\n date: Date;\n language: Locale;\n}\n\nexport const getFormattedTime = ({ shouldShowTime, date, language }: GetFormattedTimeOptions) => {\n if (!shouldShowTime) {\n return '';\n }\n\n let timeFormat = 'HH:mm';\n\n if (language.code === 'en-GB' || language.code === 'pt') {\n timeFormat = 'KK:mm';\n }\n\n return `, ${format(date, timeFormat)} ${getTimeString({\n language: language.code,\n isMorning: isMorning(date),\n })}`;\n};\n\nexport const isMorning = (date: Date) => {\n const hours = date.getHours();\n\n return hours >= 0 && hours < 12;\n};\n\nexport interface Time {\n value: number;\n type: TimeType;\n isPast: boolean;\n}\n\nexport enum TimeType {\n Seconds,\n Minutes,\n Hours,\n Days,\n Weeks,\n Months,\n Years,\n}\n\nexport const getTimeTypeStrings = (language: string): TimeTypeStringsRecord | undefined =>\n TIME_TYPE_STRINGS[language === 'en-GB' ? 'en' : language];\n\ninterface GetTimeTillNowOptions {\n date: Date;\n currentDate: Date;\n language: Locale;\n}\n\nexport const getTimeTillNow = ({ date, currentDate, language }: GetTimeTillNowOptions): string => {\n const time: Time = {\n value: 0,\n type: TimeType.Years,\n isPast: false,\n };\n\n if (isPast(date)) {\n const elapsedMilliseconds = currentDate.getTime() - date.getTime();\n\n switch (true) {\n case elapsedMilliseconds < 60000:\n time.value = Math.floor(elapsedMilliseconds / 1000);\n time.type = TimeType.Seconds;\n break;\n case elapsedMilliseconds < 3600000:\n time.value = Math.floor(elapsedMilliseconds / 60000);\n time.type = TimeType.Minutes;\n break;\n case elapsedMilliseconds < 86400000:\n time.value = Math.floor(elapsedMilliseconds / 3600000);\n time.type = TimeType.Hours;\n break;\n case elapsedMilliseconds < 604800000:\n time.value = Math.floor(elapsedMilliseconds / 86400000);\n time.type = TimeType.Days;\n break;\n case elapsedMilliseconds < 2592000000:\n time.value = Math.floor(elapsedMilliseconds / 604800000);\n time.type = TimeType.Weeks;\n break;\n case elapsedMilliseconds < 31536000000:\n time.value = Math.floor(elapsedMilliseconds / 2592000000);\n time.type = TimeType.Months;\n break;\n default:\n time.value = Math.floor(elapsedMilliseconds / 31536000000);\n time.type = TimeType.Years;\n break;\n }\n\n return `${time.value} ${getFormattedPastTimeString(time, language)}`;\n }\n\n const remainingMilliseconds = date.getTime() - currentDate.getTime();\n\n switch (true) {\n case remainingMilliseconds < 60000:\n time.value = Math.floor(remainingMilliseconds / 1000);\n time.type = TimeType.Seconds;\n break;\n case remainingMilliseconds < 3600000:\n time.value = Math.floor(remainingMilliseconds / 60000);\n time.type = TimeType.Minutes;\n break;\n case remainingMilliseconds < 86400000:\n time.value = Math.floor(remainingMilliseconds / 3600000);\n time.type = TimeType.Hours;\n break;\n case remainingMilliseconds < 604800000:\n time.value = Math.floor(remainingMilliseconds / 86400000);\n time.type = TimeType.Days;\n break;\n case remainingMilliseconds < 2592000000:\n time.value = Math.floor(remainingMilliseconds / 604800000);\n time.type = TimeType.Weeks;\n break;\n case remainingMilliseconds < 31536000000:\n time.value = Math.floor(remainingMilliseconds / 2592000000);\n time.type = TimeType.Months;\n break;\n default:\n time.value = Math.floor(remainingMilliseconds / 31536000000);\n time.type = TimeType.Years;\n break;\n }\n\n return `${time.value} ${getFormattedFutureTimeString(time, language)}`;\n};\n\nexport const getFormattedPastTimeString = (time: Time, language: Locale): string => {\n const { value, type } = time;\n\n const timeTypeStrings = getTimeTypeStrings(language.code ?? 'de');\n const isSingular = value === 1;\n\n if (!timeTypeStrings) {\n return '';\n }\n\n const { seconds, days, weeks, months, years, minutes, hours } = timeTypeStrings.past;\n\n switch (true) {\n case type === TimeType.Seconds:\n return isSingular ? seconds.singular : seconds.plural;\n case type === TimeType.Minutes:\n return isSingular ? minutes.singular : minutes.plural;\n case type === TimeType.Hours:\n return isSingular ? hours.singular : hours.plural;\n case type === TimeType.Days:\n return isSingular ? days.singular : days.plural;\n case type === TimeType.Weeks:\n return isSingular ? weeks.singular : weeks.plural;\n case type === TimeType.Months:\n return isSingular ? months.singular : months.plural;\n default:\n return isSingular ? years.singular : years.plural;\n }\n};\n\nexport const getFormattedFutureTimeString = (time: Time, language: Locale): string => {\n const { value, type } = time;\n const timeTypeStrings = getTimeTypeStrings(language.code ?? 'de');\n const isSingular = value === 1;\n\n if (!timeTypeStrings) {\n return '';\n }\n\n const { seconds, days, weeks, months, years, minutes, hours } = timeTypeStrings.future;\n\n switch (true) {\n case type === TimeType.Seconds:\n return isSingular ? seconds.singular : seconds.plural;\n case type === TimeType.Minutes:\n return isSingular ? minutes.singular : minutes.plural;\n case type === TimeType.Hours:\n return isSingular ? hours.singular : hours.plural;\n case type === TimeType.Days:\n return isSingular ? days.singular : days.plural;\n case type === TimeType.Weeks:\n return isSingular ? weeks.singular : weeks.plural;\n case type === TimeType.Months:\n return isSingular ? months.singular : months.plural;\n default:\n return isSingular ? years.singular : years.plural;\n }\n};\n"],"mappings":"AAAA,SAASA,WAAW,IAAIC,iBAAiB,QAAQ,YAAY;AAC7D,SACIC,MAAM,EACNC,MAAM,EACNC,UAAU,EACVC,OAAO,EACPC,UAAU,EACVC,WAAW,QAER,UAAU;AACjB,SAASC,EAAE,EAAEC,IAAI,EAAEC,EAAE,EAAEC,EAAE,EAAEC,EAAE,EAAEC,EAAE,EAAEC,EAAE,EAAEC,EAAE,EAAEC,EAAE,EAAEC,EAAE,QAAQ,iBAAiB;AAC1E,SAASC,iBAAiB,QAAoC,uBAAuB;AAErF,OAAO,MAAMlB,WAAW,GAAGA,CAAA,KAAc;EACrC;EACA,QAAQC,iBAAiB,CAAC,CAAC,CAACkB,WAAW,IAAIlB,iBAAiB,CAAC,CAAC,CAACmB,IAAI;IAC/D,KAAK,IAAI;MACL,OAAOX,IAAI;IACf,KAAK,IAAI;MACL,OAAOI,EAAE;IACb,KAAK,IAAI;MACL,OAAOF,EAAE;IACb,KAAK,IAAI;MACL,OAAOC,EAAE;IACb,KAAK,IAAI;MACL,OAAOE,EAAE;IACb,KAAK,IAAI;MACL,OAAOC,EAAE;IACb,KAAK,IAAI;MACL,OAAOL,EAAE;IACb,KAAK,IAA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M,CAAC,GAAGwB,eAAe,CAACW,MAAM;EAEtF,QAAQ,IAAI;IACR,KAAK1B,IAAI,KAAKP,QAAQ,CAACa,OAAO;MAC1B,OAAOU,UAAU,GAAGC,OAAO,CAACO,QAAQ,GAAGP,OAAO,CAACQ,MAAM;IACzD,KAAKzB,IAAI,KAAKP,QAAQ,CAACc,OAAO;MAC1B,OAAOS,UAAU,GAAGM,OAAO,CAACE,QAAQ,GAAGF,OAAO,CAACG,MAAM;IACzD,KAAKzB,IAAI,KAAKP,QAAQ,CAACe,KAAK;MACxB,OAAOQ,UAAU,GAAGzB,KAAK,CAACiC,QAAQ,GAAGjC,KAAK,CAACkC,MAAM;IACrD,KAAKzB,IAAI,KAAKP,QAAQ,CAACgB,IAAI;MACvB,OAAOO,UAAU,GAAGE,IAAI,CAACM,QAAQ,GAAGN,IAAI,CAACO,MAAM;IACnD,KAAKzB,IAAI,KAAKP,QAAQ,CAACiB,KAAK;MACxB,OAAOM,UAAU,GAAGG,KAAK,CAACK,QAAQ,GAAGL,KAAK,CAACM,MAAM;IACrD,KAAKzB,IAAI,KAAKP,QAAQ,CAACkB,MAAM;MACzB,OAAOK,UAAU,GAAGI,MAAM,CAACI,QAAQ,GAAGJ,MAAM,CAACK,MAAM;IACvD;MACI,OAAOT,UAAU,GAAGK,KAAK,CAACG,QAAQ,GAAGH,KAAK,CAACI,MAAM;EACzD;AACJ,CAAC","ignoreList":[]}
|
|
@@ -1,37 +1,5 @@
|
|
|
1
1
|
import { FC } from 'react';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
* The date, that should be displayed
|
|
5
|
-
*/
|
|
6
|
-
date: Date | string;
|
|
7
|
-
/**
|
|
8
|
-
* Additional text for "shouldShowDateToNowDifference" prop. Writes a text before the calculated time
|
|
9
|
-
*/
|
|
10
|
-
preText?: string;
|
|
11
|
-
/**
|
|
12
|
-
* Adds the current year to the display
|
|
13
|
-
*/
|
|
14
|
-
shouldShowThisYear?: boolean;
|
|
15
|
-
/**
|
|
16
|
-
* Adds the time to the display.
|
|
17
|
-
*/
|
|
18
|
-
shouldShowTime?: boolean;
|
|
19
|
-
/**
|
|
20
|
-
* Whether the relative day of week to today should be shown (today, yesterday or tomorrow).
|
|
21
|
-
*/
|
|
22
|
-
shouldShowRelativeDayOfWeek?: boolean;
|
|
23
|
-
/**
|
|
24
|
-
* Shortens the day and month text to maximum three digits
|
|
25
|
-
*/
|
|
26
|
-
shouldUseShortText?: boolean;
|
|
27
|
-
/**
|
|
28
|
-
* Adds the day of week to the display
|
|
29
|
-
*/
|
|
30
|
-
shouldShowDayOfWeek?: boolean;
|
|
31
|
-
/**
|
|
32
|
-
* Shows the difference from the date to now. The component handles updates itself.
|
|
33
|
-
*/
|
|
34
|
-
shouldShowDateToNowDifference?: boolean;
|
|
35
|
-
};
|
|
2
|
+
import { type UseDateInfoOptions } from '../../hooks/useDateInfo';
|
|
3
|
+
export type DateInfoProps = UseDateInfoOptions;
|
|
36
4
|
declare const DateInfo: FC<DateInfoProps>;
|
|
37
5
|
export default DateInfo;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export interface UseDateInfoOptions {
|
|
2
|
+
/**
|
|
3
|
+
* The date, that should be displayed
|
|
4
|
+
*/
|
|
5
|
+
date: Date | string;
|
|
6
|
+
/**
|
|
7
|
+
* Additional text for "shouldShowDateToNowDifference" prop. Writes a text before the calculated time
|
|
8
|
+
*/
|
|
9
|
+
preText?: string;
|
|
10
|
+
/**
|
|
11
|
+
* Adds the current year to the display
|
|
12
|
+
*/
|
|
13
|
+
shouldShowYear?: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Adds the time to the display.
|
|
16
|
+
*/
|
|
17
|
+
shouldShowTime?: boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Whether the relative day of week to today should be shown (today, yesterday or tomorrow).
|
|
20
|
+
*/
|
|
21
|
+
shouldShowRelativeDayOfWeek?: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Shortens the day and month text to maximum three digits
|
|
24
|
+
*/
|
|
25
|
+
shouldUseShortText?: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Adds the day of week to the display
|
|
28
|
+
*/
|
|
29
|
+
shouldShowDayOfWeek?: boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Shows the difference from the date to now. The component handles updates itself.
|
|
32
|
+
*/
|
|
33
|
+
shouldShowDateToNowDifference?: boolean;
|
|
34
|
+
}
|
|
35
|
+
export declare const useDateInfo: ({ date, shouldShowDateToNowDifference, shouldShowRelativeDayOfWeek, shouldShowDayOfWeek, shouldShowTime, shouldUseShortText, shouldShowYear, preText, }: UseDateInfoOptions) => string;
|
|
@@ -8,9 +8,9 @@ interface GetTimeStringProps {
|
|
|
8
8
|
export declare const getTimeString: ({ language, isMorning }: GetTimeStringProps) => "" | "uur" | "heures" | "AM" | "PM" | "Uhr" | "h";
|
|
9
9
|
interface GetFormattedYearOptions {
|
|
10
10
|
date: Date;
|
|
11
|
-
|
|
11
|
+
shouldShowYear?: boolean;
|
|
12
12
|
}
|
|
13
|
-
export declare const getYearFormat: ({ date,
|
|
13
|
+
export declare const getYearFormat: ({ date, shouldShowYear }: GetFormattedYearOptions) => "" | " yyyy";
|
|
14
14
|
interface GetFormattedMonthOptions {
|
|
15
15
|
shouldUseShortText?: boolean;
|
|
16
16
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chayns-components/date",
|
|
3
|
-
"version": "5.0.0-beta.
|
|
3
|
+
"version": "5.0.0-beta.772",
|
|
4
4
|
"description": "A set of beautiful React components for developing your own applications with chayns.",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"browserslist": [
|
|
@@ -67,7 +67,7 @@
|
|
|
67
67
|
"typescript": "^5.5.4"
|
|
68
68
|
},
|
|
69
69
|
"dependencies": {
|
|
70
|
-
"@chayns-components/core": "^5.0.0-beta.
|
|
70
|
+
"@chayns-components/core": "^5.0.0-beta.772",
|
|
71
71
|
"date-fns": "^3.6.0",
|
|
72
72
|
"uuid": "^10.0.0"
|
|
73
73
|
},
|
|
@@ -81,5 +81,5 @@
|
|
|
81
81
|
"publishConfig": {
|
|
82
82
|
"access": "public"
|
|
83
83
|
},
|
|
84
|
-
"gitHead": "
|
|
84
|
+
"gitHead": "6b34cab3d20171d951d13a3148db26fbe03c1525"
|
|
85
85
|
}
|