format-date.js 606 B

1234567891011121314151617181920212223242526272829
  1. import moment from 'moment'
  2. moment.updateLocale('en', {
  3. calendar: {
  4. lastDay: '[Yesterday]',
  5. sameDay: '[Today]',
  6. nextDay: '[Tomorrow]',
  7. lastWeek: 'ddd, Do MMM YY',
  8. nextWeek: 'ddd, Do MMM YY',
  9. sameElse: 'ddd, Do MMM YY',
  10. },
  11. })
  12. export function formatTime(date, format = 'h:mm a') {
  13. return moment(date).format(format)
  14. }
  15. export function relativeDate(date) {
  16. return moment(date).calendar()
  17. }
  18. /**
  19. * @param {string} isoTimestamp
  20. * @returns {number}
  21. */
  22. export function isoToUnix(isoTimestamp) {
  23. const unixTimestamp = Date.parse(isoTimestamp) / 1000
  24. return unixTimestamp
  25. }