Hi everyone,
I'm trying to find a way to calculate a date a few days in the future, from one date value given in an external data source.
I've got a weather forecast, which I'm bringing in using JSON. It has a forecast for the next 4 days, marked up as Day0, Day1, Day2 and Day3, but handily it only gives one date in the entire feed, which is the date for Day0, given as 'IssuedDate'.
I can use the ^date_format modifier on the IssuedDate, so it is recognised by Matrix as a valid date string.
Is there a way I can use this to generate the dates for days 1, 2 and 3?
I thought I had it cracked using ^ds__IssuedDate^increment^date_format:l j F Y%
I'm testing this with IssuedDate as Wed 15 August 2012, and that modifier gives me Thursday 16 August 2012.
But if I add lots of ^increments, to take the date past the end of August, it doesn't flip to September, the date string is 2012-08-34 which then errors, understandably.
I need to increment the whole date, not just the day value, so it will work across the end/beginnings of months.
Is there anyway I'm going to be able to do this?
Thanks for any suggestions!
Charlie.
PS - I have to use this IssuedDate as the source date, as the feed updates during the day so it doesn't always match today's actual date.
What is the format of the 'IssueDate' that is being provided in the feed?
Hi Ash,
Sorry, I should have put that in my post.
I've actually got two different elements that I can use, which are formatted like this:
2012-08-16 (which is the one I've been using)
Thursday, 16 August 2012
So, when I use 2012-08-16, and use ^increment, I'm guessing it just increments the 16 to be 17, but doesn't know that it needs to go from 08-31 to 09-01.
Thanks,
Charlie.
Hi Charlie,
This can get a bit complicated but is surely doable. In case if you get confused somewhere feel free to ask me any questions.
Here is what you can do :
Lets say your keyword %ds__IssuedDate% is the one with Day0. And using %ds__IssuedDate^date_format:l j F Y% is giving you desired result for the first day.
You can use this keyword in the metadata text field and append +1 day, +2 day, +3 day in the value.
So lets say your Metadata fields and value are as below :
- day_one : "%ds__IssuedDate% + 1 day"
[*]day_two : "%ds__IssuedDate% + 2 day"
[*]day_three : "%ds__IssuedDate% + 3 day"
Now if you use the similar keyword modifiers on these metadata field (%asset_metadata_day_one^date_format:l j F Y%, %asset_metadata_day_two^date_format:l j F Y%, %asset_metadata_day_three^date_format:l j F Y%) you will get the result you are hoping for.
Hope this helps.
Ash.
Hi Ash,
That looks like exactly the solution I need… but i'm glad you said feel free to ask questions!
Here's what I've done:
I've created a metadata schema with a text field (correct?) for 'daytwo'
I've set the default value to: %ds__IssuedDate% + 2 day
I've applied the schema to my JSON datasource, but it won't apply to the child Data Source Record Set - and this is the bit that I'm showing on my asset list to output the details, so when I output %asset_metadata_daytwo% I get nothing output.
So, how can I get the metadata to be filled with values comming from the Data Source Record Set, when it won't apply to that asset?
Thanks again for your help!
Charlie.
Bummer! Totally overlooked the fact that you can't apply metadata schema to Data Source Record Sets 
Think we've hit a road block here. I am totally out of ideas now. Hopefully some who stumbles upon on topic might have an idea how to overcome this.
The only other think I could think of was capturing the date and incrementing with the help of javascript.
Ash
Hi Ash,
Yup, other than that it was a brilliant plan!
I've compromised at the moment, and have taken the format of the IssuedDate as the day name, and then done ^replace modifiers to change it from Monday -> Wednesday, Tuesday -> Thursday etc, so at least I have the day name for those bits of the forecast.
I'm guessing there is probably a javascript solution, but I really need it converted server-side so that the html code contains the actual dates (accessiblity for screen readers and for the vast number of visitors who print it out).
So, if anyone does think of anything that would work, let me know!
In the meantime I'm sending feedback to the UK Met Office that adding in those extra dates to their feed would be kinda helpful!
C ;o)