[nycphp-talk] Faced with a headache :D
Brian O'Connor
gatzby3jr at gmail.com
Mon Mar 20 18:10:52 EST 2006
I'm a little confused as to what you're doing here:
$i = $day;
$curday = $day + $i;
if($curday == 7) {
$i = 0;
$curday = 6;
}
If the current day is Saturday, then the $day variable will hold 6 (I
believe).
You're then saying that $curday has a value of 12, (because you're adding
$i, which has an initial value of 6), which shouldn't happen (I don't think
at least), which in effect would bypass the check if $curday is 7.
Hope that helps shed some light on why the code is acting weird.
On 3/20/06, Joseph Crawford <codebowl at gmail.com> wrote:
>
> Hey guys,
>
> I have a database of vendors, each have different days and times they are
> open from.
>
> now what i need to do is this
>
> check to see if the vendor is open at the current time, if not i need to
> check the next day, then the next, etc..
>
> I have some simple code that is not in working form, that is this
>
>
> $time = '';
> $day = date('w');
> $days = 1;
>
> // getLeadTime() returns a time in minutes,
> converting to seconds so we can add it to the timestamp.
> $leadTime = 60 * $location->getLeadTime();
>
> $i = $day;
> while($i <= 6) {
> $curday = $day + $i;
> if($curday == 7) {
> $i = 0;
> $curday = 6;
> }
> // getOpenTime() returns a string such as
> 10:00:00 or 23:30:00
> $timeStr =
> $location->getOpenTime($curday);
> // if $timStr is = 00:00:00 then it needs
> to continue on to the next loop
> if($timeStr == '00:00:00') {
> $i++;
> $days++;
> continue;
> }
> }
> // now we need to get the timestamp, this is
> where the strtotime converts the string from getOpenTime to a timestamp and
> we add the leadTime
> $vendorOpenTime =
> strtotime($location->getOpenTime($day + $days)) + $leadTime;
>
> Now the above code works fine if they are closed on Monday and not open
> again until Thursday, the trouble lies in being closed Sat and Sun, it
> doesnt flip over to Monday. it just says get it delivered today, even if
> they are closed the current day.
>
> Anyone who can help me with this i would appreciate it, i wouldnt even
> mind paying someone to help me nail this logic :D I have spent pretty much
> about 5 hours on this and i think i just need another brain to pick at it :)
>
>
> Thanks,
> --
> Joseph Crawford Jr.
> Zend Certified Engineer
> Codebowl Solutions, Inc.
> http://www.codebowl.com/
> 1-802-671-2021
> codebowl at gmail.com
>
> _______________________________________________
> New York PHP Community Talk Mailing List
> http://lists.nyphp.org/mailman/listinfo/talk
> New York PHP Conference and Expo 2006
> http://www.nyphpcon.com
> Show Your Participation in New York PHP
> http://www.nyphp.org/show_participation.php
>
>
>
--
Brian O'Connor
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nyphp.org/pipermail/talk/attachments/20060320/5d93ce42/attachment.html>
More information about the talk
mailing list