Hi,
I am trying to have a Date argument work as intended without success.

In my example I have two nodes, one created 12 October 2010, another created 13 October 2010.
I created a View with a Date(node) argument.

As a Date Field(s) I checked "Node: Post date"
As granularity I checked "hour"

Now I run it at:

www.mysite.com/myview/DATEARGUMENT

and the behaviour is this:
1) if DATEARGUMENT is 2010-10-12 both posts are shown (wrong, only the one created in that date should be shown)
2) if DATEARGUMENT is 2010-10-13 both posts are shown (wrong, like above)
3) if DATEARGUMENT is 2010-10-11 no post is shown (correct)
4) if DATEARGUMENT is xyz or other random strings, both posts are shown (wrong)

I just want to display nodes created in the Argument's DAY. What am I doing wrong?

CommentFileSizeAuthor
#3 Capture.JPG108.23 KBarlinsandbulte

Comments

arlinsandbulte’s picture

The granularity of your argument setting should be set to "day"

Aldus’s picture

Category: bug » support

I did it right now, tested it, the situation is still the same. Might an export of my view be of any help?

arlinsandbulte’s picture

StatusFileSize
new108.23 KB

I've never really tried either importing a view or deciphering the output.
Here is a screenshot of a quick view I created with argument settings that seem to work for me.

Aldus’s picture

Category: bug » support

Seems identical to what I have. WHen you give the argument, do you pass it as YYYY-MM-DD ?

I call my page this way:

http://mysite.com/myview/2010-10-13

arlinsandbulte’s picture

Pretty much, yes.
I use a path of http://mysite.com/view_path/2010-10-13

Aldus’s picture

It seems like working if I use Node Revision: Created as an argument. But i.e. doesn't work with the Node Updated date.

Setting the date argument as Node: Updated (granularity Day) and Calling:

www.mysite.com/myview/2010-10-13

gives me also a result for a node which was updated 2010-10-12. This is proved by the use of the Node: Updated date Field, which is clearly outputting 2010-10-12.

Maybe I should turn this to a bug report

Aldus’s picture

Category: support » bug
Aldus’s picture

Category: support » bug

The mistake seems to be located in the generated query.
To reproduce simply create a view, add Node: Title as a field and a Date(Node) as an argument. Pick node(updated date) as date field and "Day" as granularity. Then run the view passing as argument the value 2010-10-12... It will generate this query:

SELECT DISTINCT(node.nid) AS nid,
   node.title AS node_title,
   node.language AS node_language
 FROM node node 
 LEFT JOIN node node2 ON node.tnid = node2.tnid
 WHERE (DATE_FORMAT(ADDTIME(FROM_UNIXTIME(node2.changed), SEC_TO_TIME(7200)), '%Y-%m-%%d') <= '2010-10-12' AND DATE_FORMAT(ADDTIME(FROM_UNIXTIME(node2.changed), SEC_TO_TIME(7200)), '%Y-%m-%%d') >= '2010-10-12')
 GROUP BY nid

This query is wrong and returns ALL THE NODES as soon as it finds some node which was updates in that date!

The correct query would be this one:

SELECT DISTINCT (
node.nid
) AS nid, node.title AS node_title, node.language AS node_language
FROM node
WHERE (
DATE_FORMAT( ADDTIME( FROM_UNIXTIME( node.changed ) , SEC_TO_TIME( 7200 ) ) , '%Y-%m-%d' ) <= '2010-10-12'
AND DATE_FORMAT( ADDTIME( FROM_UNIXTIME( node.changed ) , SEC_TO_TIME( 7200 ) ) , '%Y-%m-%d' ) >= '2010-10-12'
)
GROUP BY nid
LIMIT 0 , 30

I'm not sure I'm able to patch it, but I'll give it a try

Aldus’s picture

interesting update: if I use the node revision: Created Date filter, the bug doesn't appear: the SQL code is in facts correct (see below).

SELECT DISTINCT(node.nid) AS nid,
node.title AS node_title
 FROM node node 
 LEFT JOIN node_revisions node_revisions ON node.vid = node_revisions.vid
 WHERE (DATE_FORMAT(ADDTIME(FROM_UNIXTIME(node_revisions.timestamp), SEC_TO_TIME(7200)), '%Y-%m-%%d') <= '2010-10-11' AND DATE_FORMAT(ADDTIME(FROM_UNIXTIME(node_revisions.timestamp), SEC_TO_TIME(7200)), '%Y-%m-%%d') >= '2010-10-11')
 GROUP BY nid

Unfortunately for my application is trivial to select only nodes filtered by updated date and a range (which is the reason to use DateAPI instead of the standard Node: Updated Date field).
If there is something I can look in to help please let me know, thanks

arlinsandbulte’s picture

Here is the SQL code I get which is working...

SELECT node.nid AS nid
 FROM node node 
 WHERE (DATE_FORMAT(CONVERT_TZ(FROM_UNIXTIME(node.created), 'UTC', 'America/Chicago'), '%Y-%m-%%d') <= '2010-10-13' AND DATE_FORMAT(CONVERT_TZ(FROM_UNIXTIME(node.created), 'UTC', 'America/Chicago'), '%Y-%m-%%d') >= '2010-10-13')

This was made with a newly created view. The ONLY things I did to the view was add the argument as above & added a page display.
No filters, no sorting, no relationships...

Aldus’s picture

Interesting... I also pasted code from a newly created view.

The presence of this in my code:

LEFT JOIN node node2 ON node.tnid = node2.tnid

is probably related to translations/multilingual system (it checks tnid). Do you make use of locale / i18n?

However I'm going to try it in a fresh install and see what comes out.

Aldus’s picture

I confirm that the bug appears when the Content translation module is enabled. Unfortunately I have no idea where to get started to work on it, where is the problem born? In DateAPI, in Views, in Content translation?

Some workaround using relationships?

The bug is blocking for anyone needing to use DateAPI arguments in a multilingual site.

drinkingcoffee’s picture

Category: support » bug

I can confirm this on my site.
That extra LEFT JOIN node node2 ON node.tnid = node2.tnid makes mysql *very* upset.
I can also confirm that switching from using the Date API to Node:updated seems to do the trick.

Now I'm going to have to hunt through all the views on this site to see if this problem is appearing elsewhere (but with less noticeable effects).

kdebaas’s picture

subscribing

Ecio’s picture

same problem here, looks like the problem is related to Date API:
http://drupal.org/node/904038
http://drupal.org/node/477068

i think i will switch from Date to Node:Created (another workaround seems to be disabling content translation module)

subscribing.

Aldus’s picture

I think those are not workarounds for anyone using a multilingual site. Also, I need to use date range features (like 2009-12-20--@).
If someone has some hints about how to get started fixing this, would be appreciated

rup3rt’s picture

Subscribe

MichaelP’s picture

Confirming the LEFT JOIN node node2 ON node.tnid = node2.tnid phenomenon on a multilingual site.

Bit of a show stopper, but a workaround I am able to use is the Node: Created year + month argument, which doesn't seem to suffer from this issue.

MichaelP’s picture

Status: Active » Fixed

Actually patch at #904146: Double join on the node table when using the date argument for the node creation date seems to fix this.

Marking this as fixed, as from the heading it hardly seems like a dupe.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.