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.any.js 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import {
  2. getLocalizedDateFormatter,
  3. getLocalizedDurationFormatter
  4. } from '../base/i18n';
  5. import { parseURIString } from '../base/util';
  6. /**
  7. * Creates a displayable list item of a recent list entry.
  8. *
  9. * @private
  10. * @param {Object} item - The recent list entry.
  11. * @param {string} defaultServerURL - The default server URL.
  12. * @param {Function} t - The translate function.
  13. * @returns {Object}
  14. */
  15. export function toDisplayableItem(item, defaultServerURL, t) {
  16. const location = parseURIString(item.conference);
  17. const baseURL = `${location.protocol}//${location.host}`;
  18. const serverName = baseURL === defaultServerURL ? null : location.host;
  19. return {
  20. colorBase: serverName,
  21. id: {
  22. date: item.date,
  23. url: item.conference
  24. },
  25. key: `key-${item.conference}-${item.date}`,
  26. lines: [
  27. _toDateString(item.date, t),
  28. _toDurationString(item.duration),
  29. serverName
  30. ],
  31. title: location.room,
  32. url: item.conference
  33. };
  34. }
  35. /**
  36. * Generates a duration string for the item.
  37. *
  38. * @private
  39. * @param {number} duration - The item's duration.
  40. * @returns {string}
  41. */
  42. export function _toDurationString(duration) {
  43. if (duration) {
  44. return getLocalizedDurationFormatter(duration);
  45. }
  46. return null;
  47. }
  48. /**
  49. * Generates a date string for the item.
  50. *
  51. * @private
  52. * @param {number} itemDate - The item's timestamp.
  53. * @param {Function} t - The translate function.
  54. * @returns {string}
  55. */
  56. export function _toDateString(itemDate, t) {
  57. const m = getLocalizedDateFormatter(itemDate);
  58. const date = new Date(itemDate);
  59. const dateInMs = date.getTime();
  60. const now = new Date();
  61. const todayInMs = (new Date()).setHours(0, 0, 0, 0);
  62. const yesterdayInMs = todayInMs - 86400000; // 1 day = 86400000ms
  63. if (dateInMs >= todayInMs) {
  64. return m.fromNow();
  65. } else if (dateInMs >= yesterdayInMs) {
  66. return t('dateUtils.yesterday');
  67. } else if (date.getFullYear() !== now.getFullYear()) {
  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. }