mirror of
https://github.com/xiaoqidun/ofdgo.git
synced 2026-10-30 01:27:26 +08:00
1 parent
764e8a750a
commit
580592bbf8
2 files changed
+13
-6
No files matched your search
@@ -22,7 +22,7 @@ import (
|
|||||||
"github.com/xiaoqidun/pdfgo"
|
"github.com/xiaoqidun/pdfgo"
|
||||||
)
|
)
|
||||||
|
|
||||||
// NormalizeDate 校验PDF日期,非严格模式补齐完整时区偏移的分隔符
|
// NormalizeDate 校验PDF日期,非严格模式修正单层外括号及完整时区偏移的分隔符
|
||||||
// 入参: text PDF日期字符串, strict 是否严格校验
|
// 入参: text PDF日期字符串, strict 是否严格校验
|
||||||
// 返回: string 标准日期字符串, error 日期错误
|
// 返回: string 标准日期字符串, error 日期错误
|
||||||
func NormalizeDate(text string, strict bool) (string, error) {
|
func NormalizeDate(text string, strict bool) (string, error) {
|
||||||
@@ -33,16 +33,23 @@ func NormalizeDate(text string, strict bool) (string, error) {
|
|||||||
if err == nil || strict {
|
if err == nil || strict {
|
||||||
return text, err
|
return text, err
|
||||||
}
|
}
|
||||||
offset := len(text) - 5
|
normalized := text
|
||||||
if offset < 6 || text[offset] != '+' && text[offset] != '-' {
|
if strings.HasPrefix(normalized, "(") && strings.HasSuffix(normalized, ")") {
|
||||||
|
normalized = normalized[1 : len(normalized)-1]
|
||||||
|
if _, parseErr := pdfgo.ParseDate(normalized); parseErr == nil {
|
||||||
|
return normalized, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
offset := len(normalized) - 5
|
||||||
|
if offset < 6 || normalized[offset] != '+' && normalized[offset] != '-' {
|
||||||
return text, err
|
return text, err
|
||||||
}
|
}
|
||||||
for _, digit := range text[offset+1:] {
|
for _, digit := range normalized[offset+1:] {
|
||||||
if digit < '0' || digit > '9' {
|
if digit < '0' || digit > '9' {
|
||||||
return text, err
|
return text, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
normalized := text[:offset+3] + "'" + text[offset+3:] + "'"
|
normalized = normalized[:offset+3] + "'" + normalized[offset+3:] + "'"
|
||||||
if _, parseErr := pdfgo.ParseDate(normalized); parseErr != nil {
|
if _, parseErr := pdfgo.ParseDate(normalized); parseErr != nil {
|
||||||
return text, err
|
return text, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -927,7 +927,7 @@ func (p *pdfImporter) documentMetadata(ctx context.Context, strict bool) error {
|
|||||||
return fmt.Errorf("PDF metadata %s: %w", field.name, err)
|
return fmt.Errorf("PDF metadata %s: %w", field.name, err)
|
||||||
}
|
}
|
||||||
if text != *field.text {
|
if text != *field.text {
|
||||||
p.report.Warnings = append(p.report.Warnings, pdfgo.Diagnostic{Message: "PDF metadata " + field.name + ": time zone separators normalized"})
|
p.report.Warnings = append(p.report.Warnings, pdfgo.Diagnostic{Message: "PDF metadata " + field.name + ": date normalized"})
|
||||||
*field.text = text
|
*field.text = text
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user