@vixoniccom/footbal-score 1.4.6-dev.1 → 1.4.6-dev.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 +2 -0
- package/build/main.js +1 -1
- package/build.zip +0 -0
- package/package.json +1 -1
- package/src/App.tsx +2 -4
- package/src/components/Table/components/Time.tsx +30 -3
- package/src/helpers/getFixture.ts +12 -10
package/build.zip
CHANGED
|
Binary file
|
package/package.json
CHANGED
package/src/App.tsx
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React, { useEffect, useRef, useState } from 'react'
|
|
2
2
|
import localforage from 'localforage'
|
|
3
3
|
import { FontLoader, FormattedText, Table } from './components'
|
|
4
|
-
import { getFixture } from './helpers/getFixture'
|
|
4
|
+
import { getFixture, resolvedTimezone } from './helpers/getFixture'
|
|
5
5
|
|
|
6
6
|
export type Props = {
|
|
7
7
|
data: VixonicData
|
|
@@ -142,9 +142,7 @@ export const App: React.FunctionComponent<Props> = ({ data, start }) => {
|
|
|
142
142
|
fetchAndSchedule()
|
|
143
143
|
}, [league])
|
|
144
144
|
|
|
145
|
-
const timezone =
|
|
146
|
-
try { return Intl.DateTimeFormat().resolvedOptions().timeZone } catch { return 'UTC' }
|
|
147
|
-
})()
|
|
145
|
+
const timezone = resolvedTimezone
|
|
148
146
|
|
|
149
147
|
return (
|
|
150
148
|
<>
|
|
@@ -1,17 +1,44 @@
|
|
|
1
|
-
import moment from 'moment'
|
|
2
1
|
import React from 'react'
|
|
3
2
|
import { FormattedText } from '../../'
|
|
3
|
+
import { resolvedTimezone } from '../../../helpers/getFixture'
|
|
4
4
|
|
|
5
5
|
interface Props {
|
|
6
6
|
time: number
|
|
7
7
|
parameters: VixonicParameters
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
+
const timezone = resolvedTimezone
|
|
11
|
+
|
|
12
|
+
const formatFixtureTime = (timestamp: number) => {
|
|
13
|
+
const date = new Date(timestamp * 1000)
|
|
14
|
+
|
|
15
|
+
const dateParts = new Intl.DateTimeFormat('es-ES', {
|
|
16
|
+
timeZone: timezone,
|
|
17
|
+
day: '2-digit',
|
|
18
|
+
month: '2-digit',
|
|
19
|
+
}).formatToParts(date)
|
|
20
|
+
const day = dateParts.find(p => p.type === 'day')?.value ?? ''
|
|
21
|
+
const month = dateParts.find(p => p.type === 'month')?.value ?? ''
|
|
22
|
+
|
|
23
|
+
const timeParts = new Intl.DateTimeFormat('en-US', {
|
|
24
|
+
timeZone: timezone,
|
|
25
|
+
hour: 'numeric',
|
|
26
|
+
minute: '2-digit',
|
|
27
|
+
hour12: true,
|
|
28
|
+
}).formatToParts(date)
|
|
29
|
+
const hour = timeParts.find(p => p.type === 'hour')?.value ?? ''
|
|
30
|
+
const minute = timeParts.find(p => p.type === 'minute')?.value ?? ''
|
|
31
|
+
const period = timeParts.find(p => p.type === 'dayPeriod')?.value?.toLowerCase() ?? ''
|
|
32
|
+
|
|
33
|
+
return { dateStr: `${day}-${month}`, timeStr: `${hour}:${minute} ${period}` }
|
|
34
|
+
}
|
|
35
|
+
|
|
10
36
|
export const Time: React.FunctionComponent<Props> = ({ time, parameters }) => {
|
|
37
|
+
const { dateStr, timeStr } = formatFixtureTime(time)
|
|
11
38
|
return (
|
|
12
39
|
<div style={{ display: 'flex', flexDirection: 'column', alignItems: 'center', justifyContent: 'center' }}>
|
|
13
|
-
<FormattedText text={
|
|
14
|
-
<FormattedText text={
|
|
40
|
+
<FormattedText text={dateStr} format={parameters.timeFormat} />
|
|
41
|
+
<FormattedText text={timeStr} format={parameters.timeFormat} />
|
|
15
42
|
</div>
|
|
16
43
|
)
|
|
17
44
|
}
|
|
@@ -11,6 +11,17 @@ const MILLISECONDS_PER_DAY = 24 * 60 * 60 * 1000
|
|
|
11
11
|
|
|
12
12
|
const USE_MOCK = false
|
|
13
13
|
|
|
14
|
+
export const resolvedTimezone = (() => {
|
|
15
|
+
try {
|
|
16
|
+
const tz = Intl.DateTimeFormat().resolvedOptions().timeZone
|
|
17
|
+
console.log(`[football-score] Timezone resolved: ${tz}`)
|
|
18
|
+
return tz
|
|
19
|
+
} catch (error) {
|
|
20
|
+
console.warn('[football-score] Failed to resolve timezone, defaulting to UTC', error)
|
|
21
|
+
return 'UTC'
|
|
22
|
+
}
|
|
23
|
+
})()
|
|
24
|
+
|
|
14
25
|
export const getFixture = async (league: string, yesterday?: boolean, tomorrow?: boolean) => {
|
|
15
26
|
if (USE_MOCK) return mockFixtures
|
|
16
27
|
|
|
@@ -18,16 +29,7 @@ export const getFixture = async (league: string, yesterday?: boolean, tomorrow?:
|
|
|
18
29
|
const year = moment().format('YYYY')
|
|
19
30
|
const from = yesterday ? moment(Date.now() - MILLISECONDS_PER_DAY).format('YYYY-MM-DD') : today
|
|
20
31
|
const to = tomorrow ? moment(Date.now() + MILLISECONDS_PER_DAY).format('YYYY-MM-DD') : today
|
|
21
|
-
const timezone =
|
|
22
|
-
try {
|
|
23
|
-
const tz = Intl.DateTimeFormat().resolvedOptions().timeZone
|
|
24
|
-
console.log(`[football-score] Timezone resolved: ${tz}`)
|
|
25
|
-
return tz
|
|
26
|
-
} catch (error) {
|
|
27
|
-
console.warn('[football-score] Failed to resolve timezone, defaulting to UTC', error)
|
|
28
|
-
return 'UTC'
|
|
29
|
-
}
|
|
30
|
-
})()
|
|
32
|
+
const timezone = resolvedTimezone
|
|
31
33
|
|
|
32
34
|
const options = {
|
|
33
35
|
method: 'GET',
|