The field handler views_handler_field_date only works with unix timestamp fields.
With a small tweak it could also work on SQL datetime fields. This would allow contrib modules that have data in this format (such as https://drupal.org/project/data, potentially) to make use of this handler.
(Note that while the Date module's Views support isn't suitable for this purpose -- it in fact doesn't have a field handler, as it uses the default Views field handler for Field API fields.)
| Comment | File | Size | Author |
|---|---|---|---|
| #11 | allow-datetime-format-2178287-11.patch | 956 bytes | pythagory |
| #9 | allow-datetime-format-2178287-9.patch | 1.08 KB | natanmoraes |
| #1 | 2178287.views_.views_handler_field_date-datetime.patch | 1.06 KB | joachim |
Comments
Comment #1
joachim commentedHere's a patch.
The intention here is that contrib modules could declare this handler in their hook_views_data() for table fields that hold MySQL datetime data.
Comment #2
jblumenfeld commentedThis seems useful, but for completeness it would probably also need something to handle sort and filter?
Comment #3
joachim commentedIt's a few weeks since I worked on this, but I seem to remember that sort and filter work as they are.
Comment #4
Andre-BIf I understand correctly: currently a contrib module would have to extend the views_handler_field_date and override the render method to provide datetime support?
saw a reference here: http://drupal.stackexchange.com/questions/34261/creating-a-sortable-field
Comment #5
lucyp commentedThe patch works for me, and I really appreciate this change. Now I'm able to extend that handler in all kinds of useful ways. I vote that it gets incorporated into Views.
Comment #6
JulienThomas commentedInstead of patching date field handler, why not creating a specific field handler?
as even the patch suggest, the patch itself makes a big assumption
So why not going toward a field handler such as
that way, we still use views_handler_field_date and add a specific strtotime for SQL datatime fields plugged in from hooks_view_data.
obviously, you need to add the following line to module.info
files[] = handlers/module_handler_field_datetime.inc
Comment #7
berliner commentedparent::renderexpects the full$valuesobject, so this would be better:Comment #8
caminadaf commentedI'm sorry @JulienThomas, but I disagree with you. It is not pratical at all to have different field handlers for each "date" sql column.
Also, is it really such a big assumption to try to turn the value into timestamp if it isnt a numeric? Is there any possibility of this assumption to break something?
IMO this is such a simple change that can help so many people without any impact on the current functionality.
I believe this should be patched.
Comment #9
natanmoraesReworked the patch with latest dev code.
Comment #10
mustanggb commented#9 is just a straightforward re-roll, so back to RTBC as per #8.
Comment #11
pythagory commented#9 no longer applying for me after updating to 3.20, rerolled patch attached.
Comment #12
natanmoraes#11 also works for 3.21
Any chance this could be added to the next release? It's RTBC for 2 years already
Comment #13
damienmckennaComment #15
damienmckennaCommitted. Thanks!