All pastes #753119 Raw Edit

Anonymous

public text v1 · immutable
#753119 ·published 2007-10-28 23:37 UTC
rendered paste body
if(strpos($query, "-") === FALSE)
{
     $date = str_replace("_", " ", $query);
     $date = explode(" ", $date);

     $CurrentTime = time();

     $units = array("minute", "minutes", "hour", "hours", "day", "days", "week", "weeks", "month", "months", "year", "years");
     $months = array"january", "february", "march", "april", "may", "june", "july", "august", "september", "october", "november", "december");
     $maxdays = array("january" => "31", "february" => "28", "march" => "31", "april" => "30", "may" => "31", "june" => "30", "july" => "31", "august" => "31", "september" => "30", "october" => "31", "november" => "30", "december" => "31");

     if(count($date) == 1)
     {
          if(!is_numeric($date[0]))
               $errors['date'] = "Error: Invalid Unix timestamp.";
          elseif(strlen($date[0]) != 10)
               $errors['date'] = "Error: Invalid timestamp length.";
          else
               $querystr .= "date:$date;";
     }
     elseif(count($date) == 3)
     {
          if(in_array($date[0], $months))
          {
               if(!is_numeric($date[1]))
                    $errors['date'] = "Error: Invalid date.<br /><br />Dates must use the following syntax:<br/>1. <b>(Number) (Hours/Days/Weeks/Months) Ago</b><br />2. <b>(Month) (Numeric Date) (Numeric Year)</b><br />3. <b>(Unix Timestamp)</b>";
               elseif(!is_numeric($date[2]))
                    $errors['date'] = "Error: Since when are there non-numeric years?";
               elseif($date[2] < 2007)
                    $errors['date'] = "Error: Stop trying to search for shit from before Weedhat was even conceived.";
               elseif($maxdays[$date[0]] < $date[1])
               {
                    if($date[0] != "february")
                         $errors['date'] = "Error: That month doesn't have that many days.";
                    else
                    {
                         if((!LeapYear($date[2])) || ($date[1] > 29))
                              $errors['date'] = "Error: That month doesn't have that many days.";
                    }
               }
               else
                    $querystr .= "date:$date[0]_$date[1]_$date[2];";
          }
          else
          {
               if(!is_numeric($date[0]))
                    $errors['date'] = "Error: Invalid date.<br /><br />Dates must use the following syntax:<br/>1. <b>(Number) (Hours/Days/Weeks/Months) Ago</b><br />2. <b>(Month) (Numeric Date) (Numeric Year)</b><br />3. <b>(Unix Timestamp)</b>";
               elseif(!in_array($date[1], $units))
                    $errors['date'] = "Error: Invalid date.<br /><br />Dates must use the following syntax:<br/>1. <b>(Number) (Hours/Days/Weeks/Months) Ago</b><br />2. <b>(Month) (Numeric Date) (Numeric Year)</b><br />3. <b>(Unix Timestamp)</b>";
               elseif($date[2] != "ago")
                    $errors['date'] = "Error: Invalid date.<br /><br />Dates must use the following syntax:<br/>1. <b>(Number) (Hours/Days/Weeks/Months) Ago</b><br />2. <b>(Month) (Numeric Date) (Numeric Year)</b><br />3. <b>(Unix Timestamp)</b>";
               else
                    $querystr .= "date:$date[0]_$date[1]_$date[2];";
          }
     }
}