@synerise/ds-core 1.5.0 → 1.5.2
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 +19 -0
- package/README.md +181 -0
- package/dist/i18n/es.json +350 -24
- package/dist/i18n/index.d.ts +425 -23
- package/dist/i18n/pt.json +87 -11
- package/dist/js/DSProvider/DSProvider.d.ts +2 -2
- package/dist/js/DSProvider/DSProvider.js +2 -2
- package/dist/js/DSProvider/LocaleProvider/LocaleProvider.utils.d.ts +740 -0
- package/dist/js/DSProvider/ThemeProvider/breakpoints.d.ts +5 -1
- package/dist/js/data-format/components/FormattedDate.d.ts +9 -0
- package/dist/js/data-format/components/FormattedDate.js +9 -0
- package/dist/js/data-format/components/FormattedDateTime.d.ts +9 -0
- package/dist/js/data-format/components/FormattedDateTime.js +13 -0
- package/dist/js/data-format/components/FormattedNumber.d.ts +7 -0
- package/dist/js/data-format/components/FormattedNumber.js +9 -0
- package/dist/js/data-format/components/FormattedRelativeDateTime.d.ts +10 -0
- package/dist/js/data-format/components/FormattedRelativeDateTime.js +24 -0
- package/dist/js/data-format/components/FormattedTime.d.ts +9 -0
- package/dist/js/data-format/components/FormattedTime.js +13 -0
- package/dist/js/data-format/components/index.d.ts +5 -0
- package/dist/js/data-format/components/index.js +5 -0
- package/dist/js/data-format/constants/dataFormat.constants.d.ts +36 -0
- package/dist/js/data-format/constants/dataFormat.constants.js +52 -0
- package/dist/js/data-format/constants/dataFormatConfig.constants.d.ts +7 -0
- package/dist/js/data-format/constants/dataFormatConfig.constants.js +14 -0
- package/dist/js/data-format/constants/dateTimeParts.constants.d.ts +5 -0
- package/dist/js/data-format/constants/dateTimeParts.constants.js +4 -0
- package/dist/js/data-format/constants/index.d.ts +3 -0
- package/dist/js/data-format/constants/index.js +3 -0
- package/dist/js/data-format/contexts/DataFormatConfigContext.d.ts +2 -0
- package/dist/js/data-format/contexts/DataFormatConfigContext.js +3 -0
- package/dist/js/data-format/contexts/DataFormatIntlsContext.d.ts +2 -0
- package/dist/js/data-format/contexts/DataFormatIntlsContext.js +7 -0
- package/dist/js/data-format/contexts/index.d.ts +2 -0
- package/dist/js/data-format/contexts/index.js +2 -0
- package/dist/js/data-format/hocs/withDataFormat.d.ts +4 -0
- package/dist/js/data-format/hocs/withDataFormat.js +10 -0
- package/dist/js/data-format/hooks/index.d.ts +5 -0
- package/dist/js/data-format/hooks/index.js +5 -0
- package/dist/js/data-format/hooks/useDataFormat.d.ts +12 -0
- package/dist/js/data-format/hooks/useDataFormat.js +96 -0
- package/dist/js/data-format/hooks/useDataFormatConfig.d.ts +2 -0
- package/dist/js/data-format/hooks/useDataFormatConfig.js +5 -0
- package/dist/js/data-format/hooks/useDataFormatIntls.d.ts +2 -0
- package/dist/js/data-format/hooks/useDataFormatIntls.js +5 -0
- package/dist/js/data-format/hooks/useDataFormatUtils.d.ts +16 -0
- package/dist/js/data-format/hooks/useDataFormatUtils.js +113 -0
- package/dist/js/data-format/hooks/useSingleIntl.d.ts +4 -0
- package/dist/js/data-format/hooks/useSingleIntl.js +12 -0
- package/dist/js/data-format/index.d.ts +8 -0
- package/dist/js/data-format/index.js +7 -0
- package/dist/js/data-format/providers/DataFormatConfigProvider.d.ts +7 -0
- package/dist/js/data-format/providers/DataFormatConfigProvider.js +26 -0
- package/dist/js/data-format/types/dataFormat.types.d.ts +42 -0
- package/dist/js/data-format/types/dataFormat.types.js +5 -0
- package/dist/js/data-format/types/dataFormatConfig.types.d.ts +16 -0
- package/dist/js/data-format/types/dataFormatConfig.types.js +2 -0
- package/dist/js/data-format/types/dateTimeParts.types.d.ts +3 -0
- package/dist/js/data-format/types/dateTimeParts.types.js +2 -0
- package/dist/js/data-format/types/index.d.ts +3 -0
- package/dist/js/data-format/types/index.js +1 -0
- package/dist/js/data-format/utils/dataFormat.utils.d.ts +16 -0
- package/dist/js/data-format/utils/dataFormat.utils.js +119 -0
- package/dist/js/data-format/utils/dataFormatConfig.utils.d.ts +2 -0
- package/dist/js/data-format/utils/dataFormatConfig.utils.js +8 -0
- package/dist/js/data-format/utils/date.utils.d.ts +8 -0
- package/dist/js/data-format/utils/date.utils.js +50 -0
- package/dist/js/data-format/utils/dateTimeParts.utils.d.ts +14 -0
- package/dist/js/data-format/utils/dateTimeParts.utils.js +86 -0
- package/dist/js/data-format/utils/index.d.ts +5 -0
- package/dist/js/data-format/utils/index.js +5 -0
- package/dist/js/data-format/utils/timeZone.utils.d.ts +16 -0
- package/dist/js/data-format/utils/timeZone.utils.js +94 -0
- package/dist/js/index.d.ts +3 -0
- package/dist/js/index.js +4 -1
- package/dist/js/mediaQuery/mediaQuery.d.ts +1 -5
- package/dist/js/testing/index.d.ts +2 -0
- package/dist/js/testing/index.js +2 -0
- package/dist/js/testing/renderWithProvider/renderWithProvider.d.ts +10 -0
- package/dist/js/testing/renderWithProvider/renderWithProvider.js +28 -0
- package/dist/js/testing/renderWithProvider/renderWithProvider.spec.d.ts +1 -0
- package/dist/js/testing/sleep.d.ts +1 -0
- package/dist/js/testing/sleep.js +8 -0
- package/dist/js/toaster/Toaster.d.ts +2 -0
- package/dist/js/toaster/Toaster.js +8 -0
- package/dist/js/toaster/Toaster.types.d.ts +1 -0
- package/dist/js/toaster/Toaster.types.js +1 -0
- package/dist/js/toaster/constants.d.ts +2 -0
- package/dist/js/toaster/constants.js +8 -0
- package/dist/js/toaster/contexts/ToasterContext.d.ts +6 -0
- package/dist/js/toaster/contexts/ToasterContext.js +6 -0
- package/dist/js/toaster/hooks/useToaster.d.ts +1 -0
- package/dist/js/toaster/hooks/useToaster.js +5 -0
- package/dist/js/toaster/index.d.ts +6 -0
- package/dist/js/toaster/index.js +5 -0
- package/dist/js/toaster/providers/ToasterProvider.d.ts +6 -0
- package/dist/js/toaster/providers/ToasterProvider.js +17 -0
- package/package.json +14 -7
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { createIntl, createIntlCache, useIntl } from 'react-intl';
|
|
2
|
+
export var useSingleIntl = function useSingleIntl(locale) {
|
|
3
|
+
var cache = createIntlCache();
|
|
4
|
+
var globalIntl = useIntl();
|
|
5
|
+
var intl = createIntl({
|
|
6
|
+
locale: locale,
|
|
7
|
+
timeZone: globalIntl.timeZone
|
|
8
|
+
}, cache);
|
|
9
|
+
return {
|
|
10
|
+
intl: intl
|
|
11
|
+
};
|
|
12
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { DataFormatConfigProvider, type DataFormatConfigProviderProps, } from './providers/DataFormatConfigProvider';
|
|
2
|
+
export { FormattedDate, FormattedDateTime, FormattedNumber, FormattedTime, FormattedRelativeDateTimeFrom, FormattedRelativeDateTimeTo, } from './components';
|
|
3
|
+
export { useDataFormat, useDataFormatUtils, useDataFormatConfig, useDataFormatIntls, type UseDataFormatProps, } from './hooks';
|
|
4
|
+
export { withDataFormat, type WithDataFormatProps, } from './hocs/withDataFormat';
|
|
5
|
+
export { getDataFormatConfigFromNotation, getDefaultDataTimeOptions, } from './utils';
|
|
6
|
+
export * from './constants';
|
|
7
|
+
export { DataFormatConfigContext, DataFormatIntlsContext } from './contexts';
|
|
8
|
+
export type { DataFormatNotationType, NumberToFormatOptions, DateToFormatOptions, DataFormatConfig, Delimiter, DateTargetFormat, NumberTargetFormat, NamingConvention, DateToFormat, OverloadFormatValue, OverloadFormatMultipleValues, CommonFormatOptions, DateConstantsTargetFormat, OverloadGetConstants, DateTimePartFormat, DataFormatIntls, } from './types';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { DataFormatConfigProvider } from './providers/DataFormatConfigProvider';
|
|
2
|
+
export { FormattedDate, FormattedDateTime, FormattedNumber, FormattedTime, FormattedRelativeDateTimeFrom, FormattedRelativeDateTimeTo } from './components';
|
|
3
|
+
export { useDataFormat, useDataFormatUtils, useDataFormatConfig, useDataFormatIntls } from './hooks';
|
|
4
|
+
export { withDataFormat } from './hocs/withDataFormat';
|
|
5
|
+
export { getDataFormatConfigFromNotation, getDefaultDataTimeOptions } from './utils';
|
|
6
|
+
export * from './constants';
|
|
7
|
+
export { DataFormatConfigContext, DataFormatIntlsContext } from './contexts';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import React, { type ReactNode } from 'react';
|
|
2
|
+
import { type DataFormatConfig } from '../types';
|
|
3
|
+
export type DataFormatConfigProviderProps = {
|
|
4
|
+
dataFormatConfig?: DataFormatConfig;
|
|
5
|
+
children?: ReactNode;
|
|
6
|
+
};
|
|
7
|
+
export declare const DataFormatConfigProvider: ({ dataFormatConfig: dataFormatConfigFromProps, children, }: DataFormatConfigProviderProps) => React.JSX.Element;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { DEFAULT_DATA_FORMAT_CONFIG } from '../constants';
|
|
3
|
+
import { DataFormatConfigContext, DataFormatIntlsContext } from '../contexts';
|
|
4
|
+
import { useDataFormatUtils, useSingleIntl } from '../hooks';
|
|
5
|
+
export var DataFormatConfigProvider = function DataFormatConfigProvider(_ref) {
|
|
6
|
+
var dataFormatConfigFromProps = _ref.dataFormatConfig,
|
|
7
|
+
children = _ref.children;
|
|
8
|
+
var dataFormatConfig = dataFormatConfigFromProps != null ? dataFormatConfigFromProps : DEFAULT_DATA_FORMAT_CONFIG;
|
|
9
|
+
var _useDataFormatUtils = useDataFormatUtils(),
|
|
10
|
+
getLocaleFromNotation = _useDataFormatUtils.getLocaleFromNotation;
|
|
11
|
+
var _useSingleIntl = useSingleIntl(getLocaleFromNotation(dataFormatConfig == null ? void 0 : dataFormatConfig.numberFormatNotation)),
|
|
12
|
+
numberFormatIntl = _useSingleIntl.intl;
|
|
13
|
+
var _useSingleIntl2 = useSingleIntl(getLocaleFromNotation(dataFormatConfig == null ? void 0 : dataFormatConfig.dateFormatNotation)),
|
|
14
|
+
dateFormatIntl = _useSingleIntl2.intl;
|
|
15
|
+
var _useSingleIntl3 = useSingleIntl(getLocaleFromNotation(dataFormatConfig == null ? void 0 : dataFormatConfig.timeFormatNotation)),
|
|
16
|
+
timeFormatIntl = _useSingleIntl3.intl;
|
|
17
|
+
return /*#__PURE__*/React.createElement(DataFormatIntlsContext.Provider, {
|
|
18
|
+
value: {
|
|
19
|
+
numberFormatIntl: numberFormatIntl,
|
|
20
|
+
dateFormatIntl: dateFormatIntl,
|
|
21
|
+
timeFormatIntl: timeFormatIntl
|
|
22
|
+
}
|
|
23
|
+
}, /*#__PURE__*/React.createElement(DataFormatConfigContext.Provider, {
|
|
24
|
+
value: dataFormatConfig
|
|
25
|
+
}, children));
|
|
26
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { type Dayjs, type default as dayjs } from 'dayjs';
|
|
2
|
+
import { type Moment } from 'moment';
|
|
3
|
+
import { type FormatDateOptions, type FormatNumberOptions, type FormatPluralOptions } from 'react-intl';
|
|
4
|
+
declare const _DATE_TARGET_FORMATS: readonly ["date", "datetime", "relative-from", "relative-to", "relative-from-without-suffix", "relative-to-without-suffix", "time", "weekday-long", "weekday-short", "month-long", "month-short"];
|
|
5
|
+
export type DateTargetFormat = (typeof _DATE_TARGET_FORMATS)[number];
|
|
6
|
+
declare const _NUMBER_TARGET_FORMATS: readonly ["compact-larger-number", "compact-decimal-larger-number"];
|
|
7
|
+
export type NumberTargetFormat = (typeof _NUMBER_TARGET_FORMATS)[number];
|
|
8
|
+
declare const _NAMING_CONVENTIONS: readonly ["upperCase", "upperFirst", "lowerCase", "lowerFirst"];
|
|
9
|
+
export type NamingConvention = (typeof _NAMING_CONVENTIONS)[number];
|
|
10
|
+
export type DateConstantsTargetFormat = 'months-long' | 'months-short' | 'weekdays-long' | 'weekdays-short';
|
|
11
|
+
export type DateToFormat = Date | Moment | Dayjs;
|
|
12
|
+
export type CommonFormatOptions = {
|
|
13
|
+
prefix?: string;
|
|
14
|
+
suffix?: string;
|
|
15
|
+
namingConvention?: NamingConvention;
|
|
16
|
+
};
|
|
17
|
+
export type NumberToFormatOptions = FormatNumberOptions & CommonFormatOptions & {
|
|
18
|
+
pluralOptions?: FormatPluralOptions;
|
|
19
|
+
targetFormat?: NumberTargetFormat;
|
|
20
|
+
};
|
|
21
|
+
export type DateToFormatOptions = FormatDateOptions & CommonFormatOptions & {
|
|
22
|
+
dateOptions?: FormatDateOptions;
|
|
23
|
+
timeOptions?: FormatDateOptions;
|
|
24
|
+
targetFormat?: DateTargetFormat;
|
|
25
|
+
applyTimeZoneOffset?: boolean;
|
|
26
|
+
};
|
|
27
|
+
export type OverloadFormatValue = {
|
|
28
|
+
(value: number, options?: NumberToFormatOptions): string;
|
|
29
|
+
(value: Date | Moment | Dayjs, options?: DateToFormatOptions): string;
|
|
30
|
+
(value: string, options?: CommonFormatOptions): string;
|
|
31
|
+
};
|
|
32
|
+
export type OverloadFormatMultipleValues = {
|
|
33
|
+
(values: number[], options?: NumberToFormatOptions): string[];
|
|
34
|
+
(values: Date[] | Moment[] | Dayjs[], options?: DateToFormatOptions): string[];
|
|
35
|
+
(values: string[], options?: CommonFormatOptions): string[];
|
|
36
|
+
};
|
|
37
|
+
export type OverloadGetConstants = {
|
|
38
|
+
(targetFormat: DateConstantsTargetFormat, options?: DateToFormatOptions, customStartDate?: Date, customEndDate?: Date, customInterval?: dayjs.UnitType): string[] | undefined;
|
|
39
|
+
};
|
|
40
|
+
declare const _DELIMITERS: readonly [",", ".", " "];
|
|
41
|
+
export type Delimiter = (typeof _DELIMITERS)[number];
|
|
42
|
+
export {};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
var _DATE_TARGET_FORMATS = ['date', 'datetime', 'relative-from', 'relative-to', 'relative-from-without-suffix', 'relative-to-without-suffix', 'time', 'weekday-long', 'weekday-short', 'month-long', 'month-short'];
|
|
2
|
+
var _NUMBER_TARGET_FORMATS = ['compact-larger-number', 'compact-decimal-larger-number'];
|
|
3
|
+
var _NAMING_CONVENTIONS = ['upperCase', 'upperFirst', 'lowerCase', 'lowerFirst'];
|
|
4
|
+
var _DELIMITERS = [',', '.', ' '];
|
|
5
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type IntlShape } from 'react-intl';
|
|
2
|
+
declare const _DATA_FORMAT_NOTATION_TYPES: readonly ["US", "EU"];
|
|
3
|
+
export type DataFormatNotationType = (typeof _DATA_FORMAT_NOTATION_TYPES)[number];
|
|
4
|
+
export type DataFormatConfig = {
|
|
5
|
+
startWeekDayNotation?: DataFormatNotationType;
|
|
6
|
+
dateFormatNotation?: DataFormatNotationType;
|
|
7
|
+
timeFormatNotation?: DataFormatNotationType;
|
|
8
|
+
numberFormatNotation?: DataFormatNotationType;
|
|
9
|
+
applyTimeZoneOffset?: boolean;
|
|
10
|
+
};
|
|
11
|
+
export type DataFormatIntls = {
|
|
12
|
+
numberFormatIntl: IntlShape;
|
|
13
|
+
dateFormatIntl: IntlShape;
|
|
14
|
+
timeFormatIntl: IntlShape;
|
|
15
|
+
};
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export type { NumberToFormatOptions, DateToFormatOptions, CommonFormatOptions, DateTargetFormat, NumberTargetFormat, NamingConvention, DateToFormat, OverloadFormatValue, OverloadFormatMultipleValues, OverloadGetConstants, Delimiter, DateConstantsTargetFormat, } from './dataFormat.types';
|
|
2
|
+
export type { DataFormatNotationType, DataFormatConfig, DataFormatIntls, } from './dataFormatConfig.types';
|
|
3
|
+
export type { DateTimePartFormat } from './dateTimeParts.types';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type IntlShape } from 'react-intl';
|
|
2
|
+
import { type CommonFormatOptions, type DateToFormatOptions, type Delimiter, type NumberToFormatOptions } from '../types';
|
|
3
|
+
export declare const convertNumberString: (value: number, numberFormatIntl: IntlShape, languageIntl: IntlShape, thousandDelimiter: Delimiter, decimalDelimiter: Delimiter, numberOptions?: NumberToFormatOptions) => string;
|
|
4
|
+
export declare const convertDateToDateTimeString: (value: Date, dateFormatIntl: IntlShape, timeFormatIntl: IntlShape, languageIntl: IntlShape, options?: DateToFormatOptions) => string;
|
|
5
|
+
export declare const convertDateToRelativeToString: (value: Date, withoutSuffix?: boolean) => string;
|
|
6
|
+
export declare const convertDateToRelativeFromString: (value: Date, withoutSuffix?: boolean) => string;
|
|
7
|
+
export declare const convertDateToTimeString: (value: Date, timeFormatIntl: IntlShape, options?: DateToFormatOptions) => string;
|
|
8
|
+
export declare const convertDateToDateString: (value: Date, dateFormatIntl: IntlShape, languageIntl: IntlShape, options?: DateToFormatOptions) => string;
|
|
9
|
+
export declare const convertDateToWeekdayLongString: (value: Date, dateFormatIntl: IntlShape, languageIntl: IntlShape, options?: DateToFormatOptions) => string;
|
|
10
|
+
export declare const convertDateToWeekdayShortString: (value: Date, dateFormatIntl: IntlShape, languageIntl: IntlShape, options?: DateToFormatOptions) => string;
|
|
11
|
+
export declare const convertDateToMonthLongString: (value: Date, dateFormatIntl: IntlShape, languageIntl: IntlShape, options?: DateToFormatOptions) => string;
|
|
12
|
+
export declare const convertDateToMonthShortString: (value: Date, dateFormatIntl: IntlShape, languageIntl: IntlShape, options?: DateToFormatOptions) => string;
|
|
13
|
+
export declare const addPrefix: (value: string, options?: CommonFormatOptions) => string;
|
|
14
|
+
export declare const addSuffix: (value: string, options?: CommonFormatOptions) => string;
|
|
15
|
+
export declare const changeNamingConvention: (value: string, options?: CommonFormatOptions) => string;
|
|
16
|
+
export declare const getDefaultDataTimeOptions: (showTime?: boolean) => DateToFormatOptions;
|
|
@@ -0,0 +1,119 @@
|
|
|
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
|
+
import dayjs from 'dayjs';
|
|
3
|
+
import relativeTimePlugin from 'dayjs/plugin/relativeTime';
|
|
4
|
+
import { COMPACT_DECIMAL_LARGER_NUMBER, COMPACT_LARGER_NUMBER, DATE, DATETIME, DEFAULT_FORMAT_MONTH_SHORT_OPTIONS, DEFAULT_FORMAT_NUMBER_OPTIONS, LARGER_NUMBER_LIMIT, LOWER_CASE, LOWER_FIRST, UPPER_CASE, UPPER_FIRST } from '../constants';
|
|
5
|
+
import { dateTimePartsToString, getDateParts, getDateTimePartsSubset, getMonthLongDateParts, getMonthShortDateParts, getTimeParts, getWeekdayLongDateParts, getWeekdayShortDateParts, numberPartsToString, translateDateTimeParts } from './dateTimeParts.utils';
|
|
6
|
+
dayjs.extend(relativeTimePlugin);
|
|
7
|
+
export var convertNumberString = function convertNumberString(value, numberFormatIntl, languageIntl, thousandDelimiter, decimalDelimiter, numberOptions) {
|
|
8
|
+
var updatedNumberOptions = numberOptions;
|
|
9
|
+
if (updatedNumberOptions != null && updatedNumberOptions.pluralOptions) {
|
|
10
|
+
return numberFormatIntl.formatPlural(value, updatedNumberOptions);
|
|
11
|
+
}
|
|
12
|
+
if ((updatedNumberOptions == null ? void 0 : updatedNumberOptions.targetFormat) === COMPACT_LARGER_NUMBER && value > LARGER_NUMBER_LIMIT) {
|
|
13
|
+
if (!updatedNumberOptions.notation) {
|
|
14
|
+
updatedNumberOptions.notation = 'compact';
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
if ((updatedNumberOptions == null ? void 0 : updatedNumberOptions.targetFormat) === COMPACT_DECIMAL_LARGER_NUMBER && value > LARGER_NUMBER_LIMIT) {
|
|
18
|
+
if (!updatedNumberOptions.notation) {
|
|
19
|
+
updatedNumberOptions.notation = 'compact';
|
|
20
|
+
}
|
|
21
|
+
if (!updatedNumberOptions.minimumFractionDigits && updatedNumberOptions.minimumFractionDigits !== 0) {
|
|
22
|
+
updatedNumberOptions.minimumFractionDigits = 1;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
var numberParts = languageIntl.formatNumberToParts(value, _extends({}, DEFAULT_FORMAT_NUMBER_OPTIONS, updatedNumberOptions));
|
|
26
|
+
return numberPartsToString(numberParts, thousandDelimiter, decimalDelimiter);
|
|
27
|
+
};
|
|
28
|
+
export var convertDateToDateTimeString = function convertDateToDateTimeString(value, dateFormatIntl, timeFormatIntl, languageIntl, options) {
|
|
29
|
+
var dateParts = getDateParts(value, dateFormatIntl, options == null ? void 0 : options.dateOptions);
|
|
30
|
+
var datePartsByLanguageIntl = getDateParts(value, languageIntl, options == null ? void 0 : options.dateOptions);
|
|
31
|
+
var translatedDateParts = translateDateTimeParts(dateParts, datePartsByLanguageIntl, options);
|
|
32
|
+
var date = dateTimePartsToString(translatedDateParts);
|
|
33
|
+
var time = dateTimePartsToString(getTimeParts(value, timeFormatIntl, options == null ? void 0 : options.timeOptions));
|
|
34
|
+
return date + ", " + time;
|
|
35
|
+
};
|
|
36
|
+
export var convertDateToRelativeToString = function convertDateToRelativeToString(value, withoutSuffix) {
|
|
37
|
+
return dayjs().to(dayjs(value), withoutSuffix);
|
|
38
|
+
};
|
|
39
|
+
export var convertDateToRelativeFromString = function convertDateToRelativeFromString(value, withoutSuffix) {
|
|
40
|
+
return dayjs().from(dayjs(value), withoutSuffix);
|
|
41
|
+
};
|
|
42
|
+
export var convertDateToTimeString = function convertDateToTimeString(value, timeFormatIntl, options) {
|
|
43
|
+
return dateTimePartsToString(getTimeParts(value, timeFormatIntl, options));
|
|
44
|
+
};
|
|
45
|
+
export var convertDateToDateString = function convertDateToDateString(value, dateFormatIntl, languageIntl, options) {
|
|
46
|
+
var dateParts = getDateParts(value, dateFormatIntl, options);
|
|
47
|
+
var datePartsByLanguageIntl = getDateParts(value, languageIntl, options);
|
|
48
|
+
var translatedDateParts = translateDateTimeParts(dateParts, datePartsByLanguageIntl, options);
|
|
49
|
+
return dateTimePartsToString(translatedDateParts);
|
|
50
|
+
};
|
|
51
|
+
export var convertDateToWeekdayLongString = function convertDateToWeekdayLongString(value, dateFormatIntl, languageIntl, options) {
|
|
52
|
+
var weekdayLongDateParts = getWeekdayLongDateParts(value, dateFormatIntl, options);
|
|
53
|
+
var weekdayLongDatePartsByLanguageIntl = getWeekdayLongDateParts(value, languageIntl, options);
|
|
54
|
+
var translatedDateTimeParts = translateDateTimeParts(weekdayLongDateParts, weekdayLongDatePartsByLanguageIntl, options);
|
|
55
|
+
var reducedDateTimeParts = getDateTimePartsSubset(translatedDateTimeParts, ['weekday']);
|
|
56
|
+
return dateTimePartsToString(reducedDateTimeParts);
|
|
57
|
+
};
|
|
58
|
+
export var convertDateToWeekdayShortString = function convertDateToWeekdayShortString(value, dateFormatIntl, languageIntl, options) {
|
|
59
|
+
var weekdayShortDateParts = getWeekdayShortDateParts(value, dateFormatIntl, options);
|
|
60
|
+
var weekdayShortDatePartsByLanguageIntl = getWeekdayShortDateParts(value, languageIntl, options);
|
|
61
|
+
var translatedDateTimeParts = translateDateTimeParts(weekdayShortDateParts, weekdayShortDatePartsByLanguageIntl, options);
|
|
62
|
+
var reducedDateTimeParts = getDateTimePartsSubset(translatedDateTimeParts, ['weekday']);
|
|
63
|
+
return dateTimePartsToString(reducedDateTimeParts);
|
|
64
|
+
};
|
|
65
|
+
export var convertDateToMonthLongString = function convertDateToMonthLongString(value, dateFormatIntl, languageIntl, options) {
|
|
66
|
+
var monthLongDateParts = getMonthLongDateParts(value, dateFormatIntl, options);
|
|
67
|
+
var monthLongDatePartsByLanguageIntl = getMonthLongDateParts(value, languageIntl, options);
|
|
68
|
+
var translatedDateTimeParts = translateDateTimeParts(monthLongDateParts, monthLongDatePartsByLanguageIntl, options);
|
|
69
|
+
var reducedDateTimeParts = getDateTimePartsSubset(translatedDateTimeParts, ['month']);
|
|
70
|
+
return dateTimePartsToString(reducedDateTimeParts);
|
|
71
|
+
};
|
|
72
|
+
export var convertDateToMonthShortString = function convertDateToMonthShortString(value, dateFormatIntl, languageIntl, options) {
|
|
73
|
+
var monthShortDateParts = getMonthShortDateParts(value, dateFormatIntl, options);
|
|
74
|
+
var monthShortDatePartsByLanguageIntl = getMonthShortDateParts(value, languageIntl, options);
|
|
75
|
+
var translatedDateTimeParts = translateDateTimeParts(monthShortDateParts, monthShortDatePartsByLanguageIntl, options);
|
|
76
|
+
var reducedDateTimeParts = getDateTimePartsSubset(translatedDateTimeParts, ['month']);
|
|
77
|
+
return dateTimePartsToString(reducedDateTimeParts);
|
|
78
|
+
};
|
|
79
|
+
export var addPrefix = function addPrefix(value, options) {
|
|
80
|
+
var result = value;
|
|
81
|
+
if (options != null && options.prefix) {
|
|
82
|
+
result = (options == null ? void 0 : options.prefix) + result;
|
|
83
|
+
}
|
|
84
|
+
return result;
|
|
85
|
+
};
|
|
86
|
+
export var addSuffix = function addSuffix(value, options) {
|
|
87
|
+
var result = value;
|
|
88
|
+
if (options != null && options.suffix) {
|
|
89
|
+
result += options == null ? void 0 : options.suffix;
|
|
90
|
+
}
|
|
91
|
+
return result;
|
|
92
|
+
};
|
|
93
|
+
export var changeNamingConvention = function changeNamingConvention(value, options) {
|
|
94
|
+
var result = value;
|
|
95
|
+
switch (options == null ? void 0 : options.namingConvention) {
|
|
96
|
+
case UPPER_CASE:
|
|
97
|
+
result = result.toUpperCase();
|
|
98
|
+
break;
|
|
99
|
+
case UPPER_FIRST:
|
|
100
|
+
result = result.charAt(0).toUpperCase() + result.slice(1);
|
|
101
|
+
break;
|
|
102
|
+
case LOWER_CASE:
|
|
103
|
+
result = result.toLowerCase();
|
|
104
|
+
break;
|
|
105
|
+
case LOWER_FIRST:
|
|
106
|
+
result = result.charAt(0).toLowerCase() + result.slice(1);
|
|
107
|
+
break;
|
|
108
|
+
default:
|
|
109
|
+
break;
|
|
110
|
+
}
|
|
111
|
+
return result;
|
|
112
|
+
};
|
|
113
|
+
export var getDefaultDataTimeOptions = function getDefaultDataTimeOptions(showTime) {
|
|
114
|
+
return {
|
|
115
|
+
targetFormat: showTime ? DATETIME : DATE,
|
|
116
|
+
dateOptions: DEFAULT_FORMAT_MONTH_SHORT_OPTIONS,
|
|
117
|
+
namingConvention: UPPER_FIRST
|
|
118
|
+
};
|
|
119
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import dayjs from 'dayjs';
|
|
2
|
+
import { type DateConstantsTargetFormat, type DateToFormatOptions } from '../types';
|
|
3
|
+
export declare const getDatesRange: (start: Date, end: Date, interval: dayjs.UnitType) => Date[];
|
|
4
|
+
export declare const isValidDate: (date: Date) => boolean;
|
|
5
|
+
export declare const getConstantDatesAndFormattingOptions: (targetFormat: DateConstantsTargetFormat, isSundayFirstWeekDay: boolean, customStartDate?: Date, customEndDate?: Date, customInterval?: dayjs.UnitType) => {
|
|
6
|
+
constantDates: Date[];
|
|
7
|
+
defaultOptions: DateToFormatOptions;
|
|
8
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import dayjs from 'dayjs';
|
|
2
|
+
import { MONTHS_LONG, MONTHS_SHORT, MONTH_LONG, MONTH_SHORT, UPPER_FIRST, WEEKDAYS_LONG, WEEKDAYS_SHORT, WEEKDAY_LONG, WEEKDAY_SHORT } from '../constants';
|
|
3
|
+
export var getDatesRange = function getDatesRange(start, end, interval) {
|
|
4
|
+
var startDate = dayjs(start);
|
|
5
|
+
var endDate = dayjs(end);
|
|
6
|
+
var diffInUnits = endDate.diff(startDate, interval);
|
|
7
|
+
return Array.from(Array(diffInUnits + 1).keys()).map(function (i) {
|
|
8
|
+
return startDate.add(i, interval).toDate();
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
export var isValidDate = function isValidDate(date) {
|
|
12
|
+
return !isNaN(date.getTime());
|
|
13
|
+
};
|
|
14
|
+
export var getConstantDatesAndFormattingOptions = function getConstantDatesAndFormattingOptions(targetFormat, isSundayFirstWeekDay, customStartDate, customEndDate, customInterval) {
|
|
15
|
+
var startDate = new Date(2023, 0, isSundayFirstWeekDay ? 1 : 2);
|
|
16
|
+
var endDate = new Date(2023, 0, isSundayFirstWeekDay ? 1 : 2);
|
|
17
|
+
var defaultTargetFormat = MONTH_LONG;
|
|
18
|
+
var interval = 'month';
|
|
19
|
+
switch (targetFormat) {
|
|
20
|
+
case MONTHS_LONG:
|
|
21
|
+
endDate.setMonth(11);
|
|
22
|
+
interval = 'month';
|
|
23
|
+
defaultTargetFormat = MONTH_LONG;
|
|
24
|
+
break;
|
|
25
|
+
case MONTHS_SHORT:
|
|
26
|
+
endDate.setMonth(11);
|
|
27
|
+
interval = 'month';
|
|
28
|
+
defaultTargetFormat = MONTH_SHORT;
|
|
29
|
+
break;
|
|
30
|
+
case WEEKDAYS_LONG:
|
|
31
|
+
endDate.setDate(isSundayFirstWeekDay ? 7 : 8);
|
|
32
|
+
interval = 'day';
|
|
33
|
+
defaultTargetFormat = WEEKDAY_LONG;
|
|
34
|
+
break;
|
|
35
|
+
case WEEKDAYS_SHORT:
|
|
36
|
+
endDate.setDate(isSundayFirstWeekDay ? 7 : 8);
|
|
37
|
+
interval = 'day';
|
|
38
|
+
defaultTargetFormat = WEEKDAY_SHORT;
|
|
39
|
+
break;
|
|
40
|
+
default:
|
|
41
|
+
break;
|
|
42
|
+
}
|
|
43
|
+
return {
|
|
44
|
+
constantDates: getDatesRange(customStartDate != null ? customStartDate : startDate, customEndDate != null ? customEndDate : endDate, customInterval != null ? customInterval : interval),
|
|
45
|
+
defaultOptions: {
|
|
46
|
+
namingConvention: UPPER_FIRST,
|
|
47
|
+
targetFormat: defaultTargetFormat
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type FormatDateOptions, type IntlShape } from 'react-intl';
|
|
2
|
+
import { type DateToFormatOptions, type Delimiter } from '../types';
|
|
3
|
+
export declare const getDateParts: (value: Date, dateFormatIntl: IntlShape, option?: FormatDateOptions) => Intl.DateTimeFormatPart[];
|
|
4
|
+
export declare const getTimeParts: (value: Date, timeFormatIntl: IntlShape, option?: FormatDateOptions) => Intl.DateTimeFormatPart[];
|
|
5
|
+
export declare const getWeekdayLongDateParts: (value: Date, dateFormatIntl: IntlShape, option?: FormatDateOptions) => Intl.DateTimeFormatPart[];
|
|
6
|
+
export declare const getWeekdayShortDateParts: (value: Date, dateFormatIntl: IntlShape, option?: FormatDateOptions) => Intl.DateTimeFormatPart[];
|
|
7
|
+
export declare const getMonthLongDateParts: (value: Date, dateFormatIntl: IntlShape, option?: FormatDateOptions) => Intl.DateTimeFormatPart[];
|
|
8
|
+
export declare const getMonthShortDateParts: (value: Date, dateFormatIntl: IntlShape, option?: FormatDateOptions) => Intl.DateTimeFormatPart[];
|
|
9
|
+
export declare const getDateTimePartsSubset: (dateTimeParts: Intl.DateTimeFormatPart[], subsetTypes: Intl.DateTimeFormatPartTypes[]) => Intl.DateTimeFormatPart[];
|
|
10
|
+
export declare const nbspToSpace: (text: string) => string;
|
|
11
|
+
export declare const numberPartsToString: (numberParts: Intl.NumberFormatPart[], thousandDelimiter: Delimiter, decimalDelimiter: Delimiter) => string;
|
|
12
|
+
export declare const dateTimePartsToString: (dateTimeParts: Intl.DateTimeFormatPart[]) => string;
|
|
13
|
+
export declare const replaceDateTimeParts: (dateTimeParts: Intl.DateTimeFormatPart[], replacementDateTimeParts: Intl.DateTimeFormatPart[], replacementDateTimeFormatPartTypes: Intl.DateTimeFormatPartTypes[]) => Intl.DateTimeFormatPart[];
|
|
14
|
+
export declare const translateDateTimeParts: (dateTimeParts: Intl.DateTimeFormatPart[], dateTimePartsFromLanguageIntl: Intl.DateTimeFormatPart[], options?: DateToFormatOptions) => Intl.DateTimeFormatPart[];
|
|
@@ -0,0 +1,86 @@
|
|
|
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
|
+
import { DEFAULT_FORMAT_DATE_OPTIONS, DEFAULT_FORMAT_MONTH_LONG_OPTIONS, DEFAULT_FORMAT_MONTH_SHORT_OPTIONS, DEFAULT_FORMAT_TIME_OPTIONS, DEFAULT_FORMAT_WEEKDAY_LONG_OPTIONS, DEFAULT_FORMAT_WEEKDAY_SHORT_OPTIONS, LONG, MONTH, MONTH_LONG, MONTH_SHORT, SHORT, WEEKDAY, WEEKDAY_LONG, WEEKDAY_SHORT } from '../constants';
|
|
3
|
+
import { dateToIsoWithOffset } from './timeZone.utils';
|
|
4
|
+
export var getDateParts = function getDateParts(value, dateFormatIntl, option) {
|
|
5
|
+
return dateFormatIntl.formatDateToParts(dateToIsoWithOffset(value, dateFormatIntl), _extends({}, DEFAULT_FORMAT_DATE_OPTIONS, option));
|
|
6
|
+
};
|
|
7
|
+
export var getTimeParts = function getTimeParts(value, timeFormatIntl, option) {
|
|
8
|
+
return timeFormatIntl.formatDateToParts(dateToIsoWithOffset(value, timeFormatIntl), _extends({}, DEFAULT_FORMAT_TIME_OPTIONS, option));
|
|
9
|
+
};
|
|
10
|
+
export var getWeekdayLongDateParts = function getWeekdayLongDateParts(value, dateFormatIntl, option) {
|
|
11
|
+
return dateFormatIntl.formatDateToParts(value, _extends({}, DEFAULT_FORMAT_WEEKDAY_LONG_OPTIONS, option));
|
|
12
|
+
};
|
|
13
|
+
export var getWeekdayShortDateParts = function getWeekdayShortDateParts(value, dateFormatIntl, option) {
|
|
14
|
+
return dateFormatIntl.formatDateToParts(value, _extends({}, DEFAULT_FORMAT_WEEKDAY_SHORT_OPTIONS, option));
|
|
15
|
+
};
|
|
16
|
+
export var getMonthLongDateParts = function getMonthLongDateParts(value, dateFormatIntl, option) {
|
|
17
|
+
return dateFormatIntl.formatDateToParts(value, _extends({}, DEFAULT_FORMAT_MONTH_LONG_OPTIONS, option));
|
|
18
|
+
};
|
|
19
|
+
export var getMonthShortDateParts = function getMonthShortDateParts(value, dateFormatIntl, option) {
|
|
20
|
+
return dateFormatIntl.formatDateToParts(value, _extends({}, DEFAULT_FORMAT_MONTH_SHORT_OPTIONS, option));
|
|
21
|
+
};
|
|
22
|
+
export var getDateTimePartsSubset = function getDateTimePartsSubset(dateTimeParts, subsetTypes) {
|
|
23
|
+
var resultDateTimeParts = [];
|
|
24
|
+
dateTimeParts.forEach(function (dateTimePart) {
|
|
25
|
+
if (subsetTypes.includes(dateTimePart.type)) {
|
|
26
|
+
resultDateTimeParts.push(dateTimePart);
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
return resultDateTimeParts;
|
|
30
|
+
};
|
|
31
|
+
export var nbspToSpace = function nbspToSpace(text) {
|
|
32
|
+
return text.replace(/ /g, ' ').replace(/\u00A0/g, ' ');
|
|
33
|
+
};
|
|
34
|
+
export var numberPartsToString = function numberPartsToString(numberParts, thousandDelimiter, decimalDelimiter) {
|
|
35
|
+
var numberPartsWithReplacedDelimiters = numberParts.map(function (numberPart) {
|
|
36
|
+
var numberPartWithReplacedDelimiters = numberPart;
|
|
37
|
+
if (numberPartWithReplacedDelimiters.type === 'group') {
|
|
38
|
+
numberPartWithReplacedDelimiters.value = thousandDelimiter;
|
|
39
|
+
}
|
|
40
|
+
if (numberPartWithReplacedDelimiters.type === 'decimal') {
|
|
41
|
+
numberPartWithReplacedDelimiters.value = decimalDelimiter;
|
|
42
|
+
}
|
|
43
|
+
return numberPartWithReplacedDelimiters;
|
|
44
|
+
});
|
|
45
|
+
var joinedNumberParts = numberPartsWithReplacedDelimiters.map(function (numberPart) {
|
|
46
|
+
return numberPart.value;
|
|
47
|
+
}).join('');
|
|
48
|
+
return nbspToSpace(joinedNumberParts);
|
|
49
|
+
};
|
|
50
|
+
export var dateTimePartsToString = function dateTimePartsToString(dateTimeParts) {
|
|
51
|
+
var joinedDateTimeParts = dateTimeParts.map(function (dateTimePart) {
|
|
52
|
+
return dateTimePart.value;
|
|
53
|
+
}).join('');
|
|
54
|
+
return nbspToSpace(joinedDateTimeParts);
|
|
55
|
+
};
|
|
56
|
+
export var replaceDateTimeParts = function replaceDateTimeParts(dateTimeParts, replacementDateTimeParts, replacementDateTimeFormatPartTypes) {
|
|
57
|
+
return dateTimeParts.map(function (dateTimePart) {
|
|
58
|
+
var dateTimePartToReplace = dateTimePart;
|
|
59
|
+
if (replacementDateTimeFormatPartTypes != null && replacementDateTimeFormatPartTypes.includes(dateTimePartToReplace.type)) {
|
|
60
|
+
var foundedReplacementDateTimePart = replacementDateTimeParts == null ? void 0 : replacementDateTimeParts.find(function (replacementDateTimePart) {
|
|
61
|
+
return replacementDateTimePart.type === dateTimePartToReplace.type;
|
|
62
|
+
});
|
|
63
|
+
if (foundedReplacementDateTimePart) {
|
|
64
|
+
dateTimePartToReplace.value = foundedReplacementDateTimePart.value;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return dateTimePartToReplace;
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
export var translateDateTimeParts = function translateDateTimeParts(dateTimeParts, dateTimePartsFromLanguageIntl, options) {
|
|
71
|
+
var _options$dateOptions, _options$dateOptions2;
|
|
72
|
+
var replacementDateTimeFormatPartTypes = [];
|
|
73
|
+
if ((options == null ? void 0 : options.targetFormat) === WEEKDAY_LONG || (options == null ? void 0 : options.targetFormat) === WEEKDAY_SHORT) {
|
|
74
|
+
replacementDateTimeFormatPartTypes.push(WEEKDAY);
|
|
75
|
+
}
|
|
76
|
+
if ((options == null ? void 0 : options.targetFormat) === MONTH_LONG || (options == null ? void 0 : options.targetFormat) === MONTH_SHORT) {
|
|
77
|
+
replacementDateTimeFormatPartTypes.push(MONTH);
|
|
78
|
+
}
|
|
79
|
+
if ((options == null || (_options$dateOptions = options.dateOptions) == null ? void 0 : _options$dateOptions.month) === LONG || (options == null || (_options$dateOptions2 = options.dateOptions) == null ? void 0 : _options$dateOptions2.month) === SHORT) {
|
|
80
|
+
replacementDateTimeFormatPartTypes.push(MONTH);
|
|
81
|
+
}
|
|
82
|
+
if ((options == null ? void 0 : options.month) === LONG || (options == null ? void 0 : options.month) === SHORT) {
|
|
83
|
+
replacementDateTimeFormatPartTypes.push(MONTH);
|
|
84
|
+
}
|
|
85
|
+
return replaceDateTimeParts(dateTimeParts, dateTimePartsFromLanguageIntl, replacementDateTimeFormatPartTypes);
|
|
86
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { getDataFormatConfigFromNotation } from './dataFormatConfig.utils';
|
|
2
|
+
export { getDateParts, getTimeParts, getWeekdayLongDateParts, getWeekdayShortDateParts, getDateTimePartsSubset, nbspToSpace, numberPartsToString, dateTimePartsToString, replaceDateTimeParts, translateDateTimeParts, getMonthLongDateParts, getMonthShortDateParts, } from './dateTimeParts.utils';
|
|
3
|
+
export { convertNumberString, convertDateToDateTimeString, convertDateToRelativeToString, convertDateToRelativeFromString, convertDateToTimeString, convertDateToDateString, convertDateToWeekdayLongString, convertDateToWeekdayShortString, convertDateToMonthLongString, convertDateToMonthShortString, addPrefix, addSuffix, changeNamingConvention, getDefaultDataTimeOptions, } from './dataFormat.utils';
|
|
4
|
+
export { getConstantDatesAndFormattingOptions } from './date.utils';
|
|
5
|
+
export { applyTimezoneOffset, currentTimeInTimezone, getValueAsLocalDate, getTimeZone, dateStringTimeZoneParts, removeTimeZoneOffset, } from './timeZone.utils';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { getDataFormatConfigFromNotation } from './dataFormatConfig.utils';
|
|
2
|
+
export { getDateParts, getTimeParts, getWeekdayLongDateParts, getWeekdayShortDateParts, getDateTimePartsSubset, nbspToSpace, numberPartsToString, dateTimePartsToString, replaceDateTimeParts, translateDateTimeParts, getMonthLongDateParts, getMonthShortDateParts } from './dateTimeParts.utils';
|
|
3
|
+
export { convertNumberString, convertDateToDateTimeString, convertDateToRelativeToString, convertDateToRelativeFromString, convertDateToTimeString, convertDateToDateString, convertDateToWeekdayLongString, convertDateToWeekdayShortString, convertDateToMonthLongString, convertDateToMonthShortString, addPrefix, addSuffix, changeNamingConvention, getDefaultDataTimeOptions } from './dataFormat.utils';
|
|
4
|
+
export { getConstantDatesAndFormattingOptions } from './date.utils';
|
|
5
|
+
export { applyTimezoneOffset, currentTimeInTimezone, getValueAsLocalDate, getTimeZone, dateStringTimeZoneParts, removeTimeZoneOffset } from './timeZone.utils';
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type IntlShape } from 'react-intl';
|
|
2
|
+
export declare const TIMEZONE_OFFSET_REGEX: RegExp;
|
|
3
|
+
export declare const dateToIsoWithOffset: (value: Date, intlObject: IntlShape) => string;
|
|
4
|
+
export declare const applyTimezoneOffset: (date: Date | undefined, timezoneOffset: true | string | undefined, intl?: IntlShape) => string | Date | undefined;
|
|
5
|
+
export declare const removeTimeZoneOffset: (dateString: string | Date) => string;
|
|
6
|
+
export declare const extractTimeZoneOffset: (datestring: string) => string | null;
|
|
7
|
+
export declare const dateStringTimeZoneParts: (dateTimeIsoString: string) => {
|
|
8
|
+
dateTimeString: string;
|
|
9
|
+
offsetString: string | null;
|
|
10
|
+
};
|
|
11
|
+
export declare const getLocalDateInTimeZone: (dateIsoString: string, timezone: string) => Date;
|
|
12
|
+
export declare function toIsoString(date: Date, timeZone?: string | undefined): string;
|
|
13
|
+
export declare const currentTimeInTimezone: (timezoneString: string) => Date;
|
|
14
|
+
export declare const dateTimeStringToLocalDate: (value?: string, timeZone?: string) => Date;
|
|
15
|
+
export declare const getValueAsLocalDate: (value?: Date | string, timeZone?: string) => Date;
|
|
16
|
+
export declare const getTimeZone: (timeZone?: boolean | string, intl?: IntlShape) => string | undefined;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { format, getTimezoneOffset, utcToZonedTime } from 'date-fns-tz';
|
|
2
|
+
export var TIMEZONE_OFFSET_REGEX = /([+-]\d\d:\d\d)|([Z])$/;
|
|
3
|
+
var defaultTimezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
4
|
+
export var dateToIsoWithOffset = function dateToIsoWithOffset(value, intlObject) {
|
|
5
|
+
return format(value, "yyyy-MM-dd'T'HH:mm:ssxxx", {
|
|
6
|
+
timeZone: (intlObject == null ? void 0 : intlObject.timeZone) || defaultTimezone
|
|
7
|
+
});
|
|
8
|
+
};
|
|
9
|
+
export var applyTimezoneOffset = function applyTimezoneOffset(date, timezoneOffset, intl) {
|
|
10
|
+
if (!timezoneOffset) {
|
|
11
|
+
return date;
|
|
12
|
+
}
|
|
13
|
+
var timezoneString = getTimeZone(timezoneOffset, intl);
|
|
14
|
+
return toIsoString(date, timezoneString);
|
|
15
|
+
};
|
|
16
|
+
export var removeTimeZoneOffset = function removeTimeZoneOffset(dateString) {
|
|
17
|
+
var date = dateString instanceof Date ? dateString.toISOString() : dateString;
|
|
18
|
+
var finalDate = date.replace(TIMEZONE_OFFSET_REGEX, '');
|
|
19
|
+
return finalDate;
|
|
20
|
+
};
|
|
21
|
+
export var extractTimeZoneOffset = function extractTimeZoneOffset(datestring) {
|
|
22
|
+
var date = datestring.toString();
|
|
23
|
+
var found = date.match(TIMEZONE_OFFSET_REGEX);
|
|
24
|
+
return found && found[0];
|
|
25
|
+
};
|
|
26
|
+
export var dateStringTimeZoneParts = function dateStringTimeZoneParts(dateTimeIsoString) {
|
|
27
|
+
return {
|
|
28
|
+
dateTimeString: removeTimeZoneOffset(dateTimeIsoString),
|
|
29
|
+
offsetString: extractTimeZoneOffset(dateTimeIsoString)
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
export var getLocalDateInTimeZone = function getLocalDateInTimeZone(dateIsoString, timezone) {
|
|
33
|
+
var _dateStringTimeZonePa = dateStringTimeZoneParts(dateIsoString),
|
|
34
|
+
offsetString = _dateStringTimeZonePa.offsetString,
|
|
35
|
+
dateTimeString = _dateStringTimeZonePa.dateTimeString;
|
|
36
|
+
var localDate = new Date(dateTimeString);
|
|
37
|
+
var localTimezoneOffset = getTimezoneOffset(timezone, localDate); // +2
|
|
38
|
+
var dateTimezoneOffset = offsetString ? getTimezoneOffset(offsetString, localDate) : 0; // -4
|
|
39
|
+
|
|
40
|
+
var offsetDiff = localTimezoneOffset - dateTimezoneOffset;
|
|
41
|
+
localDate.setMilliseconds(localDate.getMilliseconds() + offsetDiff);
|
|
42
|
+
return localDate;
|
|
43
|
+
};
|
|
44
|
+
var pad = function pad(num) {
|
|
45
|
+
return (num < 10 ? '0' : '') + num;
|
|
46
|
+
};
|
|
47
|
+
export function toIsoString(date, timeZone) {
|
|
48
|
+
if (timeZone === void 0) {
|
|
49
|
+
timeZone = 'UTC';
|
|
50
|
+
}
|
|
51
|
+
if (!timeZone) {
|
|
52
|
+
return date.toISOString();
|
|
53
|
+
}
|
|
54
|
+
var timeZoneOffset = getTimezoneOffset(timeZone, date);
|
|
55
|
+
var dif = timeZoneOffset >= 0 ? '+' : '-';
|
|
56
|
+
var tzHours = pad(Math.floor(Math.abs(timeZoneOffset) / 60 / 60 / 1000));
|
|
57
|
+
var tzMinutes = pad(Math.abs(timeZoneOffset) / 60 / 1000 % 60);
|
|
58
|
+
return date.getFullYear() + "-" + pad(date.getMonth() + 1) + "-" + pad(date.getDate()) + "T" + pad(date.getHours()) + ":" + pad(date.getMinutes()) + ":" + pad(date.getSeconds()) + dif + tzHours + ":" + tzMinutes;
|
|
59
|
+
}
|
|
60
|
+
export var currentTimeInTimezone = function currentTimeInTimezone(timezoneString) {
|
|
61
|
+
var now = new Date();
|
|
62
|
+
return utcToZonedTime(now.toISOString(), timezoneString);
|
|
63
|
+
};
|
|
64
|
+
export var dateTimeStringToLocalDate = function dateTimeStringToLocalDate(value, timeZone) {
|
|
65
|
+
if (!value || !timeZone) {
|
|
66
|
+
return new Date();
|
|
67
|
+
}
|
|
68
|
+
if (timeZone !== undefined) {
|
|
69
|
+
return getLocalDateInTimeZone(value, timeZone);
|
|
70
|
+
}
|
|
71
|
+
// FIXME ????
|
|
72
|
+
return typeof value === 'string' ? new Date(value) : value;
|
|
73
|
+
};
|
|
74
|
+
export var getValueAsLocalDate = function getValueAsLocalDate(value, timeZone) {
|
|
75
|
+
if (!value) {
|
|
76
|
+
return new Date();
|
|
77
|
+
}
|
|
78
|
+
if (timeZone !== undefined) {
|
|
79
|
+
if (typeof value !== 'string') {
|
|
80
|
+
return getLocalDateInTimeZone(value.toISOString(), timeZone);
|
|
81
|
+
}
|
|
82
|
+
return getLocalDateInTimeZone(value, timeZone);
|
|
83
|
+
}
|
|
84
|
+
return typeof value === 'string' ? new Date(value) : value;
|
|
85
|
+
};
|
|
86
|
+
export var getTimeZone = function getTimeZone(timeZone, intl) {
|
|
87
|
+
if (!timeZone) {
|
|
88
|
+
return undefined;
|
|
89
|
+
}
|
|
90
|
+
if (timeZone === true) {
|
|
91
|
+
return (intl == null ? void 0 : intl.timeZone) || defaultTimezone;
|
|
92
|
+
}
|
|
93
|
+
return timeZone;
|
|
94
|
+
};
|
package/dist/js/index.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
1
|
export { default as DSProvider, type DSProviderProps } from './DSProvider';
|
|
2
2
|
export { default as mediaQuery } from './mediaQuery/mediaQuery';
|
|
3
3
|
export { theme, useTheme, defaultColorsOrder, themeVariables, type ThemePropsVars, type ThemeProps, type WithTheme, type DefaultColor, } from './DSProvider/ThemeProvider/theme';
|
|
4
|
+
export * from './data-format';
|
|
5
|
+
export * from './testing';
|
|
6
|
+
export * from './toaster';
|
package/dist/js/index.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
1
|
export { default as DSProvider } from './DSProvider';
|
|
2
2
|
export { default as mediaQuery } from './mediaQuery/mediaQuery';
|
|
3
|
-
export { theme, useTheme, defaultColorsOrder, themeVariables } from './DSProvider/ThemeProvider/theme';
|
|
3
|
+
export { theme, useTheme, defaultColorsOrder, themeVariables } from './DSProvider/ThemeProvider/theme';
|
|
4
|
+
export * from './data-format';
|
|
5
|
+
export * from './testing';
|
|
6
|
+
export * from './toaster';
|
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
import { type FlattenSimpleInterpolation, type SimpleInterpolation } from 'styled-components';
|
|
2
|
-
|
|
3
|
-
export type BreakpointsData = Record<BreakpointKey, {
|
|
4
|
-
min: number;
|
|
5
|
-
max: number;
|
|
6
|
-
}>;
|
|
2
|
+
import { type BreakpointKey } from '../DSProvider/ThemeProvider/breakpoints';
|
|
7
3
|
export type Media = {
|
|
8
4
|
from: BreakpointsType;
|
|
9
5
|
to: BreakpointsType;
|