This feature request is for extending the options and features of the handler field date. Features added are:
- Best UI date format options with the format date name in the select options, in order to know what is the format of each option.
- add support for custom date formats defined with the Date API module if it's installed, this way you can use defined default formats for all the drupal site instead that by view.
- Allow to the SQL query to use the defined date format instead the standard unixtime. ( Only valid for Custom Date Formats and Date API defined formats). This way you can have a kind of "group by". For example, if you have your date results on the June/10 format instead of the full unixtime unique code you can have all the items with the same date format with the same value in the other way each item have a unique value.
I know about all the long discussions regarding date formats, and I would just like to give more options instead doing changes or discussing existing configurations.
This feature is complemented by this other feature request #755342: Add more date format string to views_date_sql_format that allows use almost all the php date functions formats.
| Comment | File | Size | Author |
|---|---|---|---|
| #43 | views-date_format_in_sql-844202-43.patch | 6.65 KB | andrew answer |
| #38 | views-date-format-in-sql-844202-38.patch | 7.67 KB | dawehner |
| #36 | 844202.patch | 0 bytes | dawehner |
| #34 | views-date-format-in-sql-844202-24.patch | 6.53 KB | dawehner |
| #24 | views-date-format-in-sql-844202-24.patch | 4.89 KB | dealancer |
Comments
Comment #1
jcmarco commentedComment #2
robby.smith commentedHello,
I applied the patch and tested to see the new feature.
I was not clear on what/where to see for the new features.
I was hoping to be able to have for the exposed date filter control over how it is shown. Being able to specify [YYYY] [MM] [DD] or [MM] [DD] [YYYY] for the select list dropdown depending on the filter would be awesome.
Comment #3
merlinofchaos commentedTypically, date.module should do stuff like this by overriding the default handler.
Comment #4
YK85 commentedsubscribing
Comment #5
YK85 commentedCould someone re-roll the patch so it applies on Date 6.x-2.x-dev?
Thank you!
Comment #6
robby.smith commentedDoes the patch apply to the View module or Date module?
Comment #7
YK85 commentedIt would be great to allow custom date formats.
Thank you
Comment #8
dealancer commentedHere is a patch for D7. I have found that in D7 version of Date API function date_get_format_types() does not exists, so I have deleted all calls and usage of it.
Comment #9
dealancer commentedComment #10
karens commentedYou already can use any custom format you want by creating a custom format at admin/config/regional/date-time. You can create any number of custom formats (Time, Date-only, whatever) using anything that php supports. I am not going to layer on top of that yet another way to configure formats.
I can't tell what the end goal is here. If this is just to be able to group dates, we don't do that by altering the query, the grouping is done using the php format in the pre-render phase. And that already works, we don't need to change anything.
Comment #11
dealancer commentedI have ported only ability to use custom format in SQL. This is useful when you want to get distinct set of dates for the nodes. So it now allows views to generate query like this:
This is very nice feature for the date module. However there could be different approaches of making that. Need your advice.
P.S. There is another pending patch for views that fixed some problems with DISTINCT: http://drupal.org/node/1245010
Comment #12
dealancer commentedAnd here is a patch in the proper format.
Comment #13
karens commentedThis is a patch to Views, there is nothing I can do with this patch. And I already noted in #10 that I can't see that you're doing anything here that isn't already possible.
Comment #14
dealancer commentedI haven't find how we could make this using grouping for node post date.
Mytask is to show distinct set of node creation years.
I do following:
1) Create view
2) Enable grouping
3) Add Node Post date and apply custom format (Y) to it.
4) Add nid field and change groping settings to SUM.
5) Add some sorting, limit and filters
I get following query:
I don't see any formatting in sql query. Is this a way how to do it you was talking about in comment #10?
P.S.
Agreed with you that it is more views issue.
Comment #15
dealancer commentedIn #12 I have uploaded wrong patch. Here is correct one.
Comment #16
dealancer commentedI am going to rewrite it for views module soon.
Comment #17
dealancer commentedComment #18
dealancer commentedFinally done!
I have rewritten patch for views 7.x-.x for date field handler. It adds an option to use format in query. This feature applicable for all format except of Time ago, Time hence and Time span formats.
Here is a patch!
Comment #19
podaroktrailing whitespaces http://drupal.org/coding-standards#indenting
Comment #20
dealancer commented@podarok, thx for review.
Here is a new patch with fixed spaces in the end of lines.
Comment #21
podarokview for testing
with patch
returned SQL with patch #20
and without patch
looks like working for me
so RTBC?
Comment #22
dawehnerSome comments but in general it looks fine!
Better directly access $this->options['date_format']. That's much easier to understand.
Can't you do this whole check on validation and add this behaviour to the #depedency as well?
Please add a new line for the else
It's sort of a problem that we loose the feature of translating the value, but i'm not sure whether it can be supported.
Comment #23
dealancer commentedTogether with nobody__ we have updated this patch. Following things have been done:
1) Added ability to process grouping and aggregation into query() method.
2) Fixed formatting errors.
3) Added validation and dependency to the options form.
Here is a patch.
Comment #24
dealancer commentedHere is a previous patch with fixed spacing issues.
Comment #25
dealancer commentedLooks like there are separate module for this: http://drupal.org/project/views_date_format_sql, which is used by 22 sites.
Any ideas to commit this functionality to the Views module?
Comment #26
podarokLet ask module maintainer for #25 merging codebase from this patch and views_date_format_sql
Comment #27
zany commented@dealancer thanks for the heads up. @podarok did you attach this thread to my project "Views Date Format SQL" by accident?
I briefly read the patch. Looks like almost the same code. Anything particular that needs to be added/fixed in "Views Date Format SQL"?
(compare the patch to: http://drupalcode.org/project/views_date_format_sql.git/blob/HEAD:/inclu... )
Comment #28
dealancer commentedI think so, so I am changing back the project.
Can anyone review my patch?
Comment #29
dealancer commentedComment #30
akoepke commentedI have been trying to get this date formatting in the SQL query working on my site and have gotten nowhere with it.
I have tried the Views Date Format SQL module plus other patches around the site and found they only work for the core date fields like Post Date. They don't seem to work for fields from the Date module.
Can someone point me in the right direction to get this working. Is it a Views issue or a Date module issue?
Comment #31
zany commentedThe sorting in "Views Date Format SQL" and this patch is for date fields. The Date module provides different fields with custom handlers. Support for the Date module can be added easily. A feature patch or sponsoring is welcome.
Comment #32
tim.plunkettRefiling. Patch looks reasonable, but I still don't understand why it wasn't left closed after KarenS pointed out it wasn't necessary.
Comment #33
dealancer commentedThanks for a question and updating category. I will shed light on this.
Issue and patch have been involved since issue was created. Now patch uses Drupal date formats as suggested by KarenS. So the initial patch is outdated.
The new patch allows date format (including custom) to be applied in SQL. By default it is applied in PHP layer. Benefit is a possibility to group by e.g. Year, but without this patch groupping works by second.
Comment #34
dawehnerI tryed to write some tests for that though they aren't working yet as expected.
Comment #36
dawehnerI somehow get the intentation that there are timezone issues on that patch.
Just look at the failures of the test, i think this is actually not what we would accept.
Comment #38
dawehnerHere is a new one.
Comment #40
WorldFallz commentedThis patch is years old-- is it worth updating or is everyone just using views_raw_sql?
Comment #42
andrew answer commentedThis patch needs reroll.
Comment #43
andrew answer commentedPatch rerolled.