mirror of
https://github.com/OpenListTeam/OpenList.git
synced 2026-10-10 21:13:10 +08:00
e80ee006ad
fix(drivers/189): support updated 189 time format with comma, timezone and unicode spaces 189 API 变更了时间返回格式,现有 Time.Unmarshal 无法解析,导致 189pc/189_tv 驱动所有写操作失败(Put → 500)。 新格式有三种形态,现有两个模板均无法覆盖: 1. "Aug 11, 2026, 10:37:18 PM +08" — 年份后多逗号,且自带时区 2. "Aug 12, 2026, 12:35:41\u202fAM +08" — AM/PM 前为 U+202F 窄不换行空格 3. "Aug 12, 2026, 12:35:41\u00a0AM +08" — AM/PM 前为 U+00A0 不换行空格 修复(189pc/help.go、189_tv/help.go 的 Time.Unmarshal): - 解析前将 U+202F 和 U+00A0 统一替换为普通空格 - 新增模板 "Jan 2, 2006, 3:04:05 PM -07"(带逗号,3 为 12 小时制配 PM) - 对可能不带时区的串,先试原串再试追加 " +08"(向后兼容) 新增 help_test.go 覆盖:数字日期、旧月份格式、新格式带/不带时区、 U+202F/U+00A0 空格、非法输入。 Fixes #2917 Generated-By: pi 0.84.1 Co-authored-by: Advanced <noreply@pi.dev>
40 lines
1.4 KiB
Go
40 lines
1.4 KiB
Go
package _189_tv
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestTimeUnmarshal(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
input string
|
|
want time.Time
|
|
}{
|
|
{"numeric date", `"2026-08-11 10:37:18"`, time.Date(2026, 8, 11, 10, 37, 18, 0, time.FixedZone("", 8*3600))},
|
|
{"legacy month date", `"Aug 11, 2026 10:37:18 PM"`, time.Date(2026, 8, 11, 22, 37, 18, 0, time.FixedZone("", 8*3600))},
|
|
{"new format with tz", `"Aug 11, 2026, 10:37:18 PM +08"`, time.Date(2026, 8, 11, 22, 37, 18, 0, time.FixedZone("", 8*3600))},
|
|
{"new format no tz", `"Aug 11, 2026, 10:37:18 PM"`, time.Date(2026, 8, 11, 22, 37, 18, 0, time.FixedZone("", 8*3600))},
|
|
{"narrow no-break space (U+202F)", "\"Aug 12, 2026, 12:35:41\u202fAM +08\"", time.Date(2026, 8, 12, 0, 35, 41, 0, time.FixedZone("", 8*3600))},
|
|
{"no-break space (U+00A0)", "\"Aug 12, 2026, 12:35:41\u00a0AM +08\"", time.Date(2026, 8, 12, 0, 35, 41, 0, time.FixedZone("", 8*3600))},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
var tm Time
|
|
if err := tm.Unmarshal([]byte(tt.input)); err != nil {
|
|
t.Fatalf("Unmarshal(%s) error: %v", tt.input, err)
|
|
}
|
|
if !tt.want.Equal(time.Time(tm)) {
|
|
t.Fatalf("Unmarshal(%s) = %v, want %v", tt.input, time.Time(tm), tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestTimeUnmarshalRejectsInvalid(t *testing.T) {
|
|
var tm Time
|
|
if err := tm.Unmarshal([]byte("Aug 12, 2026, 25:32:44 AM")); err == nil {
|
|
t.Fatal("Unmarshal accepted an invalid time")
|
|
}
|
|
}
|