@trackunit/react-date-and-time-components 0.0.42 → 0.0.43
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/index.cjs.js +6 -6
- package/index.esm.js +6 -6
- package/package.json +1 -1
package/index.cjs.js
CHANGED
|
@@ -4,8 +4,8 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var jsxRuntime = require('react/jsx-runtime');
|
|
6
6
|
var i18nLibraryTranslation = require('@trackunit/i18n-library-translation');
|
|
7
|
-
var reactDateAndTimeHooks = require('@trackunit/react-date-and-time-hooks');
|
|
8
7
|
var dateAndTimeUtils = require('@trackunit/date-and-time-utils');
|
|
8
|
+
var reactDateAndTimeHooks = require('@trackunit/react-date-and-time-hooks');
|
|
9
9
|
var uiDesignTokens = require('@trackunit/ui-design-tokens');
|
|
10
10
|
var react = require('react');
|
|
11
11
|
var reactComponents = require('@trackunit/react-components');
|
|
@@ -90,18 +90,18 @@ const MS_PER_HOUR = 60 * 60 * 1000;
|
|
|
90
90
|
*/
|
|
91
91
|
const DateTime = ({ value, format, className, fromNow, withTitle, titleFormat, timezone, subtle, calendar, }) => {
|
|
92
92
|
const { t } = useTranslation();
|
|
93
|
-
const
|
|
93
|
+
const locale = reactDateAndTimeHooks.useLocale();
|
|
94
94
|
const nowDate = react.useMemo(() => new Date(), []);
|
|
95
95
|
const date = value ? dateAndTimeUtils.toDateUtil(value) : nowDate;
|
|
96
|
-
const newDateTime = dateAndTimeUtils.formatDateUtil(date, format, timezone === null || timezone === void 0 ? void 0 : timezone.id,
|
|
97
|
-
const titleDateTime = withTitle ? dateAndTimeUtils.formatDateUtil(date, titleFormat, timezone === null || timezone === void 0 ? void 0 : timezone.id,
|
|
96
|
+
const newDateTime = dateAndTimeUtils.formatDateUtil(date, format, timezone === null || timezone === void 0 ? void 0 : timezone.id, locale);
|
|
97
|
+
const titleDateTime = withTitle ? dateAndTimeUtils.formatDateUtil(date, titleFormat, timezone === null || timezone === void 0 ? void 0 : timezone.id, locale) : undefined;
|
|
98
98
|
const getTimeSince = react.useCallback((from, to) => {
|
|
99
99
|
const same = dateAndTimeUtils.isEqualUtil(from, to);
|
|
100
100
|
if (same) {
|
|
101
101
|
return t("dateTime.instant.now");
|
|
102
102
|
}
|
|
103
|
-
return dateAndTimeUtils.timeSinceAuto(from, to, timezone === null || timezone === void 0 ? void 0 : timezone.id,
|
|
104
|
-
}, [
|
|
103
|
+
return dateAndTimeUtils.timeSinceAuto(from, to, timezone === null || timezone === void 0 ? void 0 : timezone.id, locale);
|
|
104
|
+
}, [locale, t, timezone === null || timezone === void 0 ? void 0 : timezone.id]);
|
|
105
105
|
const dateValue = react.useMemo(() => {
|
|
106
106
|
return fromNow ? getTimeSince(date, nowDate) : newDateTime;
|
|
107
107
|
}, [date, fromNow, getTimeSince, newDateTime, nowDate]);
|
package/index.esm.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
2
2
|
import { registerTranslations, useNamespaceTranslation } from '@trackunit/i18n-library-translation';
|
|
3
|
-
import { useLocale as useLocale$1, useDateAndTime } from '@trackunit/react-date-and-time-hooks';
|
|
4
3
|
import { toDateUtil, formatDateUtil, isEqualUtil, timeSinceAuto } from '@trackunit/date-and-time-utils';
|
|
4
|
+
import { useLocale as useLocale$1, useDateAndTime } from '@trackunit/react-date-and-time-hooks';
|
|
5
5
|
import { color } from '@trackunit/ui-design-tokens';
|
|
6
6
|
import { useMemo, useCallback, useState, useEffect } from 'react';
|
|
7
7
|
import { Tooltip, IconButton, Icon, Button, Popover, PopoverTrigger, PopoverContent, Card } from '@trackunit/react-components';
|
|
@@ -86,18 +86,18 @@ const MS_PER_HOUR = 60 * 60 * 1000;
|
|
|
86
86
|
*/
|
|
87
87
|
const DateTime = ({ value, format, className, fromNow, withTitle, titleFormat, timezone, subtle, calendar, }) => {
|
|
88
88
|
const { t } = useTranslation();
|
|
89
|
-
const
|
|
89
|
+
const locale = useLocale$1();
|
|
90
90
|
const nowDate = useMemo(() => new Date(), []);
|
|
91
91
|
const date = value ? toDateUtil(value) : nowDate;
|
|
92
|
-
const newDateTime = formatDateUtil(date, format, timezone === null || timezone === void 0 ? void 0 : timezone.id,
|
|
93
|
-
const titleDateTime = withTitle ? formatDateUtil(date, titleFormat, timezone === null || timezone === void 0 ? void 0 : timezone.id,
|
|
92
|
+
const newDateTime = formatDateUtil(date, format, timezone === null || timezone === void 0 ? void 0 : timezone.id, locale);
|
|
93
|
+
const titleDateTime = withTitle ? formatDateUtil(date, titleFormat, timezone === null || timezone === void 0 ? void 0 : timezone.id, locale) : undefined;
|
|
94
94
|
const getTimeSince = useCallback((from, to) => {
|
|
95
95
|
const same = isEqualUtil(from, to);
|
|
96
96
|
if (same) {
|
|
97
97
|
return t("dateTime.instant.now");
|
|
98
98
|
}
|
|
99
|
-
return timeSinceAuto(from, to, timezone === null || timezone === void 0 ? void 0 : timezone.id,
|
|
100
|
-
}, [
|
|
99
|
+
return timeSinceAuto(from, to, timezone === null || timezone === void 0 ? void 0 : timezone.id, locale);
|
|
100
|
+
}, [locale, t, timezone === null || timezone === void 0 ? void 0 : timezone.id]);
|
|
101
101
|
const dateValue = useMemo(() => {
|
|
102
102
|
return fromNow ? getTimeSince(date, nowDate) : newDateTime;
|
|
103
103
|
}, [date, fromNow, getTimeSince, newDateTime, nowDate]);
|