Currently this module binds only to node.changed and node.created.
What about binding to all date fields?

An option is to loop against the data in
"function views_date_format_sql_views_data_alter(&$data) {"
And change the handler for fields already bound to a date handler.
Otherwise it seems that the structure has an "is_date" property that could be used.

Comments

zany’s picture

Status: Active » Postponed

A feature patch or sponsoring is welcome.

bago’s picture

Status: Postponed » Needs review
StatusFileSize
new1.21 KB

Here is my attempt.
Loops through fields looking for is date and the views_handler_field_date handler and replace it with the new one.
Not sure if it is good to have such a loop in this method for performance (don't know how often this method is called).

zany’s picture

Status: Needs review » Needs work

That patch illustrates the concept. It does not work in any sensible way though (for me at least?).
Did you try Krumo (devel module) on the hook data? There is no key 'is date' anywhere.
Also your scope is to broad. You'll catch fields like Feeds import date, and file upload dates. Then the custom fields definitions are one level deeper afaik.

Thanks for sketching the idea though!

bago’s picture

@zany it works fine here with that patch (i'm using it in 2 sites). I don't know if "is date" is created from some other module I installed. I didn't notice issues on other sides.

zany’s picture

Status: Needs work » Needs review

Ok. Let's keep it around as 'Needs Review' and get some comments on it.

The problem could be on my end. I do see the 'is date'-key in the Date module, but it doesn't show up in the hook data. Maybe an issue with module ordering.

Do you get the functionality on 'created' and 'changed' fields? Those are not from the Date module and don't have 'is date'. Does Date override something there for you?

Thanks.

webflo’s picture

Yes date_views module add a "is date" to all date fields in date_views_views_data_alter().

bago’s picture

I see options:
1) leave the changed+created alterations and add my loop so to support the date module.
2) remove the "is date" check in my loop and simply rely on the name of the previous handler.

I see no harm in #2, so I think we could simply go with it and it should zany issues.

zany’s picture

StatusFileSize
new1.1 KB

Thanks webflo, I didn't enable the date views module here:)
Bago, option 2 looks fine and works.
I'm still concerned about the scope. This walks across all modules and tables. do we really want all these?

comment created
comment changed
feeds_item imported
feeds_log log_time
feeds_log request_time
node created
node changed
node_revision timestamp
file_managed timestamp
users created
users access
users login

(Feeds is the only non-core here as an example).
It might be nice to have it on all core fields, and it's opt-in after all... Thoughts?

bago’s picture

We don't know what users will want to use in their views, so it sounds right to do this on all of them.
Either way we only enable the rewrite for fields where people flagged the checkbox.

I didn't test if it works against every field, but in my case I needed it to work in a custom field (and it works fine).

(in fact the sql rewrite behaviour should be used by default by views as the "current default option" produces unexpected results if you try to group by things).

zany’s picture

Strangely enough my Date-module fields are marked with views_handler_field_field not views_handler_field_date. Once I figure that out this patch gets released. Thanks again!

jurriaanroelofs’s picture

patch #2 works fine for me, I can now SQL-format commerce entity fields. Probably it should also patch the .info file to list date_views as a dependency.

zany’s picture

@JurriaanRoelofs can you try patch #8?
Also note that this module works without the Date module (for Created & Changed fields). So Date or Date_views are not a dependency.

jeremymcminn’s picture

Jurriaan - does this work for Commerce order date fields? I've applied patch #2 however no checkbox shows up on my order date field settings.

jeremymcminn’s picture

StatusFileSize
new24 KB

Managed to get it showing, all working great for aggregation apart from the fact that it doesn't seem to sort by date. Adding a date sorting rule stops the aggregation from working.

See attached for without the date sorting, the months are in random places.

jeremymcminn’s picture

For some reason adding MIn or Max to the aggregation settings for date field in sort criteria managed to get this in the right order.

jurriaanroelofs’s picture

I dont use min and max. I'll try to make time for this tomorrow.

jeremymcminn’s picture

Cool - seems to be working fine for me at present with the Min & Max, no idea why though!

jurriaanroelofs’s picture

Status: Needs review » Reviewed & tested by the community

Sorry for the slow reply. I just tested patch #8 and it works fine too.

zany’s picture

Assigned: Unassigned » zany
Status: Reviewed & tested by the community » Closed (fixed)
bennos’s picture

hm. I did not get it on date field of a content type. date views module is enabled.

I tried one of the core fields and it works.

how can i figure out the problem? and how can I get it work?

zany’s picture

@bennos did you use the new 3.1 version? If you know php you can use the devel module and dpm() to inspect the data structure in the hook. http://drupalcode.org/project/views_date_format_sql.git/blob/HEAD:/views...

mpisano’s picture

It works on core fields ok, but I'm trying to apply to a date field in a field collection entity and doesn't work.
Any help?
Thanks

patsch_lux’s picture

I like to use this also for date fields created by myself, not just for the core dates like node.changed, node.created and so on.

Please can anybody help me?

I tried do make a new class:

class views_date_format_sql_handler_field_MYDATEFIELDS extends views_handler_field_field {
same code
}

I remove this code:

 &&
         ($field['field']['handler'] == 'views_handler_field_date')

from the function views_date_format_sql_views_data_alter(&$data) .

Now i have the checkbox "Use SQL to format date" at my date fields, but it doesn't work.

Edit:
I got these errors:

Error message
Notice: Undefined index: date_format in views_date_format_sql_handler_field_date->query() (line 38 of
modules/views_date_format_sql/includes/views_date_format_sql_handler_field_date.inc)
Notice: Undefined index: custom_date_format in views_date_format_sql_handler_field_date->query() (line 39 of
modules/views_date_format_sql/includes/views_date_format_sql_handler_field_date.inc)

Thx for helping me.

zany’s picture

Please do not comment on closed issues. Open a support request ticket. Give more detail: what modules did you enable what exactly is the setup.