You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

functions.all.js 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import { getLocalizedDateFormatter, getLocalizedDurationFormatter }
  2. from '../base/i18n/index';
  3. import { parseURIString } from '../base/util/index';
  4. /**
  5. * Creates a displayable list item of a recent list entry.
  6. *
  7. * @private
  8. * @param {Object} item - The recent list entry.
  9. * @param {string} defaultServerURL - The default server URL.
  10. * @param {Function} t - The translate function.
  11. * @returns {Object}
  12. */
  13. export function toDisplayableItem(item, defaultServerURL, t) {
  14. // const { _defaultServerURL } = this.props;
  15. const location = parseURIString(item.conference);
  16. const baseURL = `${location.protocol}//${location.host}`;
  17. const serverName = baseURL === defaultServerURL ? null : location.host;
  18. return {
  19. colorBase: serverName,
  20. key: `key-${item.conference}-${item.date}`,
  21. lines: [
  22. _toDateString(item.date, t),
  23. _toDurationString(item.duration),
  24. serverName
  25. ],
  26. title: location.room,
  27. url: item.conference
  28. };
  29. }
  30. /**
  31. * Generates a duration string for the item.
  32. *
  33. * @private
  34. * @param {number} duration - The item's duration.
  35. * @returns {string}
  36. */
  37. export function _toDurationString(duration) {
  38. if (duration) {
  39. return getLocalizedDurationFormatter(duration);
  40. }
  41. return null;
  42. }
  43. /**
  44. * Generates a date string for the item.
  45. *
  46. * @private
  47. * @param {number} itemDate - The item's timestamp.
  48. * @param {Function} t - The translate function.
  49. * @returns {string}
  50. */
  51. export function _toDateString(itemDate, t) {
  52. const date = new Date(itemDate);
  53. const dateString = date.toDateString();
  54. const m = getLocalizedDateFormatter(itemDate);
  55. const yesterday = new Date();
  56. yesterday.setDate(yesterday.getDate() - 1);
  57. const yesterdayString = yesterday.toDateString();
  58. const today = new Date();
  59. const todayString = today.toDateString();
  60. const currentYear = today.getFullYear();
  61. const year = date.getFullYear();
  62. if (dateString === todayString) {
  63. // The date is today, we use fromNow format.
  64. return m.fromNow();
  65. } else if (dateString === yesterdayString) {
  66. return t('dateUtils.yesterday');
  67. } else if (year !== currentYear) {
  68. // we only want to include the year in the date if its not the current
  69. // year
  70. return m.format('ddd, MMMM DD h:mm A, gggg');
  71. }
  72. return m.format('ddd, MMMM DD h:mm A');
  73. }