2021-04-28 07:41:20 -04:00
|
|
|
import moment from 'moment'
|
|
|
|
|
|
|
|
moment.updateLocale('en', {
|
|
|
|
calendar: {
|
|
|
|
lastDay: '[Yesterday]',
|
|
|
|
sameDay: '[Today]',
|
|
|
|
nextDay: '[Tomorrow]',
|
|
|
|
lastWeek: 'ddd, Do MMM YY',
|
|
|
|
nextWeek: 'ddd, Do MMM YY',
|
|
|
|
sameElse: 'ddd, Do MMM YY',
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
2023-04-11 04:35:33 -04:00
|
|
|
export function formatTime(date, format = 'h:mm a') {
|
|
|
|
return moment(date).format(format)
|
2021-04-28 07:41:20 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
export function relativeDate(date) {
|
|
|
|
return moment(date).calendar()
|
|
|
|
}
|
2023-05-02 07:58:01 -04:00
|
|
|
|
2023-12-04 08:15:20 -05:00
|
|
|
export function formatTimeBasedOnYear(date) {
|
|
|
|
const currentDate = moment()
|
|
|
|
|
|
|
|
return currentDate.diff(date, 'years') > 0
|
|
|
|
? formatTime(date, 'D MMMM YYYY, h:mm a')
|
|
|
|
: formatTime(date, 'D MMMM, h:mm a')
|
|
|
|
}
|
|
|
|
|
2023-05-02 07:58:01 -04:00
|
|
|
/**
|
|
|
|
* @param {string} isoTimestamp
|
|
|
|
* @returns {number}
|
|
|
|
*/
|
|
|
|
export function isoToUnix(isoTimestamp) {
|
|
|
|
const unixTimestamp = Date.parse(isoTimestamp) / 1000
|
|
|
|
return unixTimestamp
|
|
|
|
}
|