mirror of https://github.com/Lissy93/dashy.git
♻️ Refactors date time method
This commit is contained in:
parent
f46d1df72a
commit
58cb439086
|
@ -22,7 +22,7 @@
|
|||
import axios from 'axios';
|
||||
import WidgetMixin from '@/mixins/WidgetMixin';
|
||||
import { widgetApiEndpoints } from '@/utils/defaults';
|
||||
import { findCurrencySymbol, convertTimestampToDate } from '@/utils/MiscHelpers';
|
||||
import { findCurrencySymbol, timestampToDate } from '@/utils/MiscHelpers';
|
||||
|
||||
export default {
|
||||
mixins: [WidgetMixin],
|
||||
|
@ -121,7 +121,7 @@ export default {
|
|||
+ `<b>${this.$options.filters.currency(info.marketCap)}</b>`
|
||||
+ `<br>Circulating Supply: <b>${info.supply} ${info.symbol.toUpperCase()}</b>${maxSupply}`
|
||||
+ `<br>All-time-high of <b>${info.allTimeHigh}</b> `
|
||||
+ `at <b>${convertTimestampToDate(info.allTimeHighDate)}</b>`;
|
||||
+ `at <b>${timestampToDate(info.allTimeHighDate)}</b>`;
|
||||
return {
|
||||
content, html: true, trigger: 'hover focus', delay: 250,
|
||||
};
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
import axios from 'axios';
|
||||
import WidgetMixin from '@/mixins/WidgetMixin';
|
||||
import { widgetApiEndpoints } from '@/utils/defaults';
|
||||
import { convertTimestampToDate } from '@/utils/MiscHelpers';
|
||||
import { timestampToDate } from '@/utils/MiscHelpers';
|
||||
|
||||
export default {
|
||||
mixins: [WidgetMixin],
|
||||
|
@ -53,7 +53,7 @@ export default {
|
|||
},
|
||||
filters: {
|
||||
date(date) {
|
||||
return convertTimestampToDate(date);
|
||||
return timestampToDate(date);
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
import axios from 'axios';
|
||||
import WidgetMixin from '@/mixins/WidgetMixin';
|
||||
import { widgetApiEndpoints } from '@/utils/defaults';
|
||||
import { convertTimestampToDate, capitalize } from '@/utils/MiscHelpers';
|
||||
import { timestampToDate, capitalize } from '@/utils/MiscHelpers';
|
||||
|
||||
export default {
|
||||
mixins: [WidgetMixin],
|
||||
|
@ -77,7 +77,7 @@ export default {
|
|||
/* Assign data variables to the returned data */
|
||||
processData(holidays) {
|
||||
const results = [];
|
||||
const makeDate = (date) => convertTimestampToDate(
|
||||
const makeDate = (date) => timestampToDate(
|
||||
new Date(`${date.year}-${date.month}-${date.day}`).getTime(),
|
||||
);
|
||||
const formatType = (ht) => capitalize(ht.replaceAll('_', ' '));
|
||||
|
|
|
@ -48,7 +48,8 @@ export const applyItemId = (inputSections) => {
|
|||
return sections;
|
||||
};
|
||||
|
||||
export const convertTimestampToDate = (timestamp) => {
|
||||
/* Given a timestamp, returns formatted date, in local format */
|
||||
export const timestampToDate = (timestamp) => {
|
||||
const localFormat = navigator.language;
|
||||
const dateFormat = {
|
||||
weekday: 'short', day: 'numeric', month: 'short', year: '2-digit',
|
||||
|
@ -57,6 +58,18 @@ export const convertTimestampToDate = (timestamp) => {
|
|||
return `${date}`;
|
||||
};
|
||||
|
||||
/* Given a timestamp, returns formatted time in local format */
|
||||
export const timestampToTime = (timestamp) => {
|
||||
const localFormat = navigator.language;
|
||||
const timeFormat = { hour: 'numeric', minute: 'numeric', second: 'numeric' };
|
||||
const time = Intl.DateTimeFormat(localFormat, timeFormat).format(new Date(timestamp));
|
||||
return time;
|
||||
};
|
||||
|
||||
export const timestampToDateTime = (timestamp) => {
|
||||
return `${timestampToDate(timestamp)} at ${timestampToTime(timestamp)}`;
|
||||
};
|
||||
|
||||
/* Given a currency code, return the corresponding unicode symbol */
|
||||
export const findCurrencySymbol = (currencyCode) => {
|
||||
const code = currencyCode.toUpperCase().trim();
|
||||
|
|
Loading…
Reference in New Issue