@24i/bigscreen-sdk 1.0.21 → 1.0.22-alpha.2373
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/package.json +2 -1
- package/packages/digital-clock/src/DigitalClock.tsx +5 -1
- package/packages/driver-androidtv/src/types.ts +8 -0
- package/packages/epg/src/v2/DatePicker.tsx +3 -1
- package/packages/epg/src/v2/DateToast/DateToast.tsx +2 -1
- package/packages/epg/src/v2/Day.tsx +3 -1
- package/packages/epg/src/v2/ProgramInfo/utils.ts +1 -1
- package/packages/epg/src/v2/TimelineSection.tsx +1 -1
- package/packages/l10n/README.md +18 -0
- package/packages/l10n/src/date/types.ts +3 -0
- package/packages/l10n/src/l10n.ts +51 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@24i/bigscreen-sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.22-alpha.2373",
|
|
4
4
|
"description": "SmartApps BIGscreen SDK monorepo",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -48,6 +48,7 @@
|
|
|
48
48
|
"@types/prop-types": "^15.7.5",
|
|
49
49
|
"@types/scheduler": "^0.16.3",
|
|
50
50
|
"csstype": "^3.1.1",
|
|
51
|
+
"date-fns": "2.29.3",
|
|
51
52
|
"lottie-web": "5.10.2",
|
|
52
53
|
"prop-types": "^15.8.1"
|
|
53
54
|
},
|
|
@@ -10,7 +10,11 @@ export type Props = {
|
|
|
10
10
|
className?: string,
|
|
11
11
|
};
|
|
12
12
|
|
|
13
|
-
const WITHOUT_SECONDS_OPTIONS = {
|
|
13
|
+
const WITHOUT_SECONDS_OPTIONS = {
|
|
14
|
+
hour: 'numeric',
|
|
15
|
+
minute: '2-digit',
|
|
16
|
+
formatType: 'timeFormat',
|
|
17
|
+
} as const;
|
|
14
18
|
const WITH_SECONDS_OPTIONS = { ...WITHOUT_SECONDS_OPTIONS, second: '2-digit' } as const;
|
|
15
19
|
|
|
16
20
|
export class DigitalClock extends Component<Props> {
|
|
@@ -74,6 +74,14 @@ export type DeviceInfo = {
|
|
|
74
74
|
* Android flavor. Ex. "appstage-bigscreen"
|
|
75
75
|
*/
|
|
76
76
|
appFlavor: string,
|
|
77
|
+
/**
|
|
78
|
+
* Underlying player engine name. Ex. "exoplayer"
|
|
79
|
+
*/
|
|
80
|
+
engineName: string,
|
|
81
|
+
/**
|
|
82
|
+
* Version of player engine. Ex. "2.18.1"
|
|
83
|
+
*/
|
|
84
|
+
engineVersion: string,
|
|
77
85
|
/**
|
|
78
86
|
* Android DRM key systems. Ex. ["Widewine", "W3C ClearKey"]
|
|
79
87
|
*/
|
|
@@ -49,7 +49,9 @@ const defaultFormat = (date: Date) => {
|
|
|
49
49
|
const locale = i18n.getLanguage();
|
|
50
50
|
return l10n
|
|
51
51
|
.date(date.getTime() + time.getTimezoneOffsetMs(), locale)
|
|
52
|
-
.toLocaleDateString({
|
|
52
|
+
.toLocaleDateString({
|
|
53
|
+
weekday: 'short', day: 'numeric', month: 'short', formatType: 'dateFormatShort',
|
|
54
|
+
});
|
|
53
55
|
};
|
|
54
56
|
|
|
55
57
|
export class DatePicker extends Component<Props> implements IDatePicker {
|
|
@@ -7,7 +7,7 @@ import { HOUR_IN_MS } from '@24i/bigscreen-sdk/utils/timeConstants';
|
|
|
7
7
|
import { InternalEpg, Plugin } from '../interface';
|
|
8
8
|
|
|
9
9
|
const formatTime = (localTimestamp: number) => l10n.date(localTimestamp).toLocaleTimeString(
|
|
10
|
-
{ hour: 'numeric', minute: '2-digit' },
|
|
10
|
+
{ hour: 'numeric', minute: '2-digit', formatType: 'timeFormat' },
|
|
11
11
|
);
|
|
12
12
|
|
|
13
13
|
const formatDate = (localTimestamp: number) => {
|
|
@@ -24,6 +24,7 @@ const formatDate = (localTimestamp: number) => {
|
|
|
24
24
|
weekday: 'short',
|
|
25
25
|
day: 'numeric',
|
|
26
26
|
month: 'short',
|
|
27
|
+
formatType: 'dateFormatShort',
|
|
27
28
|
});
|
|
28
29
|
};
|
|
29
30
|
|
|
@@ -18,7 +18,9 @@ export class Day extends Component<Props> implements IDay {
|
|
|
18
18
|
private formatCurrentTimestamp() {
|
|
19
19
|
return l10n
|
|
20
20
|
.date(this.timestamp + time.getTimezoneOffsetMs())
|
|
21
|
-
.toLocaleDateString({
|
|
21
|
+
.toLocaleDateString({
|
|
22
|
+
weekday: 'long', day: 'numeric', month: 'short', formatType: 'dateFormatShort',
|
|
23
|
+
});
|
|
22
24
|
}
|
|
23
25
|
|
|
24
26
|
render() {
|
|
@@ -19,7 +19,7 @@ export const getSubtitle = (asset: Asset) => (
|
|
|
19
19
|
|
|
20
20
|
const toLocaleTimeString = (timestamp: number) => l10n
|
|
21
21
|
.date(timestamp + time.getTimezoneOffsetMs())
|
|
22
|
-
.toLocaleTimeString({ hour: 'numeric', minute: '2-digit' });
|
|
22
|
+
.toLocaleTimeString({ hour: 'numeric', minute: '2-digit', formatType: 'timeFormat' });
|
|
23
23
|
|
|
24
24
|
export const getBroadcastTime = (asset: Asset) => {
|
|
25
25
|
const start = toLocaleTimeString(asset.program!.startTime);
|
|
@@ -26,7 +26,7 @@ export class TimelineSection extends Component<Props> implements ITimelineSectio
|
|
|
26
26
|
private formatCurrentTimestamp() {
|
|
27
27
|
return l10n
|
|
28
28
|
.date(this.timestamp + time.getTimezoneOffsetMs())
|
|
29
|
-
.toLocaleTimeString({ hour: 'numeric', minute: '2-digit' });
|
|
29
|
+
.toLocaleTimeString({ hour: 'numeric', minute: '2-digit', formatType: 'timeFormat' });
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
render() {
|
package/packages/l10n/README.md
CHANGED
|
@@ -76,6 +76,24 @@ type DateTimeFormatOptions = {
|
|
|
76
76
|
}
|
|
77
77
|
```
|
|
78
78
|
|
|
79
|
+
#### date-fns DateTime format
|
|
80
|
+
It is also possible to use formatting provided by [date-fns](https://date-fns.org/v2.30.0/docs/format) library. First you need to globally configure the formats used (usually from backstage):
|
|
81
|
+
```ts
|
|
82
|
+
l10n.init({
|
|
83
|
+
dateFormatLong?: string | null, // e.g. 'eee, dd MMM' for "Wed, 09 Jul"
|
|
84
|
+
dateFormatNumeric?: string | null, // e.g. 'EEEE, MMMM d' for "Wednesday, July 9"
|
|
85
|
+
dateFormatShort?: string | null, // e.g. 'MM/dd/yyyy' for "07/09/2023"
|
|
86
|
+
timeFormat?: string | null, // e.g. 'h:mm a' for "9:05 PM"
|
|
87
|
+
});
|
|
88
|
+
```
|
|
89
|
+
After that, `timeFormat` and `dateFormatShort` are used automatically where appropriate, in case the format string is _falsy_ the [default formatting implementation](#datetime-format) will be used. You can also specify which format you want to use in `DateTimeFormatOptions`:
|
|
90
|
+
```ts
|
|
91
|
+
type DateTimeFormatOptions = {
|
|
92
|
+
...
|
|
93
|
+
formatType: 'dateFormatLong' | 'dateFormatNumeric' | 'dateFormatShort' | 'timeFormat',
|
|
94
|
+
}
|
|
95
|
+
```
|
|
96
|
+
|
|
79
97
|
You can use both `timestamp` in `ms` or `Date` object directly for formatting.
|
|
80
98
|
|
|
81
99
|
#### Examples
|
|
@@ -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>;
|
|
@@ -1,3 +1,5 @@
|
|
|
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';
|
|
2
4
|
import { csDateFormatter } from './date/cs';
|
|
3
5
|
import { deDateFormatter } from './date/de';
|
|
@@ -6,11 +8,19 @@ import { frDateFormatter } from './date/fr';
|
|
|
6
8
|
import { heDateFormatter } from './date/he';
|
|
7
9
|
import { isoDateFormatter } from './date/iso';
|
|
8
10
|
import { Formatters } from './types';
|
|
11
|
+
import { DateTimeFormatOptions } from './date/types';
|
|
9
12
|
|
|
10
13
|
type Events = {
|
|
11
14
|
'localechange': () => void,
|
|
12
15
|
};
|
|
16
|
+
|
|
17
|
+
type DateFnsConfig = Partial<
|
|
18
|
+
Record<NonNullable<DateTimeFormatOptions['formatType']>, string | null>
|
|
19
|
+
>;
|
|
20
|
+
|
|
13
21
|
class L10n implements IEvents<Events> {
|
|
22
|
+
private dateFnsConfig: DateFnsConfig = {};
|
|
23
|
+
|
|
14
24
|
private readonly events = new EventsManager<Events>();
|
|
15
25
|
|
|
16
26
|
addEventListener = this.events.addEventListener;
|
|
@@ -43,15 +53,53 @@ class L10n implements IEvents<Events> {
|
|
|
43
53
|
return this.formatters[formatter].iso;
|
|
44
54
|
}
|
|
45
55
|
|
|
56
|
+
init(config: DateFnsConfig) {
|
|
57
|
+
this.dateFnsConfig = config;
|
|
58
|
+
}
|
|
59
|
+
|
|
46
60
|
setLocale(locale: string) {
|
|
47
61
|
if (locale === this.locale) return;
|
|
48
62
|
this.locale = locale;
|
|
49
63
|
this.triggerEvent('localechange');
|
|
50
64
|
}
|
|
51
65
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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
|
+
};
|
|
55
103
|
}
|
|
56
104
|
|
|
57
105
|
addFormatter<T extends keyof Formatters, U extends keyof Formatters[T]>(
|