From c602f3d53159a8f67af4caeecc8335755da2c2cb Mon Sep 17 00:00:00 2001 From: Book Pauk Date: Thu, 15 Dec 2022 17:18:05 +0700 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B5=D1=85=D0=BE=D0=B4=20?= =?UTF-8?q?=D0=BD=D0=B0=20dayjs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PasteTextPage/PasteTextPage.vue | 2 +- .../Reader/ReaderDialogs/ReaderDialogs.vue | 8 +++---- .../RecentBooksPage/RecentBooksPage.vue | 4 ++-- client/share/utils.js | 23 ++++--------------- 4 files changed, 12 insertions(+), 25 deletions(-) diff --git a/client/components/Reader/LoaderPage/PasteTextPage/PasteTextPage.vue b/client/components/Reader/LoaderPage/PasteTextPage/PasteTextPage.vue index 3647999d..a197396e 100644 --- a/client/components/Reader/LoaderPage/PasteTextPage/PasteTextPage.vue +++ b/client/components/Reader/LoaderPage/PasteTextPage/PasteTextPage.vue @@ -60,7 +60,7 @@ class PasteTextPage { calcTitle(event) { if (this.bookTitle == '') { - this.bookTitle = `Из буфера обмена ${utils.formatDate(new Date(), 'noDate')}`; + this.bookTitle = `Из буфера обмена ${utils.dateFormat(new Date())}`; if (event) { let text = event.clipboardData.getData('text'); this.bookTitle += ': ' + _.compact([ diff --git a/client/components/Reader/ReaderDialogs/ReaderDialogs.vue b/client/components/Reader/ReaderDialogs/ReaderDialogs.vue index 0cca448a..4c6db589 100644 --- a/client/components/Reader/ReaderDialogs/ReaderDialogs.vue +++ b/client/components/Reader/ReaderDialogs/ReaderDialogs.vue @@ -130,7 +130,7 @@ class ReaderDialogs { async showWhatsNew() { const whatsNew = versionHistory[0]; if (this.showWhatsNewDialog && - whatsNew.showUntil >= utils.formatDate(new Date(), 'coDate') && + whatsNew.showUntil >= utils.dateFormat(new Date(), 'YYYY-MM-DD') && this.whatsNewHeader != this.whatsNewContentHash) { await utils.sleep(2000); this.whatsNewContent = 'Версия ' + this.whatsNewHeader + whatsNew.content; @@ -139,8 +139,8 @@ class ReaderDialogs { } async showDonation() { - const today = utils.formatDate(new Date(), 'coMonth'); - + const today = utils.dateFormat(new Date(), 'MM'); +console.log(today); if ((this.mode == 'omnireader' || this.mode == 'liberama') && this.showDonationDialog && this.donationRemindDate != today) { await utils.sleep(3000); this.donationVisible = true; @@ -158,7 +158,7 @@ class ReaderDialogs { donationDialogRemind() { this.donationVisible = false; - this.commit('reader/setDonationRemindDate', utils.formatDate(new Date(), 'coMonth')); + this.commit('reader/setDonationRemindDate', utils.dateFormat(new Date(), 'MM')); } makeDonation() { diff --git a/client/components/Reader/RecentBooksPage/RecentBooksPage.vue b/client/components/Reader/RecentBooksPage/RecentBooksPage.vue index 23aecd51..98942a6d 100644 --- a/client/components/Reader/RecentBooksPage/RecentBooksPage.vue +++ b/client/components/Reader/RecentBooksPage/RecentBooksPage.vue @@ -367,10 +367,10 @@ class RecentBooksPage { let d = new Date(); d.setTime(book.touchTime); - const touchTime = utils.formatDate(d); + const touchTime = utils.dateFormat(d, 'DD.MM.YYYY HH:mm'); const loadTimeRaw = (book.loadTime ? book.loadTime : 0);//book.addTime); d.setTime(loadTimeRaw); - const loadTime = utils.formatDate(d); + const loadTime = utils.dateFormat(d, 'DD.MM.YYYY HH:mm'); let readPart = 0; let perc = ''; diff --git a/client/share/utils.js b/client/share/utils.js index 193837f9..edd23b5d 100644 --- a/client/share/utils.js +++ b/client/share/utils.js @@ -1,4 +1,5 @@ import _ from 'lodash'; +import dayjs from 'dayjs'; import baseX from 'base-x'; import PAKO from 'pako'; import {Buffer} from 'safe-buffer'; @@ -35,24 +36,6 @@ export function randomHexString(len) { return Buffer.from(randomArray(len)).toString('hex'); } -export function formatDate(d, format) { - if (!format) - format = 'normal'; - - switch (format) { - case 'normal': - return `${d.getDate().toString().padStart(2, '0')}.${(d.getMonth() + 1).toString().padStart(2, '0')}.${d.getFullYear()} ` + - `${d.getHours().toString().padStart(2, '0')}:${d.getMinutes().toString().padStart(2, '0')}`; - case 'coDate': - return `${d.getFullYear()}-${(d.getMonth() + 1).toString().padStart(2, '0')}-${d.getDate().toString().padStart(2, '0')}`; - case 'coMonth': - return `${(d.getMonth() + 1).toString().padStart(2, '0')}`; - case 'noDate': - return `${d.getDate().toString().padStart(2, '0')}.${(d.getMonth() + 1).toString().padStart(2, '0')}.${d.getFullYear()}`; - } - -} - export function fallbackCopyTextToClipboard(text) { let textArea = document.createElement('textarea'); textArea.value = text; @@ -416,3 +399,7 @@ export function resizeImage(dataUrl, toWidth, toHeight, quality = 0.9) { export function makeDonation() { window.open('https://donatty.com/liberama', '_blank'); } + +export function dateFormat(date, format = 'DD.MM.YYYY') { + return dayjs(date).format(format); +}