Repository URL to install this package:
|
Version:
1.1.2 ▾
|
import { toDate } from 'exotic'
import format from 'date-fns/format'
import isThisWeek from 'date-fns/is_this_week'
import distanceInWordsToNow from 'date-fns/distance_in_words_to_now'
const DATE_FORMAT = 'YYYY-MM-DD h:mm A'
const DATE_ISO_FORMAT = 'YYYY-MM-DD hh:mm:ss a ZZ'
const toDateFormat = (formatOption: string) => (date: string) =>
format(date, formatOption)
const toLongDate = toDateFormat(DATE_FORMAT)
const toISODate = toDateFormat(DATE_ISO_FORMAT)
const toTimeAgoInWords = (date: string) => distanceInWordsToNow(date)
// @todo - this isn't proper for parsing the data given by apis
// may need getActualDate
function toPrettyDate(date: string) {
date = toDate(date)
if (isThisWeek(date)) {
return toTimeAgoInWords(date)
} else {
return toLongDate(date)
}
}
export { toPrettyDate }