@24i/bigscreen-sdk 1.0.4 → 1.0.5-4.alpha-2832
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/README.md +2 -3
- package/ci/is_ci_job_skippable.sh +153 -0
- package/package.json +55 -34
- package/packages/adobe-heartbeat/src/AdobeHeartbeat.ts +9 -9
- package/packages/analytics/README.md +8 -0
- package/packages/analytics/src/A.ts +1 -0
- package/packages/analytics/src/Analytics.ts +1 -0
- package/packages/analytics/src/analyticsOnScroll.ts +1 -0
- package/packages/analytics/src/clients/ConsoleAnalytics/ConsoleAnalytics.ts +1 -0
- package/packages/analytics/src/clients/ConsoleAnalytics/index.ts +1 -0
- package/packages/analytics/src/clients/GoogleAnalytics/GoogleAnalytics.ts +196 -0
- package/packages/analytics/src/clients/GoogleAnalytics/constants.ts +126 -0
- package/packages/analytics/src/clients/GoogleAnalytics/getUrl.ts +17 -0
- package/packages/analytics/src/clients/GoogleAnalytics/index.ts +2 -0
- package/packages/analytics/src/clients/GoogleAnalytics/interface.ts +82 -0
- package/packages/analytics/src/clients/GoogleAnalytics/mapPayload.ts +51 -0
- package/packages/analytics/src/clients/GoogleAnalytics/prepareBody.ts +14 -0
- package/packages/analytics/src/clients/TealiumAnalytics/TealiumAnalytics.ts +181 -0
- package/packages/analytics/src/clients/TealiumAnalytics/constants.ts +106 -0
- package/packages/analytics/src/clients/TealiumAnalytics/findForLanguage.ts +9 -0
- package/packages/analytics/src/clients/TealiumAnalytics/index.ts +4 -0
- package/packages/analytics/src/clients/TealiumAnalytics/interface.ts +35 -0
- package/packages/analytics/src/clients/TealiumAnalytics/mappers/__mocks__/mediaPayload.ts +72 -0
- package/packages/analytics/src/clients/TealiumAnalytics/mappers/helper.ts +36 -0
- package/packages/analytics/src/clients/TealiumAnalytics/mappers/mapAppError.ts +13 -0
- package/packages/analytics/src/clients/TealiumAnalytics/mappers/mapAppOpen.ts +13 -0
- package/packages/analytics/src/clients/TealiumAnalytics/mappers/mapFavoriteAdd.ts +11 -0
- package/packages/analytics/src/clients/TealiumAnalytics/mappers/mapFavoriteRemove.ts +11 -0
- package/packages/analytics/src/clients/TealiumAnalytics/mappers/mapPlayerClose.ts +15 -0
- package/packages/analytics/src/clients/TealiumAnalytics/mappers/mapPlayerOpen.ts +15 -0
- package/packages/analytics/src/clients/TealiumAnalytics/mappers/mapSceneView.ts +18 -0
- package/packages/analytics/src/clients/TealiumAnalytics/mappers/mapSearch.ts +18 -0
- package/packages/analytics/src/clients/TealiumAnalytics/mappers/mapSearchFailed.ts +8 -0
- package/packages/analytics/src/clients/TealiumAnalytics/mappers/mapSearchSuccess.ts +8 -0
- package/packages/analytics/src/clients/TealiumAnalytics/mappers/mapVideoPause.ts +15 -0
- package/packages/analytics/src/clients/TealiumAnalytics/mappers/mapVideoProgress.ts +18 -0
- package/packages/analytics/src/clients/TealiumAnalytics/mappers/mapVideoResume.ts +15 -0
- package/packages/analytics/src/clients/TealiumAnalytics/mappers/mapVideoStart.ts +15 -0
- package/packages/analytics/src/clients/TealiumAnalytics/mappers/mapVideoStop.ts +15 -0
- package/packages/analytics/src/clients/TealiumAnalytics/types.ts +161 -0
- package/packages/analytics/src/clients/TwentyFourIQ/TwentyFourIQClient.ts +107 -0
- package/packages/analytics/src/clients/TwentyFourIQ/constants.ts +111 -0
- package/packages/analytics/src/clients/TwentyFourIQ/helper.ts +34 -0
- package/packages/analytics/src/clients/TwentyFourIQ/index.ts +2 -0
- package/packages/analytics/src/clients/TwentyFourIQ/interface.ts +34 -0
- package/packages/analytics/src/clients/TwentyFourIQ/mappers/mapAdEvent.ts +20 -0
- package/packages/analytics/src/clients/TwentyFourIQ/mappers/mapBase.ts +24 -0
- package/packages/analytics/src/clients/TwentyFourIQ/mappers/mapBuffering.ts +15 -0
- package/packages/analytics/src/clients/TwentyFourIQ/mappers/mapPlayerClose.ts +25 -0
- package/packages/analytics/src/clients/TwentyFourIQ/mappers/mapPlayerOpen.ts +17 -0
- package/packages/analytics/src/clients/TwentyFourIQ/mappers/mapSceneView.ts +15 -0
- package/packages/analytics/src/clients/TwentyFourIQ/mappers/mapScroll.ts +17 -0
- package/packages/analytics/src/clients/TwentyFourIQ/mappers/mapVideoComplete.ts +22 -0
- package/packages/analytics/src/clients/TwentyFourIQ/mappers/mapVideoPause.ts +25 -0
- package/packages/analytics/src/clients/TwentyFourIQ/mappers/mapVideoProgress.ts +25 -0
- package/packages/analytics/src/clients/TwentyFourIQ/mappers/mapVideoStart.ts +34 -0
- package/packages/analytics/src/clients/TwentyFourIQ/mappers/mapVideoStop.ts +32 -0
- package/packages/analytics/src/clients/TwentyFourIQ/types.ts +132 -0
- package/packages/analytics/src/constants.ts +1 -0
- package/packages/analytics/src/index.ts +3 -0
- package/packages/analytics/src/interface.ts +1 -0
- package/packages/analytics/src/utils/generateSessionId.ts +8 -0
- package/packages/async-image/src/AsyncImage.tsx +15 -10
- package/packages/developer-tools/PlayerDebugWindow/README.md +1 -1
- package/packages/developer-tools/src/DeveloperConsole/DeveloperConsole.tsx +1 -0
- package/packages/developer-tools/src/DeveloperToolsService/DeveloperToolsList.tsx +11 -0
- package/packages/developer-tools/src/PlayerDebugWindow/PlayerDebugWindow.tsx +5 -5
- package/packages/developer-tools/src/PlayerDebugWindow/constants.ts +15 -0
- package/packages/developer-tools/src/TechnicalInfo/TechnicalInfo.tsx +2 -0
- package/packages/developer-tools/src/TechnicalInfo/TechnicalInfoDetail.tsx +2 -1
- package/packages/developer-tools/src/TechnicalInfo/TechnicalInfoProvider.ts +57 -5
- package/packages/developer-tools/src/TechnicalInfo/__mocks__/Device.ts +12 -0
- package/packages/developer-tools/src/TechnicalInfo/translations.ts +8 -0
- package/packages/device/src/driver/index.android.tv.ts +1 -0
- package/packages/device/src/driver/index.firetv.ts +1 -0
- package/packages/device/src/driver/index.smartcast.tv.ts +1 -0
- package/packages/device/src/getKeyDigit.ts +2 -2
- package/packages/device/src/resolver/resolver.ts +19 -0
- package/packages/digital-clock/src/DigitalClock.tsx +15 -4
- package/packages/driver-androidtv/src/DeviceAndroidTV.ts +262 -0
- package/packages/driver-androidtv/src/__mocks__/javaScriptBridge.ts +45 -0
- package/packages/driver-androidtv/src/formatUserAgent.ts +11 -0
- package/packages/driver-androidtv/src/index.ts +2 -0
- package/packages/driver-androidtv/src/keymap.ts +27 -0
- package/packages/driver-androidtv/src/types.ts +155 -0
- package/packages/driver-base/src/DeviceBase.ts +73 -2
- package/packages/driver-base/src/KeyMap/Key.ts +8 -1
- package/packages/driver-base/src/KeyMap/KeyMap.ts +4 -0
- package/packages/driver-base/src/KeyMap/interface.ts +1 -0
- package/packages/driver-base/src/KeyMap/overrideValues.ts +2 -1
- package/packages/driver-base/src/__mocks__/DeviceBase.ts +24 -0
- package/packages/driver-base/src/__mocks__/keyMap.ts +1 -0
- package/packages/driver-base/src/index.ts +3 -0
- package/packages/driver-base/src/types/AdInfo.ts +5 -0
- package/packages/driver-base/src/types/DeviceEvent.ts +2 -0
- package/packages/driver-base/src/types/InAppPurchase.ts +20 -0
- package/packages/driver-base/src/types/KeycodeKeyMap.ts +1 -0
- package/packages/driver-browser/src/DeviceBrowser.ts +26 -0
- package/packages/driver-browser/src/keymap.ts +8 -0
- package/packages/driver-entone/src/DeviceEntone.ts +31 -1
- package/packages/driver-entone/src/keymap.ts +1 -0
- package/packages/driver-firetv/src/DeviceFireTV.ts +86 -0
- package/packages/driver-firetv/src/__mocks__/javaScriptBridge.ts +45 -0
- package/packages/driver-firetv/src/index.ts +1 -0
- package/packages/driver-firetv/src/types.ts +1 -0
- package/packages/driver-hbbtv/src/DeviceHbbTV.ts +26 -0
- package/packages/driver-kreatv/src/DeviceKreaTV.ts +26 -0
- package/packages/driver-saphi/src/DeviceSaphi.ts +26 -0
- package/packages/driver-smartcast/src/DeviceSmartCast.ts +380 -0
- package/packages/driver-smartcast/src/__mocks__/api.ts +69 -0
- package/packages/driver-smartcast/src/index.ts +1 -0
- package/packages/driver-smartcast/src/keymap.ts +9 -0
- package/packages/driver-smartcast/src/types.ts +102 -0
- package/packages/driver-tizen/src/DeviceTizen.ts +121 -7
- package/packages/driver-tizen/src/ITizen.ts +15116 -202
- package/packages/driver-tizen/src/IWebapis.ts +8643 -87
- package/packages/driver-tizen/src/TizenKeys.ts +4 -2
- package/packages/driver-tizen/src/__mocks__/tizen.ts +7 -8
- package/packages/driver-tizen/src/constants.ts +1 -195
- package/packages/driver-vidaa/src/DeviceVidaa.ts +29 -2
- package/packages/driver-vidaa/src/__mocks__/vidaa.ts +1 -1
- package/packages/driver-vidaa/src/keymap.ts +2 -0
- package/packages/driver-webos/src/DeviceWebos.ts +55 -0
- package/packages/driver-webos/src/__mocks__/webos.ts +33 -0
- package/packages/driver-webos/src/constants.ts +1 -0
- package/packages/driver-webos/src/keymap.ts +2 -1
- package/packages/driver-webos/src/types.ts +30 -0
- package/packages/driver-xbox/src/DeviceXbox.ts +30 -1
- package/packages/driver-xbox/src/keymap.ts +1 -1
- package/packages/epg/README.md +3 -1
- package/packages/epg/src/v2/Cell.tsx +16 -2
- package/packages/epg/src/v2/DataManager.ts +112 -41
- package/packages/epg/src/v2/DatePicker.tsx +9 -3
- package/packages/epg/src/v2/DateToast/DateToast.tsx +12 -9
- package/packages/epg/src/v2/Day.tsx +6 -3
- package/packages/epg/src/v2/Epg.tsx +5 -5
- package/packages/epg/src/v2/MockGenerator/generator.ts +3 -2
- package/packages/epg/src/v2/ProgramInfo/utils.ts +4 -3
- package/packages/epg/src/v2/Row.tsx +3 -1
- package/packages/epg/src/v2/TimelineSection.tsx +4 -1
- package/packages/epg/src/v2/basic/CellsManager.tsx +7 -2
- package/packages/epg/src/v2/basic/RowsManager.tsx +3 -1
- package/packages/epg/src/v2/interface.ts +13 -0
- package/packages/events-manager/src/EventsManager.ts +1 -56
- package/packages/focus/README.md +33 -0
- package/packages/focus/src/IFocusable.ts +1 -0
- package/packages/focus/src/Layout/Base.tsx +41 -6
- package/packages/focus/src/Layout/Matrix.tsx +51 -19
- package/packages/focus/src/focusFirstExisting.ts +7 -1
- package/packages/focus/src/hasFocus.ts +36 -0
- package/packages/focus/src/index.ts +2 -1
- package/packages/gallup/src/Gallup.ts +3 -3
- package/packages/grid/src/Base/Base.tsx +15 -10
- package/packages/grid/src/FirstOnlyGrid/FirstOnlyGrid.tsx +4 -2
- package/packages/grid/src/UnifiedGridController/UnifiedGridController.ts +6 -6
- package/packages/icon/src/Icon.tsx +27 -5
- package/packages/input/README.md +1 -1
- package/packages/input/src/Input.tsx +10 -10
- package/packages/interactable/README.md +2 -1
- package/packages/interactable/src/Interactable.tsx +9 -3
- package/packages/interactable/src/interface.ts +1 -0
- package/packages/jsx/src/index.ts +1 -1
- package/packages/jsx/src/test-utils/index.ts +1 -0
- package/packages/jsx/src/test-utils/keyup.ts +27 -0
- package/packages/keyboard/README.md +2 -0
- package/packages/keyboard/src/Backdrop/Backdrop.scss +2 -0
- package/packages/keyboard/src/KeyboardBase.tsx +16 -4
- package/packages/keyboard/src/WhitelabelKeyboard/Keyboard.scss +10 -0
- package/packages/keyboard/src/WhitelabelKeyboard/Keyboard.tsx +128 -142
- package/packages/keyboard/src/WhitelabelKeyboard/WhitelabelStyles/whitelabel.scss +4 -0
- package/packages/keyboard/src/WhitelabelKeyboard/_sizes.1080.scss +1 -0
- package/packages/keyboard/src/WhitelabelKeyboard/_sizes.scss +1 -0
- package/packages/keyboard/src/WhitelabelKeyboard/icons/key_language.svg +20 -0
- package/packages/keyboard/src/WhitelabelKeyboard/index.ts +1 -1
- package/packages/keyboard/src/WhitelabelKeyboard/layouts/arabic.ts +27 -0
- package/packages/keyboard/src/WhitelabelKeyboard/layouts/burmese.ts +27 -0
- package/packages/keyboard/src/WhitelabelKeyboard/layouts/dari.ts +28 -0
- package/packages/keyboard/src/WhitelabelKeyboard/layouts/hebrew.ts +28 -0
- package/packages/keyboard/src/WhitelabelKeyboard/layouts/index.ts +15 -0
- package/packages/keyboard/src/WhitelabelKeyboard/layouts/korean.ts +26 -0
- package/packages/keyboard/src/WhitelabelKeyboard/layouts/latin.ts +26 -0
- package/packages/keyboard/src/WhitelabelKeyboard/layouts/pashto.ts +27 -0
- package/packages/keyboard/src/WhitelabelKeyboard/layouts/persian.ts +27 -0
- package/packages/keyboard/src/WhitelabelKeyboard/layouts/russian.ts +27 -0
- package/packages/keyboard/src/WhitelabelKeyboard/layouts/spanish.ts +26 -0
- package/packages/keyboard/src/WhitelabelKeyboard/layouts/special.ts +28 -0
- package/packages/keyboard/src/WhitelabelKeyboard/layouts/tibetan.ts +26 -0
- package/packages/keyboard/src/WhitelabelKeyboard/layouts/turkish.ts +26 -0
- package/packages/keyboard/src/WhitelabelKeyboard/layouts/ukrainian.ts +27 -0
- package/packages/keyboard/src/WhitelabelKeyboard/layouts/urdu.ts +26 -0
- package/packages/keyboard/src/WhitelabelKeyboard/types.ts +22 -2
- package/packages/keyboard/src/types/index.ts +1 -1
- package/packages/keyboard/src/utils/caret.ts +5 -8
- package/packages/keyboard/src/utils/input.ts +5 -6
- package/packages/keyboard/src/utils/setInputSelectionRange.ts +10 -0
- package/packages/l10n/README.md +18 -0
- package/packages/l10n/src/date/common.ts +18 -6
- package/packages/l10n/src/date/cs.ts +2 -8
- package/packages/l10n/src/date/de.ts +97 -0
- package/packages/l10n/src/date/en-001.ts +3 -3
- package/packages/l10n/src/date/en-common.ts +5 -4
- package/packages/l10n/src/date/en-us.ts +3 -3
- package/packages/l10n/src/date/es.ts +71 -0
- package/packages/l10n/src/date/fr.ts +94 -0
- package/packages/l10n/src/date/he.ts +101 -0
- package/packages/l10n/src/date/iso.ts +12 -13
- package/packages/l10n/src/date/types.ts +9 -0
- package/packages/l10n/src/l10n.ts +61 -3
- package/packages/list/src/Base/Base.tsx +19 -9
- package/packages/list/src/Base/interface.ts +2 -2
- package/packages/list/src/BasicList/BasicList.tsx +7 -7
- package/packages/list/src/CenteredList/CenteredList.tsx +2 -2
- package/packages/list/src/CenteredList/controller.ts +0 -1
- package/packages/list/src/EdgeOffsetList/EdgeOffsetList.tsx +10 -10
- package/packages/list/src/FirstOnlyList/FirstOnlyList.tsx +2 -2
- package/packages/list/src/FirstOnlyVariedList/FirstOnlyVariedList.tsx +2 -2
- package/packages/list/src/FixedToEndList/FixedToEndList.tsx +2 -2
- package/packages/list/src/UnifiedListController/UnifiedListController.ts +6 -2
- package/packages/list/src/interface.ts +2 -2
- package/packages/logger/src/loggers/ConsoleLogger/ConsoleLogger.ts +7 -1
- package/packages/logger/src/loggers/SentryLogger/Sentry.ts +1 -0
- package/packages/logger/src/loggers/SentryLogger/SentryLogger.ts +5 -3
- package/packages/menu/src/MenuAndContentContainer/MenuAndContentContainer.tsx +31 -3
- package/packages/menu/src/MenuAndContentContainer/interface.ts +8 -0
- package/packages/modal-service/README.md +4 -1
- package/packages/modal-service/src/ModalService.tsx +29 -5
- package/packages/perf-utils/README.md +1 -120
- package/packages/perf-utils/src/array/filter.ts +1 -54
- package/packages/perf-utils/src/array/find.ts +1 -43
- package/packages/perf-utils/src/array/findIndex.ts +1 -43
- package/packages/perf-utils/src/array/forEach.ts +1 -48
- package/packages/perf-utils/src/array/includes.ts +1 -41
- package/packages/perf-utils/src/array/includesNaN.ts +1 -32
- package/packages/perf-utils/src/array/index.ts +1 -7
- package/packages/perf-utils/src/array/map.ts +1 -52
- package/packages/player-ui/README.md +1 -1
- package/packages/player-ui/src/CurrentTime.tsx +2 -2
- package/packages/player-ui/src/Duration.tsx +2 -2
- package/packages/player-ui/src/PauseButton.tsx +8 -0
- package/packages/player-ui/src/PlayerInteractable.tsx +1 -0
- package/packages/player-ui/src/PlayerTime.tsx +3 -1
- package/packages/player-ui/src/PlayerUI.tsx +68 -35
- package/packages/player-ui/src/RemainingTime.tsx +2 -2
- package/packages/player-ui/src/Seekbar.tsx +110 -18
- package/packages/player-ui/src/Seeking.ts +57 -16
- package/packages/player-ui/src/Subtitles.tsx +2 -2
- package/packages/player-ui/src/index.ts +1 -0
- package/packages/player-ui/src/mocks.ts +32 -8
- package/packages/player-ui/src/timeUtils.ts +3 -3
- package/packages/player-ui/src/types.ts +9 -3
- package/packages/router/README.md +1 -0
- package/packages/router/src/Route.tsx +61 -27
- package/packages/router/src/Router.tsx +63 -14
- package/packages/router/src/history.ts +8 -1
- package/packages/router/src/index.ts +1 -1
- package/packages/router/src/utils.ts +9 -4
- package/packages/sass-utils/src/linear-gradient.scss +9 -4
- package/packages/sass-utils/src/scale.1080.scss +3 -1
- package/packages/sass-utils/src/scale.720.scss +1 -1
- package/packages/time/README.md +4 -1
- package/packages/time/src/Time.ts +35 -13
- package/packages/time/src/adapters/24iMediaTimeApi.ts +47 -0
- package/packages/time/src/constants.ts +1 -0
- package/packages/time/src/services/24iMediaTimeApi/24iMediaTimeApi.ts +43 -0
- package/packages/time/src/services/24iMediaTimeApi/index.ts +6 -0
- package/packages/toast/src/ToastService.scss +1 -0
- package/packages/toast/src/ToastService.tsx +16 -5
- package/packages/types-bigscreen-jsx/README.md +5 -4
- package/packages/types-bigscreen-jsx/index.d.ts +72 -67
- package/packages/utils/README.md +27 -0
- package/packages/utils/src/elementUtils.ts +25 -0
- package/packages/utils/src/forceReflow.ts +14 -0
- package/packages/utils/src/index.ts +8 -0
- package/packages/utils/src/keyPress/index.ts +6 -0
- package/packages/utils/src/keyPress/keyPressSimulator.ts +74 -0
- package/packages/utils/src/keyPress/simulateKeyPress.ts +25 -0
- package/packages/utils/src/scaledImage.ts +6 -3
- package/packages/utils/src/textUtils.ts +46 -14
- package/packages/utils/src/wait.ts +3 -1
- package/packages/utils/src/xhr/xhrSend.ts +3 -1
- package/packages/utils/src/xhr/xhrSendRetry.ts +3 -1
- package/packages/zapping/src/ChannelZapping.ts +9 -0
- package/packages/zapping/src/Zapping.tsx +10 -0
- package/utils/release/release.ts +156 -0
- package/packages/driver-tizen/src/types.ts +0 -14
- package/packages/focus/src/Layout/__test__/Base.spec.ts +0 -180
- package/packages/focus/src/Layout/__test__/Horizontal.spec.ts +0 -94
- package/packages/focus/src/Layout/__test__/Matrix.spec.ts +0 -261
- package/packages/focus/src/Layout/__test__/Vertical.spec.ts +0 -46
- package/packages/focus/src/Layout/__test__/isRtl.spec.ts +0 -23
- package/packages/focus/src/Layout/__test__/shared.ts +0 -19
- package/packages/keyboard/src/WhitelabelKeyboard/focusMatrix.ts +0 -19
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { processYear, dateFormatter, toTwoDigitLocaleTimeString } from './common';
|
|
2
|
+
import { DateTimeFormatOptions, Day, Month, Weekday, Year } from './types';
|
|
3
|
+
|
|
4
|
+
// https://web.library.yale.edu/cataloging/months
|
|
5
|
+
const DE_MONTHS = {
|
|
6
|
+
narrow: [
|
|
7
|
+
'J', 'F', 'M', 'A', 'M', 'J', 'J', 'A', 'S', 'O', 'N', 'D',
|
|
8
|
+
],
|
|
9
|
+
short: [
|
|
10
|
+
'Jan', 'Feb', 'März', 'Apr', 'Mai', 'Juni', 'Juli', 'Aug', 'Sept', 'Okt', 'Nov', 'Dez',
|
|
11
|
+
],
|
|
12
|
+
long: [
|
|
13
|
+
'Januar', 'Februar', 'März', 'April', 'Mai', 'Juni', 'Juli', 'August', 'September',
|
|
14
|
+
'Oktober', 'November', 'Dezember',
|
|
15
|
+
],
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const DE_WEEKDAYS = {
|
|
19
|
+
narrow: [
|
|
20
|
+
'S', 'M', 'D', 'M', 'D', 'F', 'S',
|
|
21
|
+
],
|
|
22
|
+
short: [
|
|
23
|
+
'So', 'Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa',
|
|
24
|
+
],
|
|
25
|
+
long: [
|
|
26
|
+
'Sonntag', 'Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag',
|
|
27
|
+
],
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const processDay = (dateParts: string[], day: Day | undefined, date: Date) => {
|
|
31
|
+
if (typeof day === 'undefined') return;
|
|
32
|
+
const strDate = date.getDate().toString();
|
|
33
|
+
dateParts.push(`${strDate}.`);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const processMonth = (
|
|
37
|
+
dateParts: string[],
|
|
38
|
+
month: Month | undefined,
|
|
39
|
+
date: Date,
|
|
40
|
+
) => {
|
|
41
|
+
if (typeof month === 'undefined') return;
|
|
42
|
+
if (month === '2-digit' || month === 'numeric') {
|
|
43
|
+
const strMonth = `${(date.getMonth() + 1).toString()}.`;
|
|
44
|
+
dateParts.push(strMonth);
|
|
45
|
+
} else {
|
|
46
|
+
const finalMonth = DE_MONTHS[month][date.getMonth()];
|
|
47
|
+
if (month === 'short') dateParts.push(`${finalMonth}.`);
|
|
48
|
+
else dateParts.push(finalMonth);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const processWeekday = (
|
|
53
|
+
dateStringParts: string[],
|
|
54
|
+
year: Year | undefined,
|
|
55
|
+
month: Month | undefined,
|
|
56
|
+
day: Day | undefined,
|
|
57
|
+
weekday: Weekday | undefined,
|
|
58
|
+
date: Date,
|
|
59
|
+
) => {
|
|
60
|
+
if (typeof weekday === 'undefined') return;
|
|
61
|
+
let weekdayString = DE_WEEKDAYS[weekday][date.getDay()];
|
|
62
|
+
if (weekday === 'short') weekdayString += '.';
|
|
63
|
+
if (
|
|
64
|
+
typeof year !== 'undefined'
|
|
65
|
+
|| typeof month !== 'undefined'
|
|
66
|
+
|| typeof day !== 'undefined'
|
|
67
|
+
) {
|
|
68
|
+
weekdayString += ',';
|
|
69
|
+
}
|
|
70
|
+
dateStringParts.push(weekdayString);
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
const toLocaleDateString = (date: Date) => (
|
|
74
|
+
{ weekday, year, month, day }: DateTimeFormatOptions = {
|
|
75
|
+
year: 'numeric', month: '2-digit', day: '2-digit',
|
|
76
|
+
},
|
|
77
|
+
) => {
|
|
78
|
+
const dateStringParts: string[] = [];
|
|
79
|
+
processWeekday(dateStringParts, year, month, day, weekday, date);
|
|
80
|
+
const dateConnection = '';
|
|
81
|
+
const dateParts: string[] = [];
|
|
82
|
+
processDay(dateParts, day, date);
|
|
83
|
+
if ((month === 'narrow'
|
|
84
|
+
|| month === 'short'
|
|
85
|
+
|| month === 'long')
|
|
86
|
+
&& day != null
|
|
87
|
+
) {
|
|
88
|
+
dateParts.push(' ');
|
|
89
|
+
}
|
|
90
|
+
processMonth(dateParts, month, date);
|
|
91
|
+
if (month === 'long') dateParts.push(' ');
|
|
92
|
+
processYear(dateParts, year, date);
|
|
93
|
+
dateStringParts.push(dateParts.join(dateConnection));
|
|
94
|
+
return dateStringParts.join(' ');
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
export const deDateFormatter = dateFormatter(toTwoDigitLocaleTimeString, toLocaleDateString);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
collonSeparatedHour12MinuteSecond, dateFormatter, processYear, SECOND_FROM_END,
|
|
3
3
|
} from './common';
|
|
4
|
-
import {
|
|
4
|
+
import { EN_MONTHS, processWeekday, isDdMmYyyy } from './en-common';
|
|
5
5
|
import type { DateTimeFormatOptions, Day, Month, Year } from './types';
|
|
6
6
|
|
|
7
7
|
const processMonth = (
|
|
@@ -19,7 +19,7 @@ const processMonth = (
|
|
|
19
19
|
: numericMonth
|
|
20
20
|
}${typeof year !== 'undefined' ? ',' : ''}`);
|
|
21
21
|
} else {
|
|
22
|
-
dateStringParts.push(
|
|
22
|
+
dateStringParts.push(EN_MONTHS[month][date.getMonth()]);
|
|
23
23
|
}
|
|
24
24
|
};
|
|
25
25
|
|
|
@@ -49,7 +49,7 @@ const getDdMmYyyy = (dateStringParts: string[], year: Year | undefined, date: Da
|
|
|
49
49
|
dateStringParts.push(`${d}/${m}/${y}`);
|
|
50
50
|
};
|
|
51
51
|
|
|
52
|
-
|
|
52
|
+
const toLocaleDateString = (date: Date) => (
|
|
53
53
|
{ weekday, year, month, day }: DateTimeFormatOptions = {
|
|
54
54
|
year: 'numeric', month: '2-digit', day: '2-digit',
|
|
55
55
|
},
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { Day, Month, Weekday, Year } from './types';
|
|
1
|
+
import type { Day, Month, Weekday, LocaleData, Year } from './types';
|
|
2
2
|
|
|
3
|
-
export const
|
|
3
|
+
export const EN_MONTHS = {
|
|
4
4
|
narrow: [
|
|
5
5
|
'J', 'F', 'M', 'A', 'M', 'J', 'J', 'A', 'S', 'O', 'N', 'D',
|
|
6
6
|
],
|
|
@@ -13,7 +13,7 @@ export const MONTHS = {
|
|
|
13
13
|
],
|
|
14
14
|
};
|
|
15
15
|
|
|
16
|
-
export const
|
|
16
|
+
export const EN_WEEKDAYS = {
|
|
17
17
|
narrow: [
|
|
18
18
|
'S', 'M', 'T', 'W', 'T', 'F', 'S',
|
|
19
19
|
],
|
|
@@ -32,9 +32,10 @@ export const processWeekday = (
|
|
|
32
32
|
day: Day | undefined,
|
|
33
33
|
weekday: Weekday | undefined,
|
|
34
34
|
date: Date,
|
|
35
|
+
weekdaysLocaleData: LocaleData = EN_WEEKDAYS,
|
|
35
36
|
) => {
|
|
36
37
|
if (typeof weekday === 'undefined') return;
|
|
37
|
-
let weekdayString =
|
|
38
|
+
let weekdayString = weekdaysLocaleData[weekday][date.getDay()];
|
|
38
39
|
if (
|
|
39
40
|
typeof year !== 'undefined'
|
|
40
41
|
|| typeof month !== 'undefined'
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
processYear,
|
|
5
5
|
SECOND_FROM_END,
|
|
6
6
|
} from './common';
|
|
7
|
-
import {
|
|
7
|
+
import { EN_MONTHS, processWeekday, isDdMmYyyy } from './en-common';
|
|
8
8
|
import type { DateTimeFormatOptions, Day, Month, Year } from './types';
|
|
9
9
|
|
|
10
10
|
const processMonth = (dateStringParts: string[], month: Month | undefined, date: Date) => {
|
|
@@ -16,7 +16,7 @@ const processMonth = (dateStringParts: string[], month: Month | undefined, date:
|
|
|
16
16
|
? `0${numericMonth}` : numericMonth,
|
|
17
17
|
);
|
|
18
18
|
} else {
|
|
19
|
-
dateStringParts.push(
|
|
19
|
+
dateStringParts.push(EN_MONTHS[month][date.getMonth()]);
|
|
20
20
|
}
|
|
21
21
|
};
|
|
22
22
|
|
|
@@ -56,7 +56,7 @@ const getDdMmYyyy = (
|
|
|
56
56
|
dateStringParts.push(`${m}/${d}/${y}`);
|
|
57
57
|
};
|
|
58
58
|
|
|
59
|
-
|
|
59
|
+
const toLocaleDateString = (date: Date) => (
|
|
60
60
|
{ weekday, year, month, day }: DateTimeFormatOptions = {
|
|
61
61
|
year: 'numeric', month: 'numeric', day: 'numeric',
|
|
62
62
|
},
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { processYear, dateFormatter, toNumericLocaleTimeString } from './common';
|
|
2
|
+
import { processWeekday } from './en-common';
|
|
3
|
+
import { DateTimeFormatOptions, Day, Month } from './types';
|
|
4
|
+
|
|
5
|
+
const ES_MONTHS = {
|
|
6
|
+
narrow: [
|
|
7
|
+
'E', 'F', 'M', 'A', 'M', 'J', 'J', 'A', 'S', 'O', 'N', 'D',
|
|
8
|
+
],
|
|
9
|
+
// https://web.library.yale.edu/cataloging/months
|
|
10
|
+
short: [
|
|
11
|
+
'ene', 'feb', 'mar', 'abr', 'mayo', 'jun', 'jul', 'ago', 'set', 'oct', 'nov', 'dic',
|
|
12
|
+
],
|
|
13
|
+
long: [
|
|
14
|
+
'enero', 'febrero', 'marzo', 'abril', 'mayo', 'junio', 'julio', 'agosto', 'septiembre',
|
|
15
|
+
'octubre', 'noviembre', 'diciembre',
|
|
16
|
+
],
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const ES_WEEKDAYS = {
|
|
20
|
+
// https://letsspeakspanish.com/blog/days-of-week-months-seasons-in-spanish/
|
|
21
|
+
narrow: [
|
|
22
|
+
'D', 'L', 'M', 'X', 'J', 'V', 'S',
|
|
23
|
+
],
|
|
24
|
+
short: [
|
|
25
|
+
'dom', 'lun', 'mar', 'mié', 'jue', 'vie', 'sáb',
|
|
26
|
+
],
|
|
27
|
+
long: [
|
|
28
|
+
'domingo', 'lunes', 'martes', 'miércoles', 'jueves', 'viernes', 'sábado',
|
|
29
|
+
],
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const processDay = (dateParts: string[], day: Day | undefined, date: Date) => {
|
|
33
|
+
if (typeof day === 'undefined') return;
|
|
34
|
+
const strDate = date.getDate().toString();
|
|
35
|
+
dateParts.push(strDate);
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const processMonth = (
|
|
39
|
+
dateParts: string[],
|
|
40
|
+
month: Month | undefined,
|
|
41
|
+
date: Date,
|
|
42
|
+
) => {
|
|
43
|
+
if (typeof month === 'undefined') return;
|
|
44
|
+
if (month === '2-digit' || month === 'numeric') {
|
|
45
|
+
const strMonth = (date.getMonth() + 1).toString();
|
|
46
|
+
dateParts.push(strMonth);
|
|
47
|
+
} else {
|
|
48
|
+
const finalMonth = ES_MONTHS[month][date.getMonth()];
|
|
49
|
+
dateParts.push(finalMonth);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const toLocaleDateString = (date: Date) => (
|
|
54
|
+
{ weekday, year, month, day }: DateTimeFormatOptions = {
|
|
55
|
+
year: 'numeric', month: '2-digit', day: '2-digit',
|
|
56
|
+
},
|
|
57
|
+
) => {
|
|
58
|
+
const dateStringParts: string[] = [];
|
|
59
|
+
processWeekday(dateStringParts, year, month, day, weekday, date, ES_WEEKDAYS);
|
|
60
|
+
const dateConnection = month === '2-digit' || month === 'numeric' ? '/' : ' ';
|
|
61
|
+
const dateParts: string[] = [];
|
|
62
|
+
processDay(dateParts, day, date);
|
|
63
|
+
if (month === 'long' && day != null) dateParts.push('de');
|
|
64
|
+
processMonth(dateParts, month, date);
|
|
65
|
+
if (month === 'long') dateParts.push('de');
|
|
66
|
+
processYear(dateParts, year, date);
|
|
67
|
+
dateStringParts.push(dateParts.join(dateConnection));
|
|
68
|
+
return dateStringParts.join(' ');
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
export const esDateFormatter = dateFormatter(toNumericLocaleTimeString, toLocaleDateString);
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { dateFormatter, processYear, toTwoDigitLocaleTimeString } from './common';
|
|
2
|
+
import { DateTimeFormatOptions, Day, Month, Weekday, Year } from './types';
|
|
3
|
+
|
|
4
|
+
// https://web.library.yale.edu/cataloging/months
|
|
5
|
+
const FR_MONTHS = {
|
|
6
|
+
narrow: [
|
|
7
|
+
'J', 'F', 'M', 'A', 'M', 'J', 'J', 'A', 'S', 'O', 'N', 'D',
|
|
8
|
+
],
|
|
9
|
+
short: [
|
|
10
|
+
'janv', 'févr', 'mars', 'avril', 'mai', 'juin', 'juil', 'août', 'sept', 'oct', 'nov', 'déc',
|
|
11
|
+
],
|
|
12
|
+
long: [
|
|
13
|
+
'janvier', 'février', 'mars', 'avril', 'mai', 'juin', 'juillet', 'août', 'septembre',
|
|
14
|
+
'octobre', 'novembre', 'décembre',
|
|
15
|
+
],
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const FR_WEEKDAYS = {
|
|
19
|
+
narrow: [
|
|
20
|
+
'D', 'L', 'M', 'M', 'J', 'V', 'S',
|
|
21
|
+
],
|
|
22
|
+
short: [
|
|
23
|
+
'dim', 'lun', 'mar', 'mer', 'jeu', 'ven', 'sam',
|
|
24
|
+
],
|
|
25
|
+
long: [
|
|
26
|
+
'dimanche', 'lundi', 'mardi', 'mercredi', 'jeudi', 'vendredi', 'samedi',
|
|
27
|
+
],
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const processWeekday = (
|
|
31
|
+
dateStringParts: string[],
|
|
32
|
+
year: Year | undefined,
|
|
33
|
+
month: Month | undefined,
|
|
34
|
+
day: Day | undefined,
|
|
35
|
+
weekday: Weekday | undefined,
|
|
36
|
+
date: Date,
|
|
37
|
+
) => {
|
|
38
|
+
if (typeof weekday === 'undefined') return;
|
|
39
|
+
let weekdayString = FR_WEEKDAYS[weekday][date.getDay()];
|
|
40
|
+
if (
|
|
41
|
+
(typeof year !== 'undefined'
|
|
42
|
+
|| typeof month !== 'undefined'
|
|
43
|
+
|| typeof day !== 'undefined') && weekday !== 'long'
|
|
44
|
+
) {
|
|
45
|
+
weekdayString += '.';
|
|
46
|
+
}
|
|
47
|
+
dateStringParts.push(weekdayString);
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const processDay = (
|
|
51
|
+
dateParts: string[], day: Day | undefined, month: Month | undefined, date: Date,
|
|
52
|
+
) => {
|
|
53
|
+
if (typeof day === 'undefined') return;
|
|
54
|
+
const strDate = date.getDate().toString();
|
|
55
|
+
dateParts.push(
|
|
56
|
+
strDate.length === 1 && month !== 'short' && month !== 'long' ? `0${strDate}` : strDate,
|
|
57
|
+
);
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const processMonth = (
|
|
61
|
+
dateParts: string[],
|
|
62
|
+
month: Month | undefined,
|
|
63
|
+
date: Date,
|
|
64
|
+
) => {
|
|
65
|
+
if (typeof month === 'undefined') return;
|
|
66
|
+
if (month === '2-digit' || month === 'numeric') {
|
|
67
|
+
const strMonth = (date.getMonth() + 1).toString();
|
|
68
|
+
dateParts.push(
|
|
69
|
+
strMonth.length === 1 ? `0${strMonth}` : strMonth,
|
|
70
|
+
);
|
|
71
|
+
} else {
|
|
72
|
+
const finalMonth = FR_MONTHS[month][date.getMonth()];
|
|
73
|
+
if (month === 'short') dateParts.push(`${finalMonth}.`);
|
|
74
|
+
else dateParts.push(finalMonth);
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
const toLocaleDateString = (date: Date) => (
|
|
79
|
+
{ weekday, year, month, day }: DateTimeFormatOptions = {
|
|
80
|
+
year: 'numeric', month: '2-digit', day: '2-digit',
|
|
81
|
+
},
|
|
82
|
+
) => {
|
|
83
|
+
const dateStringParts: string[] = [];
|
|
84
|
+
processWeekday(dateStringParts, year, month, day, weekday, date);
|
|
85
|
+
const dateConnection = month === '2-digit' || month === 'numeric' ? '/' : ' ';
|
|
86
|
+
const dateParts: string[] = [];
|
|
87
|
+
processDay(dateParts, day, month, date);
|
|
88
|
+
processMonth(dateParts, month, date);
|
|
89
|
+
processYear(dateParts, year, date);
|
|
90
|
+
dateStringParts.push(dateParts.join(dateConnection));
|
|
91
|
+
return dateStringParts.join(' ');
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
export const frDateFormatter = dateFormatter(toTwoDigitLocaleTimeString, toLocaleDateString, ' ');
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { processYear, dateFormatter, toNumericLocaleTimeString } from './common';
|
|
2
|
+
import { DateTimeFormatOptions, Day, Month, Weekday } from './types';
|
|
3
|
+
|
|
4
|
+
const HE_MONTHS = {
|
|
5
|
+
narrow: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12'],
|
|
6
|
+
short: [
|
|
7
|
+
'ינו׳',
|
|
8
|
+
'פבר׳',
|
|
9
|
+
'מרץ',
|
|
10
|
+
'אפר׳',
|
|
11
|
+
'מאי',
|
|
12
|
+
'יוני',
|
|
13
|
+
'יולי',
|
|
14
|
+
'אוג׳',
|
|
15
|
+
'ספט׳',
|
|
16
|
+
'אוק׳',
|
|
17
|
+
'נוב׳',
|
|
18
|
+
'דצמ׳',
|
|
19
|
+
],
|
|
20
|
+
long: [
|
|
21
|
+
'ינואר',
|
|
22
|
+
'פברואר',
|
|
23
|
+
'מרץ',
|
|
24
|
+
'אפריל',
|
|
25
|
+
'מאי',
|
|
26
|
+
'יוני',
|
|
27
|
+
'יולי',
|
|
28
|
+
'אוגוסט',
|
|
29
|
+
'ספטמבר',
|
|
30
|
+
'אוקטובר',
|
|
31
|
+
'נובמבר',
|
|
32
|
+
'דצמבר',
|
|
33
|
+
],
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const HE_WEEKDAYS = {
|
|
37
|
+
narrow: ['א׳', 'ב׳', 'ג׳', 'ד׳', 'ה׳', 'ו׳', 'ש׳'],
|
|
38
|
+
short: ['יום א׳', 'יום ב׳', 'יום ג׳', 'יום ד׳', 'יום ה׳', 'יום ו׳', 'שבת'],
|
|
39
|
+
long: ['יום ראשון', 'יום שני', 'יום שלישי', 'יום רביעי', 'יום חמישי', 'יום שישי', 'יום שבת'],
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const processWeekday = (
|
|
43
|
+
dateStringParts: string[],
|
|
44
|
+
weekday: Weekday | undefined,
|
|
45
|
+
date: Date,
|
|
46
|
+
) => {
|
|
47
|
+
if (typeof weekday === 'undefined') return;
|
|
48
|
+
const weekdayString = HE_WEEKDAYS[weekday][date.getDay()];
|
|
49
|
+
dateStringParts.push(`${weekdayString},`);
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const processDay = (dateParts: string[], day: Day | undefined, date: Date) => {
|
|
53
|
+
if (typeof day === 'undefined') return;
|
|
54
|
+
const strDate = date.getDate().toString();
|
|
55
|
+
dateParts.push(strDate);
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const processMonth = (
|
|
59
|
+
dateParts: string[],
|
|
60
|
+
day:Day | undefined,
|
|
61
|
+
month: Month | undefined,
|
|
62
|
+
date: Date,
|
|
63
|
+
) => {
|
|
64
|
+
if (typeof month === 'undefined') return;
|
|
65
|
+
if (month === '2-digit' || month === 'numeric') {
|
|
66
|
+
const strMonth = (date.getMonth() + 1).toString();
|
|
67
|
+
dateParts.push(strMonth);
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
const finalMonth = HE_MONTHS[month][date.getMonth()];
|
|
71
|
+
if (day != null) {
|
|
72
|
+
dateParts.push(`ב${finalMonth}`);
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
dateParts.push(finalMonth);
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
const toLocaleDateString = (date: Date) => (
|
|
79
|
+
{ weekday, year, month, day }: DateTimeFormatOptions = {
|
|
80
|
+
year: 'numeric', month: '2-digit', day: '2-digit',
|
|
81
|
+
},
|
|
82
|
+
) => {
|
|
83
|
+
const dateStringParts: string[] = [];
|
|
84
|
+
processWeekday(dateStringParts, weekday, date);
|
|
85
|
+
const dateConnection = month === 'numeric' || month === '2-digit' ? '.' : '';
|
|
86
|
+
const dateParts: string[] = [];
|
|
87
|
+
processDay(dateParts, day, date);
|
|
88
|
+
if ((month === 'narrow'
|
|
89
|
+
|| month === 'short'
|
|
90
|
+
|| month === 'long')
|
|
91
|
+
&& day != null
|
|
92
|
+
) {
|
|
93
|
+
dateParts.push(' ');
|
|
94
|
+
}
|
|
95
|
+
processMonth(dateParts, day, month, date);
|
|
96
|
+
if (month === 'long') dateParts.push(' ');
|
|
97
|
+
processYear(dateParts, year, date);
|
|
98
|
+
dateStringParts.push(dateParts.join(dateConnection));
|
|
99
|
+
return dateStringParts.join(' ');
|
|
100
|
+
};
|
|
101
|
+
export const heDateFormatter = dateFormatter(toNumericLocaleTimeString, toLocaleDateString);
|
|
@@ -1,8 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { dateFormatter, processYear, toTwoDigitLocaleTimeString } from './common';
|
|
2
|
+
import { EN_MONTHS, EN_WEEKDAYS } from './en-common';
|
|
3
3
|
import type { DateTimeFormatOptions, Day, Month, Weekday, Year } from './types';
|
|
4
4
|
|
|
5
|
-
const processMonth = (
|
|
5
|
+
const processMonth = (
|
|
6
|
+
dateParts: string[],
|
|
7
|
+
month: Month | undefined,
|
|
8
|
+
date: Date,
|
|
9
|
+
|
|
10
|
+
) => {
|
|
6
11
|
if (typeof month === 'undefined') return;
|
|
7
12
|
if (month === '2-digit' || month === 'numeric') {
|
|
8
13
|
const strMonth = (date.getMonth() + 1).toString();
|
|
@@ -11,7 +16,7 @@ const processMonth = (dateParts: string[], month: Month | undefined, date: Date)
|
|
|
11
16
|
strMonth.length === 1 ? `0${strMonth}` : strMonth,
|
|
12
17
|
);
|
|
13
18
|
} else {
|
|
14
|
-
dateParts.push(
|
|
19
|
+
dateParts.push(EN_MONTHS[month][date.getMonth()]);
|
|
15
20
|
}
|
|
16
21
|
};
|
|
17
22
|
|
|
@@ -29,7 +34,7 @@ const processWeekday = (
|
|
|
29
34
|
&& typeof month === 'undefined'
|
|
30
35
|
&& typeof day === 'undefined'
|
|
31
36
|
);
|
|
32
|
-
dateStringParts.push(`${
|
|
37
|
+
dateStringParts.push(`${EN_WEEKDAYS[weekday][date.getDay()]}${isOnlyWeekday ? '' : ','}`);
|
|
33
38
|
};
|
|
34
39
|
|
|
35
40
|
const processDay = (dateParts: string[], day: Day | undefined, date: Date) => {
|
|
@@ -39,7 +44,7 @@ const processDay = (dateParts: string[], day: Day | undefined, date: Date) => {
|
|
|
39
44
|
dateParts.push(strDate.length === 1 ? `0${strDate}` : strDate);
|
|
40
45
|
};
|
|
41
46
|
|
|
42
|
-
|
|
47
|
+
const toLocaleDateString = (date: Date) => (
|
|
43
48
|
{ weekday, year, month, day }: DateTimeFormatOptions = {
|
|
44
49
|
year: 'numeric', month: '2-digit', day: '2-digit',
|
|
45
50
|
},
|
|
@@ -55,10 +60,4 @@ export const toLocaleDateString = (date: Date) => (
|
|
|
55
60
|
return dateStringParts.join(' ');
|
|
56
61
|
};
|
|
57
62
|
|
|
58
|
-
const
|
|
59
|
-
options: DateTimeFormatOptions = {
|
|
60
|
-
hour: '2-digit', minute: '2-digit', second: '2-digit',
|
|
61
|
-
},
|
|
62
|
-
) => collonSeparatedHour24MinuteSecond(date, options);
|
|
63
|
-
|
|
64
|
-
export const isoDateFormatter = dateFormatter(toLocaleTimeString, toLocaleDateString);
|
|
63
|
+
export const isoDateFormatter = dateFormatter(toTwoDigitLocaleTimeString, toLocaleDateString);
|
|
@@ -20,6 +20,8 @@ type TimeKeys = 'hour' | 'minute' | 'second';
|
|
|
20
20
|
|
|
21
21
|
type DateKeys = 'weekday' | 'year' | 'month' | 'day';
|
|
22
22
|
|
|
23
|
+
type FormatType = 'dateFormatLong' | 'dateFormatNumeric' | 'dateFormatShort' | 'timeFormat';
|
|
24
|
+
|
|
23
25
|
export type DateTimeFormatOptions = {
|
|
24
26
|
weekday?: Weekday,
|
|
25
27
|
year?: Year,
|
|
@@ -28,6 +30,7 @@ export type DateTimeFormatOptions = {
|
|
|
28
30
|
hour?: Hour,
|
|
29
31
|
minute?: Minute,
|
|
30
32
|
second?: Second,
|
|
33
|
+
formatType?: FormatType,
|
|
31
34
|
};
|
|
32
35
|
|
|
33
36
|
export type DateFormatOptions = Pick<DateTimeFormatOptions, DateKeys>;
|
|
@@ -45,3 +48,9 @@ export type Props = {
|
|
|
45
48
|
locale?: string,
|
|
46
49
|
options?: DateTimeFormatOptions,
|
|
47
50
|
};
|
|
51
|
+
|
|
52
|
+
export type LocaleData = {
|
|
53
|
+
narrow: string[];
|
|
54
|
+
short: string[];
|
|
55
|
+
long: string[];
|
|
56
|
+
};
|
|
@@ -1,11 +1,26 @@
|
|
|
1
|
+
import { format } from 'date-fns';
|
|
2
|
+
import * as fnsLocales from 'date-fns/locale';
|
|
1
3
|
import { EventsManager, IEvents } from '@24i/bigscreen-sdk/events-manager';
|
|
4
|
+
import { csDateFormatter } from './date/cs';
|
|
5
|
+
import { deDateFormatter } from './date/de';
|
|
6
|
+
import { esDateFormatter } from './date/es';
|
|
7
|
+
import { frDateFormatter } from './date/fr';
|
|
8
|
+
import { heDateFormatter } from './date/he';
|
|
2
9
|
import { isoDateFormatter } from './date/iso';
|
|
3
10
|
import { Formatters } from './types';
|
|
11
|
+
import { DateTimeFormatOptions } from './date/types';
|
|
4
12
|
|
|
5
13
|
type Events = {
|
|
6
14
|
'localechange': () => void,
|
|
7
15
|
};
|
|
16
|
+
|
|
17
|
+
type DateFnsConfig = Partial<
|
|
18
|
+
Record<NonNullable<DateTimeFormatOptions['formatType']>, string | null>
|
|
19
|
+
>;
|
|
20
|
+
|
|
8
21
|
class L10n implements IEvents<Events> {
|
|
22
|
+
private dateFnsConfig: DateFnsConfig = {};
|
|
23
|
+
|
|
9
24
|
private readonly events = new EventsManager<Events>();
|
|
10
25
|
|
|
11
26
|
addEventListener = this.events.addEventListener;
|
|
@@ -19,6 +34,11 @@ class L10n implements IEvents<Events> {
|
|
|
19
34
|
private readonly formatters: Formatters = {
|
|
20
35
|
date: {
|
|
21
36
|
iso: isoDateFormatter,
|
|
37
|
+
cs: csDateFormatter,
|
|
38
|
+
fr: frDateFormatter,
|
|
39
|
+
es: esDateFormatter,
|
|
40
|
+
de: deDateFormatter,
|
|
41
|
+
he: heDateFormatter,
|
|
22
42
|
},
|
|
23
43
|
};
|
|
24
44
|
|
|
@@ -33,15 +53,53 @@ class L10n implements IEvents<Events> {
|
|
|
33
53
|
return this.formatters[formatter].iso;
|
|
34
54
|
}
|
|
35
55
|
|
|
56
|
+
init(config: DateFnsConfig) {
|
|
57
|
+
this.dateFnsConfig = config;
|
|
58
|
+
}
|
|
59
|
+
|
|
36
60
|
setLocale(locale: string) {
|
|
37
61
|
if (locale === this.locale) return;
|
|
38
62
|
this.locale = locale;
|
|
39
63
|
this.triggerEvent('localechange');
|
|
40
64
|
}
|
|
41
65
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
66
|
+
getDateFnsFormatter = (
|
|
67
|
+
timestamp: number | Date,
|
|
68
|
+
locale: string,
|
|
69
|
+
fallbackCb: (options?: DateTimeFormatOptions) => string,
|
|
70
|
+
fallbackFormatType?: DateTimeFormatOptions['formatType'],
|
|
71
|
+
) => (
|
|
72
|
+
(options?: DateTimeFormatOptions): string => {
|
|
73
|
+
const { formatType, ...baseOptions } = options || {};
|
|
74
|
+
const dateFnsBsFormat = this.dateFnsConfig?.[formatType || fallbackFormatType!];
|
|
75
|
+
if (!dateFnsBsFormat) {
|
|
76
|
+
if (!options || Object.keys(baseOptions).length === 0) {
|
|
77
|
+
return fallbackCb();
|
|
78
|
+
}
|
|
79
|
+
return fallbackCb(baseOptions);
|
|
80
|
+
}
|
|
81
|
+
return format(
|
|
82
|
+
timestamp,
|
|
83
|
+
dateFnsBsFormat,
|
|
84
|
+
{ locale: fnsLocales[locale as keyof typeof fnsLocales] },
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
date(timestamp: number | Date, locale: string = this.locale) {
|
|
90
|
+
const formatter = this.getFormatterByLocale('date', locale)(timestamp);
|
|
91
|
+
|
|
92
|
+
return {
|
|
93
|
+
toLocaleString: this.getDateFnsFormatter(
|
|
94
|
+
timestamp, locale, formatter.toLocaleString,
|
|
95
|
+
),
|
|
96
|
+
toLocaleTimeString: this.getDateFnsFormatter(
|
|
97
|
+
timestamp, locale, formatter.toLocaleTimeString, 'timeFormat',
|
|
98
|
+
),
|
|
99
|
+
toLocaleDateString: this.getDateFnsFormatter(
|
|
100
|
+
timestamp, locale, formatter.toLocaleDateString, 'dateFormatShort',
|
|
101
|
+
),
|
|
102
|
+
};
|
|
45
103
|
}
|
|
46
104
|
|
|
47
105
|
addFormatter<T extends keyof Formatters, U extends keyof Formatters[T]>(
|