@synerise/ds-core 1.9.1 → 1.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,12 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [1.10.0](https://github.com/synerise/synerise-design/compare/@synerise/ds-core@1.9.1...@synerise/ds-core@1.10.0) (2026-01-19)
7
+
8
+ ### Features
9
+
10
+ - **core:** refresh relative date ([23d74a6](https://github.com/synerise/synerise-design/commit/23d74a6855e082a6895d8799b61fa8b78fb27ae1))
11
+
6
12
  ## [1.9.1](https://github.com/synerise/synerise-design/compare/@synerise/ds-core@1.9.0...@synerise/ds-core@1.9.1) (2026-01-07)
7
13
 
8
14
  ### Bug Fixes
@@ -1,11 +1,12 @@
1
1
  function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
2
2
  import React from 'react';
3
3
  import { RELATIVE_FROM, RELATIVE_FROM_WITHOUT_SUFFIX, RELATIVE_TO, RELATIVE_TO_WITHOUT_SUFFIX } from '../constants';
4
- import { useDataFormat } from '../hooks';
4
+ import { useDataFormat, useRelativeDateTimeUpdate } from '../hooks';
5
5
  export var FormattedRelativeDateTimeTo = function FormattedRelativeDateTimeTo(_ref) {
6
6
  var value = _ref.value,
7
7
  withoutSuffix = _ref.withoutSuffix,
8
8
  options = _ref.options;
9
+ useRelativeDateTimeUpdate(value);
9
10
  var _useDataFormat = useDataFormat(),
10
11
  formatValue = _useDataFormat.formatValue;
11
12
  return /*#__PURE__*/React.createElement(React.Fragment, null, formatValue(value, _extends({}, options, {
@@ -16,6 +17,7 @@ export var FormattedRelativeDateTimeFrom = function FormattedRelativeDateTimeFro
16
17
  var value = _ref2.value,
17
18
  withoutSuffix = _ref2.withoutSuffix,
18
19
  options = _ref2.options;
20
+ useRelativeDateTimeUpdate(value);
19
21
  var _useDataFormat2 = useDataFormat(),
20
22
  formatValue = _useDataFormat2.formatValue;
21
23
  return /*#__PURE__*/React.createElement(React.Fragment, null, formatValue(value, _extends({}, options, {
@@ -3,3 +3,4 @@ export { useDataFormat, type UseDataFormatProps } from './useDataFormat';
3
3
  export { useDataFormatUtils } from './useDataFormatUtils';
4
4
  export { useSingleIntl } from './useSingleIntl';
5
5
  export { useDataFormatIntls } from './useDataFormatIntls';
6
+ export { useRelativeDateTimeUpdate } from './useRelativeDateTimeUpdate';
@@ -2,4 +2,5 @@ export { useDataFormatConfig } from './useDataFormatConfig';
2
2
  export { useDataFormat } from './useDataFormat';
3
3
  export { useDataFormatUtils } from './useDataFormatUtils';
4
4
  export { useSingleIntl } from './useSingleIntl';
5
- export { useDataFormatIntls } from './useDataFormatIntls';
5
+ export { useDataFormatIntls } from './useDataFormatIntls';
6
+ export { useRelativeDateTimeUpdate } from './useRelativeDateTimeUpdate';
@@ -0,0 +1,3 @@
1
+ import { type Dayjs } from 'dayjs';
2
+ import { type Moment } from 'moment';
3
+ export declare const useRelativeDateTimeUpdate: (value: Date | Moment | Dayjs) => number;
@@ -0,0 +1,37 @@
1
+ import { useEffect, useState } from 'react';
2
+ var getIntervalForTimeDifference = function getIntervalForTimeDifference(timeDiffMs) {
3
+ // https://day.js.org/docs/en/display/from-now#list-of-breakdown-range
4
+ var UNDER_45_MINUTES = 45 * 60 * 1000;
5
+ var UNDER_22_HOURS = 22 * 60 * 60 * 1000;
6
+ if (timeDiffMs < UNDER_45_MINUTES) {
7
+ return 60 * 1000; // 60 seconds
8
+ }
9
+ if (timeDiffMs < UNDER_22_HOURS) {
10
+ return 60 * 60 * 1000; // 60 minutes
11
+ }
12
+ return null; // no interval
13
+ };
14
+ export var useRelativeDateTimeUpdate = function useRelativeDateTimeUpdate(value) {
15
+ var _useState = useState(0),
16
+ updateTrigger = _useState[0],
17
+ setUpdateTrigger = _useState[1];
18
+ useEffect(function () {
19
+ if (!(value instanceof Date)) {
20
+ return;
21
+ }
22
+ var timeDiffMs = Math.abs(value.getTime() - Date.now());
23
+ var interval = getIntervalForTimeDifference(timeDiffMs);
24
+ if (interval === null) {
25
+ return;
26
+ }
27
+ var timeoutId = setTimeout(function () {
28
+ setUpdateTrigger(function (prev) {
29
+ return prev + 1;
30
+ });
31
+ }, interval);
32
+ return function () {
33
+ return clearTimeout(timeoutId);
34
+ };
35
+ }, [value, updateTrigger]);
36
+ return updateTrigger;
37
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@synerise/ds-core",
3
- "version": "1.9.1",
3
+ "version": "1.10.0",
4
4
  "description": "Core Components for the Synerise Design System",
5
5
  "license": "ISC",
6
6
  "repository": "synerise/synerise-design",
@@ -57,5 +57,5 @@
57
57
  "hex-rgb": "^5.0.0",
58
58
  "less-vars-to-js": "^1.3.0"
59
59
  },
60
- "gitHead": "f38e4b2dca1d43c39af0b189c93808de62c11e9b"
60
+ "gitHead": "451fc5f79af6c42be89179a11374a78bdec1110f"
61
61
  }