NYCPHP Meetup

NYPHP.org

[nycphp-talk] Faced with a headache :D

CED Consult at CovenantEDesign.com
Mon Mar 20 18:08:13 EST 2006


Your issue lies here I believe:

 if($curday == 7) {
                                    $i = 0; 
                                    $curday = 6;
                                }
you're resetting curday instead od $day.
For above it you're assigning

$curday = $day + $i

so it's either pointless, or it's broke.

Edward J Prevost II
Senior Applications Specialist
SIS Project, Data Migration Lead
Albany Medical College
Albany Medical Center
Edward.Prevost at amc.edu
desk |  518.262.2743
cell |  518.331.5061
  ----- Original Message ----- 
  From: Joseph Crawford 
  To: NYPHP Talk 
  Sent: Monday, March 20, 2006 5:54 PM
  Subject: [nycphp-talk] Faced with a headache :D


  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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nyphp.org/pipermail/talk/attachments/20060320/45cbe3ce/attachment.html>


More information about the talk mailing list