接口添加时间与时区&赔率

This commit is contained in:
xianyi
2026-01-14 15:14:09 +08:00
parent 1bd10694bf
commit 8dc87c9b29
7 changed files with 149 additions and 13 deletions

View File

@@ -34,6 +34,15 @@ export default function HomeScreen() {
const [loadingLeagues, setLoadingLeagues] = useState(false);
const [now, setNow] = useState(() => new Date());
const deviceTimeZone = useMemo(() => {
try {
console.log("deviceTimeZone", Intl.DateTimeFormat().resolvedOptions().timeZone);
return Intl.DateTimeFormat().resolvedOptions().timeZone || "UTC";
} catch {
return "UTC";
}
}, []);
// Selection States
// 默认足球
const [selectedSportId, setSelectedSportId] = useState<number | null>(1);
@@ -158,7 +167,7 @@ export default function HomeScreen() {
const loadMatches = async (sportId: number) => {
setLoading(true);
try {
const list = await fetchTodayMatches(sportId, selectedDate);
const list = await fetchTodayMatches(sportId, selectedDate, deviceTimeZone);
setMatches(list);
} catch (e) {
console.error(e);

View File

@@ -10,7 +10,7 @@ import { Colors } from "@/constants/theme";
import { useTheme } from "@/context/ThemeContext";
import { fetchLeagues, fetchSports, fetchTodayMatches } from "@/lib/api";
import { League, Match, Sport } from "@/types/api";
import React, { useEffect, useState } from "react";
import React, { useEffect, useMemo, useState } from "react";
import { useTranslation } from "react-i18next";
import {
ActivityIndicator,
@@ -32,6 +32,14 @@ export default function HomeScreen() {
const [matches, setMatches] = useState<Match[]>([]);
const [loading, setLoading] = useState(true);
const deviceTimeZone = useMemo(() => {
try {
return Intl.DateTimeFormat().resolvedOptions().timeZone || "UTC";
} catch {
return "UTC";
}
}, []);
// Selection States
// 默认足球
const [selectedSportId, setSelectedSportId] = useState<number | null>(1);
@@ -131,7 +139,7 @@ export default function HomeScreen() {
setLoading(true);
try {
// Pass selectedDate if API supported it
const list = await fetchTodayMatches(sportId);
const list = await fetchTodayMatches(sportId, undefined, deviceTimeZone);
setMatches(list);
} catch (e) {
console.error(e);