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:
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user