Matrix Version: v5.5.6.10
Hi all
I’m trying to find a way to get the difference between 2 dates into a metadata field and sort an asset listing by it but even though I can get the correct result the asset list won’t sort it correctly.
The reason for this functionality is to list Event assets and News assets in the same asset listing and sort them by the difference in time between now and when the news item was published or the start date of the event. ie. show the item dated closest to right now regardless of asset type.
I know I could just have a metadata field and manually update it each time a new asset is created but I’d prefer to automate the process by pulling in the required date using keywords.
I have a simplified test setup with assets as below. Dates are in the metadata field config.date_diff. Asset list is set to sort on this field in ascending order (‘closest to now’ to ‘furthest from now’).
Assets
News 1
1/1/2020
News 2
1/1/2021
News 3
4/8/2021
When the config.date_diff metadata field is just:
%metadata_field_dcterms.date^date_format:U^subtract:{globals_date_U}^abs%
The result is as expected (News 1: 50258682, News 2: 18636256, News 3: 56672) and the asset list sorts as expected (News 3, News 2, News 1).
But as soon as I try to add any conditionals so that News assets and Event assets use different date sources I get unexpected results. Sometimes the values seem correct but the sort still isn’t correct and other times the values returned are just whacky.
This is ideally where I want to end up with the Metadata field:
%begin_asset_type^eq:News Item%
%metadata_field_dcterms.date^date_format:U^subtract:{globals_date_U}^abs%
%end_asset_type%
%begin_asset_type^neq:News Item%
%asset_attribute_start_date^date_format:U^subtract:{globals_date_U}^abs%
%end_asset_type%
Note: the only difference is the value I pull the date from.
Any thoughts on this or other possible approaches?
Cheers
Sean