Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Hello,
At the moment, convert data can convert a date to a string, but the output can only be a Linux timestamp.
It would be useful to be able to provide a format, and even a timezone, to get a usable string (to put in a mail, display to a user...).
Patch will follow.
David
Comment | File | Size | Author |
---|---|---|---|
#6 | 1898828-6-rules-convert-date2string.patch | 14.08 KB | David Stosik |
#5 | 1898828-5-rules-convert-date2string.patch | 14.09 KB | David Stosik |
#3 | 1898828-3-rules-convert-date2string.patch | 14.08 KB | David Stosik |
#1 | 1898828-1-rules-convert-date2string.patch | 13.85 KB | David Stosik |
Comments
Comment #1
David Stosik CreditAttribution: David Stosik commentedHere is the patch.
Feel free to test and give me a feedback.
David
Comment #2
David Stosik CreditAttribution: David Stosik commentedMy code breaks other actions, such as "Add a variable", but I don't know why yet.
Any help is welcome!
Comment #3
David Stosik CreditAttribution: David Stosik commentedHere is a better patch, that does not seem to break anything.
David
Comment #4
fonant CreditAttribution: fonant commentedPatch #3 works for me, and handy workaround for formatting dates as strings in rules. Thanks!
Comment #5
David Stosik CreditAttribution: David Stosik commentedHere is a new version working on Rules-2.x branch, with a small fix concerning date custom format.
Comment #6
David Stosik CreditAttribution: David Stosik commentedActually, previous patch was just a reroll. This one here fixes the custom date format field.
Regards,
David
Comment #7
4kant CreditAttribution: 4kant commentedDavid, I tried your patch #6 - it is exactly what I needed and works fine.
I needed to set an ISO Date value for a text field (to hand the string over to Facebook to post an event on a Facebook page via module fb_autopost)
Great job
Thanks
Comment #8
rbrownellComment #9
fagoThank you for the patch.
However, I'm not so happy with the increased complexity it adds to the data type conversion action. Also, I don't think formatting a date is something that should be handled in a date conversion action - it's way more than just converting the data type, it's formatting. So this qualifies as a separate action.
Note, that we have intervals as separate data types also ("duration"), so I think we shouldn't bake formatting durations into the same action either but use another one. I don't know whether core has any built-in duration formats, I guess not - in which case we'd have to roll our own as the patch does.
Comment #10
fagooh, and I forgot - we'll need test coverage for that.
Comment #11
jsibley CreditAttribution: jsibley commentedSo, please, where does this leave us? I would like to format a date to show only the date without a time.
If this patch won't be committed what solution is there?
Thanks
Comment #12
jsibley CreditAttribution: jsibley commentedduplicate comment by mistake
Comment #13
TR CreditAttribution: TR commentedThis can be done in D8 using Data Filters. See https://www.drupal.org/docs/8/modules/d8-rules-essentials/token-replacem...
I have already contributed more than my share to getting that implemented.
There doesn't seem to be any community support for doing this in D7 - it's been more than 7 years since anyone contributed anything to this issue, despite there being ~250,000 users of D7 Rules. So I don't see any need to keep this issue open any longer.