refactor: update match time utilities and improve local match window logic

- Introduced new functions `isInLocalTodayMatchWindow` and `isAfterLocalTodayMatchWindow` to enhance match time checks.
- Replaced the deprecated `dayKeyInTimeZone` function with `isInLocalTodayMatchWindow` in the PlayerController.
- Updated related tests and utility exports to reflect the new naming conventions.
- Improved handling of local match windows in various components for better accuracy.
This commit is contained in:
wchino
2026-06-13 18:20:26 +08:00
parent 7b33d9f9fa
commit 21dd9957f0
5 changed files with 99 additions and 22 deletions

View File

@@ -30,6 +30,7 @@ import { BetsService } from '../../domains/betting/bets.service';
import { ContentService } from '../../domains/operations/content/content.service';
import { CashbackService } from '../../domains/operations/cashback/cashback.service';
import { DepositService } from '../../domains/deposit/deposit.service';
import { isInLocalTodayMatchWindow } from '@thebet365/shared';
import { IsString, IsNumber, IsArray, ValidateNested, Min, IsOptional } from 'class-validator';
import { Type } from 'class-transformer';
@@ -104,17 +105,6 @@ function safeTimeZone(input?: string): string {
}
}
function dayKeyInTimeZone(date: Date, timeZone: string): string {
const parts = new Intl.DateTimeFormat('en-US', {
timeZone,
year: 'numeric',
month: '2-digit',
day: '2-digit',
}).formatToParts(date);
const map = new Map(parts.map((part) => [part.type, part.value]));
return `${map.get('year')}-${map.get('month')}-${map.get('day')}`;
}
@ApiTags('Player')
@Controller('player')
@UseGuards(JwtAuthGuard, PlayerGuard)
@@ -191,11 +181,11 @@ export class PlayerController {
this.matches.listPublished(locale, undefined, { includeMarkets: false }),
]);
const timeZone = safeTimeZone(headerTimeZone);
const todayKey = dayKeyInTimeZone(new Date(), timeZone);
const now = new Date();
const hotMatches = (allMatches as Array<{ isHot?: boolean }>).filter((m) => m.isHot);
const todayMatches = (allMatches as Array<{ startTime: string }>).filter((m) => {
const kickoff = new Date(m.startTime);
return !Number.isNaN(kickoff.getTime()) && dayKeyInTimeZone(kickoff, timeZone) === todayKey;
return !Number.isNaN(kickoff.getTime()) && isInLocalTodayMatchWindow(kickoff, now, timeZone);
});
return jsonResponse({
banners,