mirror of
https://github.com/misenhower/splatoon2.ink.git
synced 2026-09-08 18:45:26 -05:00
Remove Moment and use built-in date functions instead
This saves about 216kb in the compiled JS and also formats dates/times based on the user's location.
This commit is contained in:
@@ -27,7 +27,6 @@
|
||||
"html-loader": "^0.5.0",
|
||||
"html-webpack-plugin": "^2.30.1",
|
||||
"mkdirp": "^0.5.1",
|
||||
"moment": "^2.18.1",
|
||||
"node-sass": "^4.5.3",
|
||||
"purify-css": "^1.2.5",
|
||||
"purifycss-webpack": "^0.7.0",
|
||||
|
||||
@@ -31,7 +31,10 @@
|
||||
<span v-else>Soon!</span>
|
||||
</div>
|
||||
<div class="title-color is-size-5">
|
||||
{{ coop.schedule.start_time | time }} –
|
||||
{{ coop.schedule.start_time | date }}
|
||||
{{ coop.schedule.start_time | time }}
|
||||
–
|
||||
{{ coop.schedule.end_time | date }}
|
||||
{{ coop.schedule.end_time | time }}
|
||||
</div>
|
||||
<div v-if="isOpen">
|
||||
|
||||
@@ -23,6 +23,9 @@
|
||||
in {{ schedule.start_time - now | duration }}
|
||||
<br />
|
||||
</template>
|
||||
<template v-if="!isToday">
|
||||
{{ schedule.start_time | date }}
|
||||
</template>
|
||||
{{ schedule.start_time | time }} –
|
||||
{{ schedule.end_time | time }}
|
||||
</div>
|
||||
@@ -43,5 +46,12 @@ import Stage from './Stage.vue';
|
||||
export default {
|
||||
components: { Stage },
|
||||
props: ['schedule', 'now'],
|
||||
computed: {
|
||||
isToday() {
|
||||
let now = new Date(this.now * 1000);
|
||||
let start = new Date(this.schedule.start_time * 1000);
|
||||
return (now.getDate() == start.getDate() && now.getMonth() == start.getMonth() && now.getFullYear() == start.getFullYear());
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import Vue from 'vue';
|
||||
import App from './components/App.vue';
|
||||
import moment from 'moment';
|
||||
|
||||
Vue.directive('portal', {
|
||||
inserted(el) {
|
||||
@@ -8,15 +7,30 @@ Vue.directive('portal', {
|
||||
}
|
||||
});
|
||||
|
||||
Vue.filter('date', function(value) {
|
||||
return (new Date(value * 1000)).toLocaleDateString([], { month: 'numeric', day: 'numeric' });
|
||||
});
|
||||
|
||||
Vue.filter('time', function(value) {
|
||||
return moment.unix(value).local().format('ha');
|
||||
return (new Date(value * 1000)).toLocaleTimeString([], { hour: 'numeric', minute: '2-digit' });
|
||||
});
|
||||
|
||||
Vue.filter('duration', function(value) {
|
||||
let duration = moment.duration(value, 'seconds');
|
||||
let hours = Math.floor(duration.asHours());
|
||||
let minutes = ('0' + duration.minutes()).substr(-2);
|
||||
let seconds = ('0' + duration.seconds()).substr(-2);
|
||||
let days = Math.floor(value / 86400);
|
||||
value -= days * 86400;
|
||||
let hours = Math.floor(value / 3600) % 24;
|
||||
value -= hours * 3600;
|
||||
let minutes = Math.floor(value / 60) % 60;
|
||||
value -= minutes * 60;
|
||||
let seconds = value % 60;
|
||||
|
||||
// Add leading zeros
|
||||
if (days || hours)
|
||||
minutes = ('0' + minutes).substr(-2);
|
||||
seconds = ('0' + seconds).substr(-2);
|
||||
|
||||
if (days)
|
||||
return `${days}d ${hours}h ${minutes}m ${seconds}s`;
|
||||
if (hours)
|
||||
return `${hours}h ${minutes}m ${seconds}s`;
|
||||
return `${minutes}m ${seconds}s`;
|
||||
|
||||
Reference in New Issue
Block a user