@@ -191,7 +191,7 @@ export const InfoBox: React.FC<InfoBoxProps> = ({ gameID }: InfoBoxProps) => {
191191 const dateStr = `${ year } -${ month } -${ day } ` ;
192192 result . push ( {
193193 date : dateStr ,
194- playtime : datePlaytimeMap . get ( dateStr ) || 0 ,
194+ playtime : datePlaytimeMap . get ( dateStr ) ?? 0 ,
195195 } ) ;
196196 }
197197 } else if ( timeRange === "MONTH" ) {
@@ -205,15 +205,15 @@ export const InfoBox: React.FC<InfoBoxProps> = ({ gameID }: InfoBoxProps) => {
205205 const dateStr = `${ year } -${ String ( month ) . padStart ( 2 , "0" ) } -${ String ( day ) . padStart ( 2 , "0" ) } ` ;
206206 result . push ( {
207207 date : dateStr ,
208- playtime : datePlaytimeMap . get ( dateStr ) || 0 ,
208+ playtime : datePlaytimeMap . get ( dateStr ) ?? 0 ,
209209 } ) ;
210210 }
211211 } else if ( timeRange === "1Y" ) {
212212 // 1年:按月聚合
213213 const monthlyMap = new Map < string , number > ( ) ;
214214 for ( const [ dateStr , playtime ] of datePlaytimeMap ) {
215215 const monthKey = dateStr . substring ( 0 , 7 ) ; // YYYY-MM
216- monthlyMap . set ( monthKey , ( monthlyMap . get ( monthKey ) || 0 ) + playtime ) ;
216+ monthlyMap . set ( monthKey , ( monthlyMap . get ( monthKey ) ?? 0 ) + playtime ) ;
217217 }
218218
219219 // 生成过去12个月(修复跨年问题)
@@ -224,35 +224,35 @@ export const InfoBox: React.FC<InfoBoxProps> = ({ gameID }: InfoBoxProps) => {
224224 const monthKey = `${ year } -${ month } ` ;
225225 result . push ( {
226226 date : monthKey ,
227- playtime : monthlyMap . get ( monthKey ) || 0 ,
227+ playtime : monthlyMap . get ( monthKey ) ?? 0 ,
228228 } ) ;
229229 }
230230 } else if ( timeRange === "ALL" ) {
231231 // 全部:判断数据量决定是否按月聚合
232- const allDates = Array . from ( datePlaytimeMap . keys ( ) ) . sort ( ) ;
232+ const allDates = Array . from ( datePlaytimeMap . keys ( ) ) . toSorted ( ) ;
233233
234234 if ( allDates . length > 60 ) {
235235 // 数据点较多,按月聚合
236236 const monthlyMap = new Map < string , number > ( ) ;
237237 for ( const [ dateStr , playtime ] of datePlaytimeMap ) {
238238 const monthKey = dateStr . substring ( 0 , 7 ) ; // YYYY-MM
239- monthlyMap . set ( monthKey , ( monthlyMap . get ( monthKey ) || 0 ) + playtime ) ;
239+ monthlyMap . set ( monthKey , ( monthlyMap . get ( monthKey ) ?? 0 ) + playtime ) ;
240240 }
241241
242242 // 按月排序输出
243- const sortedMonths = Array . from ( monthlyMap . keys ( ) ) . sort ( ) ;
243+ const sortedMonths = Array . from ( monthlyMap . keys ( ) ) . toSorted ( ) ;
244244 for ( const monthKey of sortedMonths ) {
245245 result . push ( {
246246 date : monthKey ,
247- playtime : monthlyMap . get ( monthKey ) || 0 ,
247+ playtime : monthlyMap . get ( monthKey ) ?? 0 ,
248248 } ) ;
249249 }
250250 } else {
251251 // 数据点较少,按天显示
252252 for ( const dateStr of allDates ) {
253253 result . push ( {
254254 date : dateStr ,
255- playtime : datePlaytimeMap . get ( dateStr ) || 0 ,
255+ playtime : datePlaytimeMap . get ( dateStr ) ?? 0 ,
256256 } ) ;
257257 }
258258 }
0 commit comments