Move _dateToString into a new function

This commit is contained in:
toasted-nutbread 2020-04-01 21:11:01 -04:00
parent efcdff72a3
commit a49e061545

View File

@ -126,18 +126,8 @@ class AnkiNoteBuilder {
return; return;
} }
const dateToString = (date) => {
const year = date.getUTCFullYear();
const month = date.getUTCMonth().toString().padStart(2, '0');
const day = date.getUTCDate().toString().padStart(2, '0');
const hours = date.getUTCHours().toString().padStart(2, '0');
const minutes = date.getUTCMinutes().toString().padStart(2, '0');
const seconds = date.getUTCSeconds().toString().padStart(2, '0');
return `${year}-${month}-${day}-${hours}-${minutes}-${seconds}`;
};
const now = new Date(Date.now()); const now = new Date(Date.now());
const filename = `yomichan_browser_screenshot_${definition.reading}_${dateToString(now)}.${screenshot.format}`; const filename = `yomichan_browser_screenshot_${definition.reading}_${this._dateToString(now)}.${screenshot.format}`;
const data = screenshot.dataUrl.replace(/^data:[\w\W]*?,/, ''); const data = screenshot.dataUrl.replace(/^data:[\w\W]*?,/, '');
try { try {
@ -160,6 +150,16 @@ class AnkiNoteBuilder {
return filename; return filename;
} }
_dateToString(date) {
const year = date.getUTCFullYear();
const month = date.getUTCMonth().toString().padStart(2, '0');
const day = date.getUTCDate().toString().padStart(2, '0');
const hours = date.getUTCHours().toString().padStart(2, '0');
const minutes = date.getUTCMinutes().toString().padStart(2, '0');
const seconds = date.getUTCSeconds().toString().padStart(2, '0');
return `${year}-${month}-${day}-${hours}-${minutes}-${seconds}`;
}
static stringReplaceAsync(str, regex, replacer) { static stringReplaceAsync(str, regex, replacer) {
let match; let match;
let index = 0; let index = 0;