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"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"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)
|
log.Error("invalid form data for file dates: %v", err)
|
||||||
return impart.HTTPError{http.StatusBadRequest, "form data for file dates was invalid"}
|
return impart.HTTPError{http.StatusBadRequest, "form data for file dates was invalid"}
|
||||||
}
|
}
|
||||||
fileTZ := r.FormValue("tz")
|
|
||||||
files := r.MultipartForm.File["files"]
|
files := r.MultipartForm.File["files"]
|
||||||
var fileErrs []error
|
var fileErrs []error
|
||||||
filesSubmitted := len(files)
|
filesSubmitted := len(files)
|
||||||
|
@ -149,12 +147,6 @@ func handleImport(app *App, u *User, w http.ResponseWriter, r *http.Request) err
|
||||||
post.Collection = collAlias
|
post.Collection = collAlias
|
||||||
}
|
}
|
||||||
dateTime := time.Unix(fileDates[formFile.Filename], 0)
|
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
|
post.Created = &dateTime
|
||||||
created := post.Created.Format("2006-01-02T15:04:05Z")
|
created := post.Created.Format("2006-01-02T15:04:05Z")
|
||||||
submittedPost := SubmittedPost{
|
submittedPost := SubmittedPost{
|
||||||
|
|
|
@ -32,7 +32,6 @@
|
||||||
<input id="fileInput" class="fileInput" name="files" type="file" multiple accept="text/markdown, text/plain"/>
|
<input id="fileInput" class="fileInput" name="files" type="file" multiple accept="text/markdown, text/plain"/>
|
||||||
</label>
|
</label>
|
||||||
<input id="fileDates" name="fileDates" hidden/>
|
<input id="fileDates" name="fileDates" hidden/>
|
||||||
<input id="tzInput" name="tz" hidden/>
|
|
||||||
<label>
|
<label>
|
||||||
Import these posts to:
|
Import these posts to:
|
||||||
<select name="collection">
|
<select name="collection">
|
||||||
|
@ -43,15 +42,16 @@
|
||||||
</select>
|
</select>
|
||||||
</label>
|
</label>
|
||||||
<script>
|
<script>
|
||||||
const tzInput = document.getElementById('tzInput');
|
// timezone offset in seconds
|
||||||
tzInput.value = new Date().getTimezoneOffset();
|
const tzOffsetSec = new Date().getTimezoneOffset() * 60;
|
||||||
const fileInput = document.getElementById('fileInput');
|
const fileInput = document.getElementById('fileInput');
|
||||||
const fileDates = document.getElementById('fileDates');
|
const fileDates = document.getElementById('fileDates');
|
||||||
fileInput.addEventListener('change', (e) => {
|
fileInput.addEventListener('change', (e) => {
|
||||||
const files = e.target.files;
|
const files = e.target.files;
|
||||||
let dateMap = {};
|
let dateMap = {};
|
||||||
for (let file of files) {
|
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);
|
fileDates.value = JSON.stringify(dateMap);
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue