From 0766e6cb366a464327c8e20f2da987e71d5bcebc Mon Sep 17 00:00:00 2001 From: Rob Loranger Date: Tue, 14 Jan 2020 10:44:56 -0800 Subject: [PATCH 1/2] fixes imported post times changes the client side to round the unix time to avoid floats alters the time to match the client time zone on the server side --- account_import.go | 8 ++++++++ templates/user/import.tmpl | 5 ++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/account_import.go b/account_import.go index b34f3a7..1098798 100644 --- a/account_import.go +++ b/account_import.go @@ -9,6 +9,7 @@ import ( "net/http" "os" "path/filepath" + "strconv" "strings" "time" @@ -85,6 +86,7 @@ func handleImport(app *App, u *User, w http.ResponseWriter, r *http.Request) err log.Error("invalid form data for file dates: %v", err) return impart.HTTPError{http.StatusBadRequest, "form data for file dates was invalid"} } + fileTZ := r.FormValue("tz") files := r.MultipartForm.File["files"] var fileErrs []error filesSubmitted := len(files) @@ -147,6 +149,12 @@ func handleImport(app *App, u *User, w http.ResponseWriter, r *http.Request) err post.Collection = collAlias } dateTime := time.Unix(fileDates[formFile.Filename], 0) + offset, err := strconv.Atoi(fileTZ) + if err != nil { + log.Error("form time zone offset not a valid integer: %v", err) + continue + } + dateTime = dateTime.Add(time.Minute * time.Duration(offset)) post.Created = &dateTime created := post.Created.Format("2006-01-02T15:04:05Z") submittedPost := SubmittedPost{ diff --git a/templates/user/import.tmpl b/templates/user/import.tmpl index 3400e2f..06ff8b7 100644 --- a/templates/user/import.tmpl +++ b/templates/user/import.tmpl @@ -32,6 +32,7 @@ +