mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-05-24 07:39:59 +08:00
Refactored moment.js out of app
Reduces bundle size by 25%
This commit is contained in:
15
resources/assets/js/services/dates.js
Normal file
15
resources/assets/js/services/dates.js
Normal file
@ -0,0 +1,15 @@
|
||||
|
||||
export function getCurrentDay() {
|
||||
let date = new Date();
|
||||
let month = date.getMonth() + 1;
|
||||
let day = date.getDate();
|
||||
|
||||
return `${date.getFullYear()}-${(month>9?'':'0') + month}-${(day>9?'':'0') + day}`;
|
||||
}
|
||||
|
||||
export function utcTimeStampToLocalTime(timestamp) {
|
||||
let date = new Date(timestamp * 1000);
|
||||
let hours = date.getHours();
|
||||
let mins = date.getMinutes();
|
||||
return `${(hours>9?'':'0') + hours}:${(mins>9?'':'0') + mins}`;
|
||||
}
|
@ -1,6 +1,4 @@
|
||||
const moment = require('moment');
|
||||
require('moment/locale/en-gb');
|
||||
moment.locale('en-gb');
|
||||
import * as Dates from "../services/dates";
|
||||
|
||||
let autoSaveFrequency = 30;
|
||||
|
||||
@ -96,9 +94,8 @@ let methods = {
|
||||
let url = window.baseUrl(`/ajax/page/${this.pageId}/save-draft`);
|
||||
window.$http.put(url, data).then(response => {
|
||||
draftErroring = false;
|
||||
let updateTime = moment.utc(moment.unix(response.data.timestamp)).toDate();
|
||||
if (!this.isNewDraft) this.isUpdateDraft = true;
|
||||
this.draftNotifyChange(response.data.message + moment(updateTime).format('HH:mm'));
|
||||
this.draftNotifyChange(`${response.data.message } ${Dates.utcTimeStampToLocalTime(response.data.timestamp)}`);
|
||||
lastSave = Date.now();
|
||||
}, errorRes => {
|
||||
if (draftErroring) return;
|
||||
|
@ -1,4 +1,4 @@
|
||||
const moment = require('moment');
|
||||
import * as Dates from "../services/dates";
|
||||
|
||||
let data = {
|
||||
terms: '',
|
||||
@ -153,7 +153,7 @@ let methods = {
|
||||
},
|
||||
|
||||
enableDate(optionName) {
|
||||
this.search.dates[optionName.toLowerCase()] = moment().format('YYYY-MM-DD');
|
||||
this.search.dates[optionName.toLowerCase()] = Dates.getCurrentDay();
|
||||
this.dateChange(optionName);
|
||||
},
|
||||
|
||||
|
Reference in New Issue
Block a user