球局日期优化

This commit is contained in:
2025-09-17 17:30:22 +08:00
parent eeb1ac07c8
commit 9f4e026687
2 changed files with 33 additions and 17 deletions

View File

@@ -124,7 +124,7 @@ export class UserService {
private static transform_game_data(backend_data: BackendGameData[]): any[] {
return backend_data.map(game => {
// 处理时间格式
const start_time = new Date(game.start_time);
const start_time = new Date(game.start_time.replace(/\s/, 'T'));
const date_time = this.format_date_time(start_time);
// 处理图片数组 - 兼容两种数据格式
@@ -161,6 +161,7 @@ export class UserService {
id: game.id,
title: game.title || '未命名球局',
start_time: date_time,
end_time: game.end_time || '',
location: location,
distance_km: parseFloat(distance.replace('km', '')) || 0,
current_players: registered_count,
@@ -177,14 +178,23 @@ export class UserService {
});
}
private static is_date_in_this_week(date: Date): boolean {
const today = new Date();
const firstDayOfWeek = new Date(today.setDate(today.getDate() - today.getDay()));
const lastDayOfWeek = new Date(firstDayOfWeek.setDate(firstDayOfWeek.getDate() + 6));
return date >= firstDayOfWeek && date <= lastDayOfWeek;
}
// 格式化时间显示
private static format_date_time(start_time: Date): string {
const now = new Date();
const today = new Date(now.getFullYear(), now.getMonth(), now.getDate());
const today = new Date(now.getFullYear(), now.getMonth() + 1, now.getDate());
const tomorrow = new Date(today.getTime() + 24 * 60 * 60 * 1000);
const day_after_tomorrow = new Date(today.getTime() + 2 * 24 * 60 * 60 * 1000);
const weekdays = ['周日', '周一', '周二', '周三', '周四', '周五', '周六'];
const start_date = new Date(start_time.getFullYear(), start_time.getMonth(), start_time.getDate());
const start_date = new Date(start_time.getFullYear(), start_time.getMonth() + 1, start_time.getDate());
let date_str = '';
if (start_date.getTime() === today.getTime()) {
@@ -193,9 +203,10 @@ export class UserService {
date_str = '明天';
} else if (start_date.getTime() === day_after_tomorrow.getTime()) {
date_str = '后天';
} else {
const weekdays = ['周日', '周一', '周二', '周三', '周四', '周五', '周六'];
} else if(this.is_date_in_this_week(start_time)) {
date_str = weekdays[start_time.getDay()];
} else {
date_str = `${start_time.getFullYear()}-${(start_time.getMonth() + 1).toString().padStart(2, '0')}-${start_time.getDate().toString().padStart(2, '0')}`;
}
const time_str = `${start_time.getHours().toString().padStart(2, '0')}:${start_time.getMinutes().toString().padStart(2, '0')}`;