const https = require('https') const http = require('http') const checkLatestCreativeTime = async () => { console.log('šŸ” ęŖ¢ęŸ„ęœ€ę–°å‰µę„ęø¬é©—ēµęžœę™‚é–“') console.log('=' .repeat(50)) const userId = 'user-1759073326705-m06y3wacd' try { // ęŖ¢ęŸ„å‰µę„ęø¬č©¦ēµęžœ API console.log('\nšŸ“Š ęŖ¢ęŸ„å‰µę„ęø¬č©¦ēµęžœ API...') const response = await new Promise((resolve, reject) => { const req = http.get(`http://localhost:3000/api/test-results/creative?userId=${userId}`, (res) => { let data = '' res.on('data', chunk => data += chunk) res.on('end', () => resolve({ status: res.statusCode, data })) }) req.on('error', reject) }) if (response.status === 200) { const data = JSON.parse(response.data) if (data.success && data.data.length > 0) { console.log(`ę‰¾åˆ° ${data.data.length} ē­†å‰µę„ęø¬č©¦ēµęžœ:`) // ęŒ‰å‰µå»ŗę™‚é–“ęŽ’åŗļ¼Œå–ęœ€ę–°ēš„ const sortedResults = data.data.sort((a, b) => new Date(b.created_at) - new Date(a.created_at)) const latestResult = sortedResults[0] console.log('\nšŸ“‹ ęœ€ę–°å‰µę„ęø¬č©¦ēµęžœ:') console.log(`ID: ${latestResult.id}`) console.log(`completed_at: ${latestResult.completed_at}`) console.log(`created_at: ${latestResult.created_at}`) const completedDate = new Date(latestResult.completed_at) const createdDate = new Date(latestResult.created_at) console.log(`completed_at å°ē£ę™‚é–“: ${completedDate.toLocaleString("zh-TW", { timeZone: "Asia/Taipei" })}`) console.log(`created_at å°ē£ę™‚é–“: ${createdDate.toLocaleString("zh-TW", { timeZone: "Asia/Taipei" })}`) // ęŖ¢ęŸ„ę™‚é–“å·® const timeDiff = createdDate.getTime() - completedDate.getTime() const hoursDiff = timeDiff / (1000 * 60 * 60) console.log(`時間差: ${hoursDiff.toFixed(2)} å°ę™‚`) // 檢柄是否是今天 const now = new Date() const isToday = now.toDateString() === completedDate.toDateString() console.log(`ę˜Æå¦ē‚ŗä»Šå¤©: ${isToday}`) // čØˆē®—č·é›¢ē¾åœØēš„ę™‚é–“ const nowDiff = now.getTime() - completedDate.getTime() const nowHoursDiff = nowDiff / (1000 * 60 * 60) console.log(`č·é›¢ē¾åœØ: ${nowHoursDiff.toFixed(2)} å°ę™‚`) } } // ęŖ¢ęŸ„ē•¶å‰ę™‚é–“ console.log('\nšŸ“Š ē•¶å‰ę™‚é–“:') const now = new Date() console.log(`UTC Ꙃ間: ${now.toISOString()}`) console.log(`å°ē£ę™‚é–“: ${now.toLocaleString("zh-TW", { timeZone: "Asia/Taipei" })}`) } catch (error) { console.error('āŒ ęŖ¢ęŸ„å¤±ę•—:', error.message) } finally { console.log('\nāœ… ęœ€ę–°å‰µę„ęø¬é©—ēµęžœę™‚é–“ęŖ¢ęŸ„å®Œęˆ') } } checkLatestCreativeTime()