Переход на dayjs

This commit is contained in:
Book Pauk
2022-12-15 17:18:05 +07:00
parent dfd45a58bd
commit c602f3d531
4 changed files with 12 additions and 25 deletions

View File

@@ -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([

View File

@@ -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() {

View File

@@ -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 = '';

View File

@@ -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);
}