mirror of
https://github.com/Wei-Shaw/claude-relay-service.git
synced 2026-01-23 09:38:02 +00:00
fix: 修复自定义过期时间的时区解析问题
修复 datetime-local 输入框在不同浏览器中时区解析不一致的问题。 ## 问题 - datetime-local 返回无时区信息的字符串 (如: 2025-12-31T23:59) - new Date(string) 在不同浏览器中解析行为不一致 - 部分浏览器错误地将其解释为 UTC,导致时区偏移 ## 解决方案 - 手动解析日期时间字符串的各个部分 - 使用 Date 构造函数明确创建本地时间对象 - 统一转换为 UTC ISO 字符串存储 - 添加日期有效性验证和错误处理 ## 影响范围 - 仅影响自定义过期时间设置功能 - 确保用户设置的时间与存储/显示一致 - 提升跨浏览器兼容性 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -304,7 +304,25 @@ const selectQuickOption = (value) => {
|
|||||||
// 更新自定义过期时间
|
// 更新自定义过期时间
|
||||||
const updateCustomExpiryPreview = () => {
|
const updateCustomExpiryPreview = () => {
|
||||||
if (localForm.customExpireDate) {
|
if (localForm.customExpireDate) {
|
||||||
localForm.expiresAt = new Date(localForm.customExpireDate).toISOString()
|
try {
|
||||||
|
// 手动解析日期时间字符串,确保它被正确解释为本地时间
|
||||||
|
const [datePart, timePart] = localForm.customExpireDate.split('T')
|
||||||
|
const [year, month, day] = datePart.split('-').map(Number)
|
||||||
|
const [hours, minutes] = timePart.split(':').map(Number)
|
||||||
|
|
||||||
|
// 使用构造函数创建本地时间的 Date 对象,然后转换为 UTC ISO 字符串
|
||||||
|
const localDate = new Date(year, month - 1, day, hours, minutes, 0, 0)
|
||||||
|
|
||||||
|
// 验证日期有效性
|
||||||
|
if (isNaN(localDate.getTime())) {
|
||||||
|
console.error('Invalid date:', localForm.customExpireDate)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
localForm.expiresAt = localDate.toISOString()
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Failed to parse custom expire date:', error)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user