From 71ed12f62259981a7665a7595919089f51c1cd67 Mon Sep 17 00:00:00 2001 From: Tatiana Ovchinnikova Date: Wed, 19 Aug 2020 14:33:30 -0500 Subject: [PATCH] Fix Angular mediumDateFilter Angular mediumDateFilter provides user with a readable date format using predefined localizable format "medium". However it should be more flexible with different types of inputs. This patch fixes the filter and applies it at the images overview page. Change-Id: I7079c306c6f98f13c779e6dae7357ccabba2d460 Closes-Bug: #1841049 --- horizon/static/framework/util/filters/filters.js | 5 ++++- horizon/static/framework/util/filters/filters.spec.js | 10 +++++++++- .../static/app/core/images/images.module.js | 4 ++-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/horizon/static/framework/util/filters/filters.js b/horizon/static/framework/util/filters/filters.js index 609f5d8ba4..cdaab15c1c 100644 --- a/horizon/static/framework/util/filters/filters.js +++ b/horizon/static/framework/util/filters/filters.js @@ -85,7 +85,10 @@ * For the input time, we need to add "Z" to fit iso8601 time format * so the filter can confirm that the input time is in UTC timezone. */ - input = input + 'Z'; + input = $filter('noValue')(input); + if (input !== '-') { + input = input.slice(-1) !== 'Z' ? input + 'Z' : input; + } var currentTimeZone = $cookies.get('django_timezone') || 'UTC'; currentTimeZone = currentTimeZone.replace(/^"(.*)"$/, '$1'); return timeZoneService.getTimeZoneOffset(currentTimeZone).then(function (timeZoneOffset) { diff --git a/horizon/static/framework/util/filters/filters.spec.js b/horizon/static/framework/util/filters/filters.spec.js index 2b98ea7882..a974f665a1 100644 --- a/horizon/static/framework/util/filters/filters.spec.js +++ b/horizon/static/framework/util/filters/filters.spec.js @@ -90,7 +90,15 @@ }); it('returns the expected time', function() { - mediumDateFilter().then(getResult); + mediumDateFilter('2019-09-03T09:19:07.000').then(getResult); + + function getResult(result) { + expect(result).toBe('Sep 3, 2019 9:19:07 AM'); + } + }); + + it('returns the expected time in UTC', function() { + mediumDateFilter('2019-09-03T09:19:07.000Z').then(getResult); function getResult(result) { expect(result).toBe('Sep 3, 2019 9:19:07 AM'); diff --git a/openstack_dashboard/static/app/core/images/images.module.js b/openstack_dashboard/static/app/core/images/images.module.js index 34330f5c8e..4aa84e8244 100644 --- a/openstack_dashboard/static/app/core/images/images.module.js +++ b/openstack_dashboard/static/app/core/images/images.module.js @@ -245,14 +245,14 @@ name: gettext('Name'), owner: gettext('Owner'), tags: gettext('Tags'), - 'updated_at': {label: gettext('Updated At'), filters: ['simpleDate'] }, + 'updated_at': {label: gettext('Updated At'), filters: ['mediumDate'] }, virtual_size: gettext('Virtual Size'), visibility: gettext('Visibility'), description: gettext('Description'), architecture: gettext('Architecture'), kernel_id: gettext('Kernel ID'), ramdisk_id: gettext('Ramdisk ID'), - 'created_at': {label: gettext('Created At'), filters: ['simpleDate'] }, + 'created_at': {label: gettext('Created At'), filters: ['mediumDate'] }, container_format: { label: gettext('Container Format'), filters: ['uppercase'] }, disk_format: { label: gettext('Disk Format'), filters: ['noValue', 'uppercase'] }, is_public: { label: gettext('Is Public'), filters: ['yesno'] },