修正完成日期時間格式
This commit is contained in:
@@ -34,6 +34,12 @@ export async function POST(request: NextRequest) {
|
||||
console.log('總分:', overallScore)
|
||||
console.log('等級:', level)
|
||||
|
||||
// 統一使用台灣時間格式
|
||||
// 將 UTC 時間轉換為台灣時間,然後轉換為 MySQL 格式
|
||||
const utcDate = new Date(completedAt)
|
||||
const taiwanTime = new Date(utcDate.getTime() + (8 * 60 * 60 * 1000)) // UTC + 8 小時
|
||||
const mysqlCompletedAt = taiwanTime.toISOString().replace('Z', '').replace('T', ' ')
|
||||
|
||||
// 建立綜合測試結果
|
||||
const testResult = await createCombinedTestResult({
|
||||
user_id: userId,
|
||||
@@ -45,7 +51,7 @@ export async function POST(request: NextRequest) {
|
||||
logic_breakdown: logicBreakdown || null,
|
||||
creativity_breakdown: creativityBreakdown || null,
|
||||
balance_score: balanceScore || 0,
|
||||
completed_at: completedAt
|
||||
completed_at: mysqlCompletedAt
|
||||
})
|
||||
|
||||
if (!testResult) {
|
||||
|
@@ -69,13 +69,19 @@ export async function POST(request: NextRequest) {
|
||||
completed_at: completedAt
|
||||
})
|
||||
|
||||
// 統一使用台灣時間格式
|
||||
// 將 UTC 時間轉換為台灣時間,然後轉換為 MySQL 格式
|
||||
const utcDate = new Date(completedAt)
|
||||
const taiwanTime = new Date(utcDate.getTime() + (8 * 60 * 60 * 1000)) // UTC + 8 小時
|
||||
const mysqlCompletedAt = taiwanTime.toISOString().replace('Z', '').replace('T', ' ')
|
||||
|
||||
const testResult = await createTestResult({
|
||||
user_id: userId,
|
||||
test_type: 'creative',
|
||||
score: scorePercentage,
|
||||
total_questions: questions.length,
|
||||
correct_answers: totalScore,
|
||||
completed_at: completedAt
|
||||
completed_at: mysqlCompletedAt
|
||||
})
|
||||
|
||||
console.log('測試結果建立結果:', testResult)
|
||||
|
@@ -63,13 +63,19 @@ export async function POST(request: NextRequest) {
|
||||
completed_at: completedAt
|
||||
})
|
||||
|
||||
// 統一使用台灣時間格式
|
||||
// 將 UTC 時間轉換為台灣時間,然後轉換為 MySQL 格式
|
||||
const utcDate = new Date(completedAt)
|
||||
const taiwanTime = new Date(utcDate.getTime() + (8 * 60 * 60 * 1000)) // UTC + 8 小時
|
||||
const mysqlCompletedAt = taiwanTime.toISOString().replace('Z', '').replace('T', ' ')
|
||||
|
||||
const testResult = await createTestResult({
|
||||
user_id: userId,
|
||||
test_type: 'logic',
|
||||
score: score,
|
||||
total_questions: questions.length,
|
||||
correct_answers: correctAnswers,
|
||||
completed_at: completedAt
|
||||
completed_at: mysqlCompletedAt
|
||||
})
|
||||
|
||||
console.log('測試結果建立結果:', testResult)
|
||||
|
@@ -243,7 +243,7 @@ export default function CombinedResultsPage() {
|
||||
<div>
|
||||
<h1 className="text-xl font-bold text-foreground">綜合能力測試結果</h1>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
完成時間:{new Date(results.completedAt).toLocaleString("zh-TW", { timeZone: "Asia/Taipei" })}
|
||||
完成時間:{new Date(results.completedAt).toLocaleString("zh-TW")}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
@@ -41,8 +41,9 @@ export default function CreativeResultsPage() {
|
||||
const data = await response.json()
|
||||
|
||||
if (data.success && data.data.length > 0) {
|
||||
// 取最新的結果
|
||||
const latestResult = data.data[0]
|
||||
// 按創建時間排序,取最新的結果
|
||||
const sortedResults = data.data.sort((a, b) => new Date(b.created_at) - new Date(a.created_at))
|
||||
const latestResult = sortedResults[0]
|
||||
|
||||
// 獲取題目資料來計算各維度分數
|
||||
const questionsResponse = await fetch('/api/creative-questions')
|
||||
@@ -263,7 +264,7 @@ export default function CreativeResultsPage() {
|
||||
<div>
|
||||
<h1 className="text-xl font-bold text-foreground">創意能力測試結果</h1>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
完成時間:{new Date(results.completedAt).toLocaleString("zh-TW", { timeZone: "Asia/Taipei" })}
|
||||
完成時間:{new Date(results.completedAt).toLocaleString("zh-TW")}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
@@ -138,7 +138,7 @@ export default function LogicResultsPage() {
|
||||
<div>
|
||||
<h1 className="text-xl font-bold text-foreground">邏輯思維測試結果</h1>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
完成時間:{new Date(results.completedAt).toLocaleString("zh-TW", { timeZone: "Asia/Taipei" })}
|
||||
完成時間:{new Date(results.completedAt).toLocaleString("zh-TW")}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
@@ -264,7 +264,7 @@ function ResultsContent() {
|
||||
<div className="min-w-0 flex-1">
|
||||
<h3 className="font-medium text-foreground">{testInfo.name}</h3>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
完成時間:{new Date(result.completedAt).toLocaleString("zh-TW", { timeZone: "Asia/Taipei" })}
|
||||
完成時間:{new Date(result.completedAt).toLocaleString("zh-TW")}
|
||||
</p>
|
||||
{result.testCount && result.testCount > 1 && (
|
||||
<p className="text-xs text-muted-foreground mt-1">
|
||||
|
Reference in New Issue
Block a user