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,

View File

@@ -1,7 +1,7 @@
import {
formatLocalMatchDateTime,
isAfterLocalToday,
isInLocalToday,
isAfterLocalTodayMatchWindow,
isInLocalTodayMatchWindow,
isoToPlatformPickerDateTime,
platformPickerDateTimeToIso,
} from '@thebet365/shared';
@@ -32,10 +32,17 @@ describe('match time helpers', () => {
expect(malaysia).not.toBe(newYork);
});
it('uses the player local day for today and early buckets', () => {
it('keeps early next-day matches in the player today bucket until local noon', () => {
const now = new Date('2026-06-11T15:00:00-04:00');
expect(isInLocalToday('2026-06-12T02:00:00.000Z', now, 'America/New_York')).toBe(true);
expect(isAfterLocalToday('2026-06-12T05:00:00.000Z', now, 'America/New_York')).toBe(true);
expect(isInLocalTodayMatchWindow('2026-06-12T02:00:00.000Z', now, 'America/New_York')).toBe(
true,
);
expect(isInLocalTodayMatchWindow('2026-06-12T15:59:59.000Z', now, 'America/New_York')).toBe(
true,
);
expect(isAfterLocalTodayMatchWindow('2026-06-12T16:00:00.000Z', now, 'America/New_York')).toBe(
true,
);
});
});

View File

@@ -1,5 +1,5 @@
export {
isAfterLocalToday as isAfterTodayMatchWindow,
isInLocalToday as isInTodayMatchWindow,
isAfterLocalTodayMatchWindow as isAfterTodayMatchWindow,
isInLocalTodayMatchWindow as isInTodayMatchWindow,
isSameLocalCalendarDay as isSameCalendarDay,
} from '@thebet365/shared';

View File

@@ -11,8 +11,8 @@ import GoldSpinner from '../components/GoldSpinner.vue';
import { usePullToRefresh } from '../composables/usePullToRefresh';
import type { MatchPhase } from '../utils/matchPhase';
import {
isAfterLocalToday as isAfterTodayMatchWindow,
isInLocalToday as isInTodayMatchWindow,
isAfterLocalTodayMatchWindow as isAfterTodayMatchWindow,
isInLocalTodayMatchWindow as isInTodayMatchWindow,
} from '@thebet365/shared';
type MainTab = 'matches' | 'outright';