mirror of
https://github.com/sajari/docconv.git
synced 2026-10-16 21:21:59 +08:00
pdf: add extra time layout for pdfs
This commit is contained in:
committed by
David Howden
parent
e3975370dc
commit
1fd4d7a6c8
+18
-7
@@ -40,16 +40,13 @@ func ConvertPDFText(path string) (BodyResult, MetaResult, error) {
|
||||
}
|
||||
|
||||
// Convert parsed meta
|
||||
if tmp, ok := metaResult.meta["Author"]; ok {
|
||||
metaResult.meta["Author"] = tmp
|
||||
}
|
||||
if tmp, ok := metaResult.meta["ModDate"]; ok {
|
||||
if t, err := time.Parse(time.ANSIC, tmp); err == nil {
|
||||
if x, ok := metaResult.meta["ModDate"]; ok {
|
||||
if t, ok := pdfTimeLayouts.Parse(x); ok {
|
||||
metaResult.meta["ModifiedDate"] = fmt.Sprintf("%d", t.Unix())
|
||||
}
|
||||
}
|
||||
if tmp, ok := metaResult.meta["CreationDate"]; ok {
|
||||
if t, err := time.Parse(time.ANSIC, tmp); err == nil {
|
||||
if x, ok := metaResult.meta["CreationDate"]; ok {
|
||||
if t, ok := pdfTimeLayouts.Parse(x); ok {
|
||||
metaResult.meta["CreatedDate"] = fmt.Sprintf("%d", t.Unix())
|
||||
}
|
||||
}
|
||||
@@ -71,3 +68,17 @@ func ConvertPDFText(path string) (BodyResult, MetaResult, error) {
|
||||
|
||||
return <-br, <-mr, nil
|
||||
}
|
||||
|
||||
var pdfTimeLayouts = timeLayouts{time.ANSIC, "Mon Jan _2 15:04:05 2006 MST"}
|
||||
|
||||
type timeLayouts []string
|
||||
|
||||
func (tl timeLayouts) Parse(x string) (time.Time, bool) {
|
||||
for _, layout := range tl {
|
||||
t, err := time.Parse(layout, x)
|
||||
if err == nil {
|
||||
return t, true
|
||||
}
|
||||
}
|
||||
return time.Time{}, false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user