Fixed incorrect date bug
This commit is contained in:
parent
b50c0c032e
commit
2320a5d404
@ -671,11 +671,23 @@
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<script>
|
||||
|
||||
/**
|
||||
* @yaireo/relative-time - javascript function to transform timestamp or date to local relative-time
|
||||
*
|
||||
* @version v1.0.0
|
||||
* @homepage https://github.com/yairEO/relative-time
|
||||
*/
|
||||
|
||||
!function (e, t) { var o = o || {}; "function" == typeof o && o.amd ? o([], t) : "object" == typeof exports && "object" == typeof module ? module.exports = t() : "object" == typeof exports ? exports.RelativeTime = t() : e.RelativeTime = t() }(this, (function () { const e = { year: 31536e6, month: 2628e6, day: 864e5, hour: 36e5, minute: 6e4, second: 1e3 }, t = "en", o = { numeric: "auto" }; function n(e) { e = { locale: (e = e || {}).locale || t, options: { ...o, ...e.options } }, this.rtf = new Intl.RelativeTimeFormat(e.locale, e.options) } return n.prototype = { from(t, o) { const n = t - (o || new Date); for (let t in e) if (Math.abs(n) > e[t] || "second" == t) return this.rtf.format(Math.round(n / e[t]), t) } }, n }));
|
||||
</script>
|
||||
<script id="ui_utils">
|
||||
// Global variables
|
||||
const domRefs = {};
|
||||
let timerId;
|
||||
const currentYear = new Date().getFullYear();
|
||||
const relativeTime = new RelativeTime({ style: 'narrow' });
|
||||
|
||||
//Checks for internet connection status
|
||||
if (!navigator.onLine)
|
||||
@ -824,18 +836,12 @@
|
||||
}
|
||||
}
|
||||
|
||||
function getFormattedTime(timeString, relative) {
|
||||
function getFormattedTime(time, format) {
|
||||
try {
|
||||
console.log(timeString)
|
||||
const [date, time] = timeString.split('T')
|
||||
const [year, month, day] = date.split('-').map(v => parseInt(v))
|
||||
let [hours, minutes] = time.split(':').map(v => parseInt(v))
|
||||
const currentTime = new Date()
|
||||
const currentTimeFrag = currentTime.toString().split(' ')
|
||||
const monthNames = ["Jan", "Feb", "Mar", "Apr", "May", "Jun",
|
||||
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
|
||||
];
|
||||
const monthName = monthNames[month - 1]
|
||||
let [day, month, date, year] = new Date(time).toString().split(' '),
|
||||
minutes = new Date(time).getMinutes(),
|
||||
hours = new Date(time).getHours(),
|
||||
currentTime = new Date().toString().split(' ')
|
||||
|
||||
minutes = minutes < 10 ? `0${minutes}` : minutes
|
||||
let finalHours = ``;
|
||||
@ -847,27 +853,13 @@
|
||||
finalHours = `${hours}:${minutes}`
|
||||
|
||||
finalHours = hours >= 12 ? `${finalHours} PM` : `${finalHours} AM`
|
||||
if (relative) {
|
||||
if (year == currentYear) {
|
||||
if ((currentTime.getMonth() + 1) === month) {
|
||||
const dateDiff = (parseInt(currentTimeFrag[2]) - parseInt(day))
|
||||
if (dateDiff === 0)
|
||||
return `${finalHours}`;
|
||||
else if (dateDiff === 1)
|
||||
return `Yesterday`;
|
||||
else if (dateDiff > 1 && dateDiff < 8)
|
||||
return currentTimeFrag[0];
|
||||
else
|
||||
return ` ${day} ${monthName}`;
|
||||
}
|
||||
else
|
||||
return ` ${day} ${monthName}`;
|
||||
}
|
||||
else
|
||||
return `${monthName} ${year}`;
|
||||
switch (format) {
|
||||
case 'date-only':
|
||||
return `${month} ${date}, ${year}`;
|
||||
break;
|
||||
default:
|
||||
return `${month} ${date} ${year}, ${finalHours}`;
|
||||
}
|
||||
else
|
||||
return `${finalHours}, ${monthName} ${day} ${year}`;
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
return time;
|
||||
@ -1224,7 +1216,7 @@
|
||||
card.querySelector('.order-card__quantity').textContent = `${quantity} ${asset}`
|
||||
card.querySelector('.order-card__price-type').textContent = type === 'buy' ? 'Max price' : 'Min price'
|
||||
card.querySelector('.order-card__price').textContent = formatAmount(price)
|
||||
card.querySelector('.order-card__time').textContent = getFormattedTime(time, true)
|
||||
card.querySelector('.order-card__time').textContent = relativeTime.from(time)
|
||||
return card
|
||||
},
|
||||
transactionCard(transactionDetails = {}) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user