Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2022 SonarSource SA
  4. * mailto:info AT sonarsource DOT com
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 3 of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with this program; if not, write to the Free Software Foundation,
  18. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. */
  20. import { parseDate } from '../helpers/dates';
  21. import { translate, translateWithParameters } from '../helpers/l10n';
  22. import { ApplicationPeriod } from '../types/application';
  23. import { Period } from '../types/types';
  24. export function getPeriodLabel(
  25. period: Period | undefined,
  26. dateFormatter: (date: string) => string
  27. ) {
  28. if (!period) {
  29. return undefined;
  30. }
  31. let parameter = period.modeParam || period.parameter || '';
  32. switch (period.mode) {
  33. case 'SPECIFIC_ANALYSIS':
  34. parameter = dateFormatter(period.date);
  35. break;
  36. case 'PREVIOUS_VERSION':
  37. parameter = parameter || dateFormatter(period.date);
  38. break;
  39. /*
  40. * Handle legacy period modes, that predate MMF-1579
  41. */
  42. case 'previous_version':
  43. if (!parameter) {
  44. return translate('overview.period.previous_version_only_date');
  45. }
  46. break;
  47. case 'date':
  48. parameter = parameter && dateFormatter(parameter);
  49. break;
  50. case 'manual_baseline':
  51. parameter = parameter || dateFormatter(period.date);
  52. break;
  53. default: // No change in the parameter
  54. }
  55. return translateWithParameters(`overview.period.${period.mode.toLowerCase()}`, parameter);
  56. }
  57. export function getPeriodDate(period?: { date?: string }): Date | undefined {
  58. return period && period.date ? parseDate(period.date) : undefined;
  59. }
  60. export function isApplicationPeriod(
  61. period: Period | ApplicationPeriod
  62. ): period is ApplicationPeriod {
  63. return (period as ApplicationPeriod).project !== undefined;
  64. }