mirror of
https://github.com/writefreely/writefreely
synced 2024-11-24 17:43:05 +00:00
move timezone correction to client side
This commit is contained in:
parent
0766e6cb36
commit
571460f08d
2 changed files with 4 additions and 12 deletions
|
@ -9,7 +9,6 @@ import (
|
|||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
|
@ -86,7 +85,6 @@ 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)
|
||||
|
@ -149,12 +147,6 @@ 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{
|
||||
|
|
|
@ -32,7 +32,6 @@
|
|||
<input id="fileInput" class="fileInput" name="files" type="file" multiple accept="text/markdown, text/plain"/>
|
||||
</label>
|
||||
<input id="fileDates" name="fileDates" hidden/>
|
||||
<input id="tzInput" name="tz" hidden/>
|
||||
<label>
|
||||
Import these posts to:
|
||||
<select name="collection">
|
||||
|
@ -43,15 +42,16 @@
|
|||
</select>
|
||||
</label>
|
||||
<script>
|
||||
const tzInput = document.getElementById('tzInput');
|
||||
tzInput.value = new Date().getTimezoneOffset();
|
||||
// timezone offset in seconds
|
||||
const tzOffsetSec = new Date().getTimezoneOffset() * 60;
|
||||
const fileInput = document.getElementById('fileInput');
|
||||
const fileDates = document.getElementById('fileDates');
|
||||
fileInput.addEventListener('change', (e) => {
|
||||
const files = e.target.files;
|
||||
let dateMap = {};
|
||||
for (let file of files) {
|
||||
dateMap[file.name] = Math.round(file.lastModified / 1000);
|
||||
// convert from milliseconds to seconds and adjust for tz
|
||||
dateMap[file.name] = Math.round(file.lastModified / 1000) + tzOffsetSec;
|
||||
}
|
||||
fileDates.value = JSON.stringify(dateMap);
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue