Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | 1x 1x | <template> <div>{{ parseDate() }}</div> </template> <script> export default { name: "OrdarDate", props: { date: String }, methods: { parseDate: function () { const currentDate = new Date(); const order_date = new Date(this.date); const curDate = currentDate.getDate(); const curDay = currentDate.getDay(); const curMonth = currentDate.getMonth(); const curYear = currentDate.getFullYear(); const orderDate = order_date.getDate(); const orderDay = order_date.getDay(); const orderMonth = order_date.getMonth(); const orderYear = order_date.getFullYear(); const orderTime = order_date.toLocaleString("en-US", { hour: "numeric", hour12: true, }); const orderDayAsString = order_date.toLocaleDateString("en-US", { weekday: "long", }); const orderMountAsString = order_date.toLocaleString("en-US", { month: "long", }); if (curYear !== orderYear) { return `${orderMountAsString} ${orderYear} at ${orderTime}`; } else if ( orderMonth !== curMonth && curDate - orderDate > 5 && curYear === orderYear ) { return `${orderMountAsString} at ${orderTime}`; } else if (curDate - orderDate > 5) { return `${orderDayAsString} at ${orderTime}`; } return `Yesturday at ${orderTime}`; }, }, }; </script> <style scoped> </style> |