The problem

OK... I'm feeling rather foolish right now, but I can't seem to figure out a good way to solve this seemingly simple problem.

I have an application that is looking up values from a time schedule. Depending on when the lookup is run it is possible to wrap around from say 23:00 past midnight in the list of desired values. I want to keep the rows sorted by relative time with the wrapped around (does that term make sense?) rows kept as being chronologically after the pre midnight rows.

I've come up with a brute force method, anymonk out there have an elegant way of doing this?

The data is stored in a PostgreSQL database with a schema that looks sorta like this (confidential info has been obfuscated).

create sequence event_id_seq; create table schedule ( event_id integer not null default nextval('event_id_seq'), event_start time not null, event_end time not null, event_descriptor varchar(50) not null, primary key (event_id) );

The application in one mode looks for events that happen within a window starting at an arbitrary time plus 3 hours and in the other mode looks for the next "n" events from an arbitrary time.

These are daily scheduled events where the schedule might change every 3 months or so. The end application schedules other events to happen in lead of the events retrieved. IE if an event as happening at 23:10 the other event has to happen at 22:50 (30 minutes prior) and is used to schedule activities of some employees.

Anybody have ideas?


Peter L. Berghold -- Unix Professional
Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg

In reply to Midnight wraparound. by blue_cowdawg

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.