Welcome, Guest. Please login or register.
Did you miss your activation email?


Login with username, password and session length

Search

 
Advanced search

8043 Posts in 1856 Topics- by 2099 Members - Latest Member: roi
Calendar Script CommunityCustomizationHacks and Mods (Moderators: scott, DanO, Marty)DoubleCal time sort question
Pages: [1]   Go Down
Print
Author Topic: DoubleCal time sort question  (Read 296 times)
0 Members and 1 Guest are viewing this topic.
Sarah
New Member
*

Karma: 0
Offline Offline

Posts: 0


WWW
« on: August 28, 2004, 03:31:00 PM »

Hello All,

I am in the midst of my first installation of Matt's excellent CalendarScript.  DanO's DoubleCal mod was exactly what I needed for this site, so I purchased it(well worth the price)yesterday.

The problem I am having is that the list of events is displaying sorted by the time, ignoring am and pm.  In other words, the event scheduled for 7 p.m. is showing before the one scheduled for 11 a.m., apparently because 7 comes before 11, without regard for the a.m. or p.m.

Based upon another post to these forums, I've added this code, all on one line immediately above the two places in default.html (formerly doublecal.html) that read <%FOREACH EVENT%> :

<% @$EVENTS = sort {$a->{schedule}->{start_time} <=> $b->{schedule}->{start_time} } @$EVENTS; %>

You can see the results (please look at October 2, as an example)here:   http://www.campbellsmazedaze.com/cgi-bin/calendar.pl

It is entirely possible that I've missed changing a preference somewhere, or that I can't see the forest for the trees, not an uncommon occurrence, especially when I'm fighting deadlines and learning curves concurrently.

I'm grateful for any help,
Sarah

P.S. BTW, as soon as I get this working so the client is satisfied with the sort, I will get paid, and as soon as I get paid, I will glady forward the payment I owe to Matt.  

Logged
DanO
Moderator
Full Member
*****

Karma: 13
Offline Offline

Posts: 230

Please don't PM me. Post in the open forum.


WWW
« Reply #1 on: August 29, 2004, 12:13:00 PM »

** apparently because 7 comes before 11, without regard for the a.m. or p.m. **

The schedule times are stored as 24 hour notation (eg. 0900, 1100, etc.) so they should sort properly on that field. Maybe your system is dropping the leading 0 and causing the problem?

You can try changing your added line to the following to sort them as strings which should maintain the leading zero if present:

<% @$EVENTS = sort {$a->{schedule}->{start_time} cmp $b->{schedule}->{start_time} } @$EVENTS; %>

The only difference is cmp in place of <=>

Dan O.


[This message has been edited by DanO (edited August 29, 2004).]

Logged
Sarah
New Member
*

Karma: 0
Offline Offline

Posts: 0


WWW
« Reply #2 on: August 29, 2004, 12:40:00 PM »

Dan O.,

Replacing <=> with cmp did the trick.  I very carefully entered the leading 0's where appropriate so am not sure why the string comparison is necessary to sort correctly.  Thank you VERY much for the prompt response, and on a weekend, too!  

Now I can see about getting Matt Paid!

Sarah

**You can try changing your added line to the following to sort them as strings which should maintain the leading zero if present:

<% @$EVENTS = sort {$a->{schedule}->{start_time} cmp $b->{schedule}->{start_time} } @$EVENTS; %>

The only difference is cmp in place of <=>

------------------

Logged
DanO
Moderator
Full Member
*****

Karma: 13
Offline Offline

Posts: 230

Please don't PM me. Post in the open forum.


WWW
« Reply #3 on: August 29, 2004, 02:31:00 PM »

** Replacing <=> with cmp did the trick. **

Glad to hear it.

Dan O.

------------------

Logged
Pages: [1]   Go Up
Print
Jump to: