Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
@skava/modules-modules / utils / toPrettyDate.ts
Size: Mime:
import { curry } from 'chain-able-boost'
import { isDate, isNumber, isString, isArray, toDate } from 'exotic'
import { format, distanceInWordsToNow, isThisWeek } from 'date-fns'

const DATE_FORMAT = 'YYYY-MM-DD h:mm A'
const DATE_ISO_FORMAT = 'YYYY-MM-DD hh:mm:ss a ZZ'

const toDateFormat = curry(2, (formatOption, date) =>
  format(date, formatOption)
)

const toLongDate = toDateFormat(DATE_FORMAT)
const toISODate = toDateFormat(DATE_ISO_FORMAT)
const toTimeAgoInWords = date => distanceInWordsToNow(date)

// @todo - this isn't proper for parsing the data given by apis
// may need getActualDate
function toPrettyDate(date) {
  date = toDate(date)

  if (isThisWeek(date)) {
    return toTimeAgoInWords(date)
  } else {
    return toLongDate(date)
  }
}

export { toPrettyDate }