Moved here from comment on front page:

Posted by kirikintha on January 7, 2010 at 11:02am

More of an FYI, rather than a bug report, I ran into an interesting problem with a content type I had started over a year ago.

Environment:
Drupal 6.x
Date, Date API, etc 6.x-2.2
Views 6.x-2.6

Due to the client's request, they needed us to separate granularity in the Date fields on an event calendar they were making into Seprate CCK Fields.

We would have liked to have had one CCK field, for a Day, Month, Year, beginning and ending time in one CCK field. However, the client had asked us to separate the granularity into three separate fields:

Field 1: Granularity - Year, Month, Day as Event Day

Field 2: Hour:Minute:Second as Beginning time

Field 3: Hour:Minute:Second as Ending time

Not our recommendation, but when they are paying the bills, you acquiesce.

After creating the content type, we then made a View that sorted 1st for Field 1 (The Day) and then Field 2 (The Time) to show a tabled view of the events, grouped by day.

Everything worked as expected, the sorting and grouping were no problem... until the year changed.

All of a sudden, our sorting was incorrect, and items were not sorting correctly:

Example of Bad Sort:

January 10, 2010 - 08:00am - 10:00am
January 10, 2010 - 09:00am - 10:00am
January 10, 2010 - 13:00pm - 15:00pm
January 10, 2010 - 08:00am - 10:30am

As you can see, the sorting is incorrect, and I had a hard time thinking about what was happening, so I cloned the view and made a views-view-myviewname.tpl file to output the arrays coming from views.

What I found was This:

When you entered an event in 2009 (The node creation date is in the year 2009) This is the array that printed out for the fields (This may not be totally correct, but the values are right, sorry i can't remember the actual key)

Field 1 (Day) - 01-10-2010T00:00:00
Field 2 (Beginning Time) - 01-01-2009T08:00:00
Field 3 (Ending Time) - 01-01-2009T10:00:00

When you create an event in 2010: (The node creation date is in the year 2010)

Field 1 (Day) - 01-10-2010T00:00:00
Field 2 (Beginning Time) - 01-01-2010T08:00:00
Field 3 (Ending Time) - 01-01-2010T10:30:00

So, as you can see - The Month, Day, Year key for Fields 2 && 3 are different, depending on when you made the event!

Voila, now you can see why those events where sorting unnaturally. And, I had to re-key my views $rows, and make them work, because there were too many events to go in and re-populate all of them, and the client would have ripped me a new on if I changed their precious form.

Long story short, IMHO, the best practice is NOT to separate granularity into different fields, if at all possible. If you do have to separate granularity, and you are trying to sort in views, or, sort in any case - you will need to re-key the array populated to have the proper keys you need, in the proper places. You could accomplish this many ways, but the point of this is just to illustrate how you can make a mistake in setting up your content type, and not even see an effect till you are very far removed from the project.

Happy Coding!

-k

Nothing unreal exists.