Change filename format of saved files

The following commit changes the default name of files saved by the
user. Originally, any saved file was named
`<map name> <capitalized three letter english month>D HH-mm.<ext>`
Now filenames follow more closely ISO 8601 and are named by default
`<map name> YYYY-MM-DD-HH-mm.<ext>`.

The function also became much smaller and easier to read.
This commit is contained in:
Lucien Cartier-Tilet 2020-08-07 11:21:26 +02:00
parent a9b16d6ee5
commit 460ccfeab7
No known key found for this signature in database
GPG key ID: BD7789E705CB8DCA

View file

@ -546,12 +546,8 @@ function unfog(id) {
function getFileName(dataType) { function getFileName(dataType) {
const name = mapName.value; const name = mapName.value;
const type = dataType ? dataType + " " : ""; const type = dataType ? dataType + " " : "";
const date = new Date(); const dateString = new Date().toISOString().replace(/:[0-9]+\..*/, "").replaceAll(/[T:]/g, "-");
const datFormatter = new Intl.DateTimeFormat("en", {month: "short", day: "numeric"}); return name + " " + type + dateString;
const timeFormatter = new Intl.DateTimeFormat("ru", {hour: "numeric", minute: "numeric"});
const day = datFormatter.format(date).replace(" ", "");
const time = timeFormatter.format(date).replace(":", "-");
return name + " " + type + day + " " + time;
} }
function downloadFile(data, name, type = "text/plain") { function downloadFile(data, name, type = "text/plain") {
@ -643,4 +639,4 @@ function refreshAllEditors() {
if (document.getElementById('statesEditorRefresh').offsetParent) statesEditorRefresh.click(); if (document.getElementById('statesEditorRefresh').offsetParent) statesEditorRefresh.click();
if (document.getElementById('zonesEditorRefresh').offsetParent) zonesEditorRefresh.click(); if (document.getElementById('zonesEditorRefresh').offsetParent) zonesEditorRefresh.click();
console.timeEnd('refreshAllEditors'); console.timeEnd('refreshAllEditors');
} }