chore: clean up date filters
This commit is contained in:
parent
6f9aa95faf
commit
a5354d63e3
1 changed files with 20 additions and 17 deletions
|
@ -1,23 +1,26 @@
|
||||||
export default {
|
export default {
|
||||||
stringToRFC822Date: (dateString) => {
|
stringToRFC822Date: (dateString) => {
|
||||||
const date = new Date(Date.parse(dateString))
|
const date = new Date(dateString)
|
||||||
const dayStrings = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']
|
|
||||||
const monthStrings = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
|
if (isNaN(date)) return ''
|
||||||
const day = dayStrings[date.getDay()]
|
|
||||||
const dayNumber = String(date.getDate()).padStart(2, '0')
|
const options = {
|
||||||
const month = monthStrings[date.getMonth()]
|
weekday: 'short',
|
||||||
const year = date.getFullYear()
|
day: '2-digit',
|
||||||
const time = `${String(date.getHours()).padStart(2, '0')}:${String(date.getMinutes()).padStart(2, '0')}:00`
|
month: 'short',
|
||||||
const timezone = date.getTimezoneOffset() === 0 ? 'GMT' : 'PT'
|
year: 'numeric',
|
||||||
return `${day}, ${dayNumber} ${month} ${year} ${time} ${timezone}`
|
hour: '2-digit',
|
||||||
|
minute: '2-digit',
|
||||||
|
second: '2-digit',
|
||||||
|
timeZoneName: 'short'
|
||||||
|
}
|
||||||
|
const formatter = new Intl.DateTimeFormat('en-GB', options)
|
||||||
|
|
||||||
|
return formatter.format(date).replace(',', '')
|
||||||
},
|
},
|
||||||
stringToRFC3339: (dateString) => {
|
stringToRFC3339: (dateString) => {
|
||||||
const timestamp = Date.parse(dateString);
|
const date = new Date(dateString)
|
||||||
if (!isNaN(timestamp)) {
|
|
||||||
const date = new Date(timestamp)
|
return isNaN(date) ? '' : date.toISOString()
|
||||||
return date.toISOString()
|
|
||||||
} else {
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in a new issue