Skip to content

Commit

Permalink
Fix Time Diff
Browse files Browse the repository at this point in the history
  • Loading branch information
ingalls committed Feb 14, 2024
1 parent fbf17cb commit d5af9f2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 29 deletions.
19 changes: 4 additions & 15 deletions api/web/src/components/Import.vue
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
<script>
import Status from './util/Status.vue';
import PageFooter from './PageFooter.vue';
import timeDiff from '../timediff.js';
import {
TablerNone,
TablerBreadCrumb,
Expand Down Expand Up @@ -100,6 +101,9 @@ export default {
if (this.interval) clearInterval(this.interval);
},
methods: {
timeDiff(update) {
return timeDiff(update);
},
fetch: async function() {
this.loading = true;
const url = window.stdurl(`/api/import/${this.$route.params.import}`);
Expand All @@ -109,21 +113,6 @@ export default {
this.loading = false;
}
},
timeDiff: function(updated) {
const msPerMinute = 60 * 1000;
const msPerHour = msPerMinute * 60;
const msPerDay = msPerHour * 24;
const msPerMonth = msPerDay * 30;
const msPerYear = msPerDay * 365;
const elapsed = +(new Date()) - updated;
if (elapsed < msPerMinute) return Math.round(elapsed/1000) + ' seconds ago';
if (elapsed < msPerHour) return Math.round(elapsed/msPerMinute) + ' minutes ago';
if (elapsed < msPerDay ) return Math.round(elapsed/msPerHour ) + ' hours ago';
if (elapsed < msPerMonth) return '~' + Math.round(elapsed/msPerDay) + ' days ago';
if (elapsed < msPerYear) return '~' + Math.round(elapsed/msPerMonth) + ' months ago';
return '~' + Math.round(elapsed/msPerYear ) + ' years ago';
},
},
components: {
Status,
Expand Down
17 changes: 3 additions & 14 deletions api/web/src/components/Layers.vue
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
<script>
import PageFooter from './PageFooter.vue';
import LayerStatus from './Layer/utils/Status.vue';
import timeDiff from '../timediff.js';
import {
TablerNone,
TablerPager,
Expand Down Expand Up @@ -134,20 +135,8 @@ export default {
await this.fetchList();
},
methods: {
timeDiff: function(updated) {
const msPerMinute = 60 * 1000;
const msPerHour = msPerMinute * 60;
const msPerDay = msPerHour * 24;
const msPerMonth = msPerDay * 30;
const msPerYear = msPerDay * 365;
const elapsed = +(new Date()) - updated;
if (elapsed < msPerMinute) return Math.round(elapsed/1000) + ' seconds ago';
if (elapsed < msPerHour) return Math.round(elapsed/msPerMinute) + ' minutes ago';
if (elapsed < msPerDay ) return Math.round(elapsed/msPerHour ) + ' hours ago';
if (elapsed < msPerMonth) return '~' + Math.round(elapsed/msPerDay) + ' days ago';
if (elapsed < msPerYear) return '~' + Math.round(elapsed/msPerMonth) + ' months ago';
return '~' + Math.round(elapsed/msPerYear ) + ' years ago';
timeDiff(update) {
return timeDiff(update);
},
fetchList: async function() {
this.loading = true;
Expand Down

0 comments on commit d5af9f2

Please sign in to comment.