Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

functions.any.js 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. key: `key-${item.conference}-${item.date}`,
  22. lines: [
  23. _toDateString(item.date, t),
  24. _toDurationString(item.duration),
  25. serverName
  26. ],
  27. title: location.room,
  28. url: item.conference
  29. };
  30. }
  31. /**
  32. * Generates a duration string for the item.
  33. *
  34. * @private
  35. * @param {number} duration - The item's duration.
  36. * @returns {string}
  37. */
  38. export function _toDurationString(duration) {
  39. if (duration) {
  40. return getLocalizedDurationFormatter(duration);
  41. }
  42. return null;
  43. }
  44. /**
  45. * Generates a date string for the item.
  46. *
  47. * @private
  48. * @param {number} itemDate - The item's timestamp.
  49. * @param {Function} t - The translate function.
  50. * @returns {string}
  51. */
  52. export function _toDateString(itemDate, t) {
  53. const m = getLocalizedDateFormatter(itemDate);
  54. const date = new Date(itemDate);
  55. const dateInMs = date.getTime();
  56. const now = new Date();
  57. const todayInMs = (new Date()).setHours(0, 0, 0, 0);
  58. const yesterdayInMs = todayInMs - 86400000; // 1 day = 86400000ms
  59. if (dateInMs >= todayInMs) {
  60. return m.fromNow();
  61. } else if (dateInMs >= yesterdayInMs) {
  62. return t('dateUtils.yesterday');
  63. } else if (date.getFullYear() !== now.getFullYear()) {
  64. // We only want to include the year in the date if its not the current
  65. // year.
  66. return m.format('ddd, MMMM DD h:mm A, gggg');
  67. }
  68. return m.format('ddd, MMMM DD h:mm A');
  69. }