Skip to content

Commit

Permalink
Add a form of timestamp to the name of the saved file.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Castle committed Jun 8, 2024
1 parent 1029bf2 commit bb42357
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion plugins/explore.js
Original file line number Diff line number Diff line change
Expand Up @@ -333,9 +333,12 @@ window.plugin.explore.State = class {
}
}
}
const dateSeq = this.#sequenceDate(new Date());
const filename = `IITC-exploration-${dateSeq}.json`;
window.saveFile(JSON.stringify(data, null, 2),
'IITC-exploration.json',
filename,
'application/json');
this.status = `Saved with ${filename}`;
}

/** Start exploring the current bounds. */
Expand Down Expand Up @@ -513,6 +516,22 @@ window.plugin.explore.State = class {
}
}

/**
* Turn a timestamp into YYYY-MM-DD-seconds.
* @param {Date} date - Date to format.
* @returns {string} - Formated date.
*/
#sequenceDate(date) {
const yyyy = date.getFullYear();
const mm = window.zeroPad(date.getMonth() + 1, 2);
const dd = window.zeroPad(date.getDate(), 2);
const seq = window.zeroPad(date.getHours() * 3600
+ date.getMinutes() * 60
+ date.getSeconds(), 5);
const dateStr = `${yyyy}-${mm}-${dd}-${seq}`;
return dateStr;
}

/**
* Determine an appropriate starting point. Maybe one saved from an
* interrupted exploration, otherwise, the northwest corner of the boundary.
Expand Down

0 comments on commit bb42357

Please sign in to comment.