TinyPortal

Development => Support => Topic started by: tomtom9800 on June 29, 2008, 05:06:40 AM

Title: timestamp error?
Post by: tomtom9800 on June 29, 2008, 05:06:40 AM
Hi I am starting to receive this error reported from several members, I am kinda lost with this one, anyone know a fix to this?

2: date() [<a href='function.date'>function.date[/url]]: Windows does not support dates prior to midnight (00:00:00), January 1, 1970
File: C:\xxxxxx\xxxxx\xxxxxx\wwwroot\forum\Themes\default\TPortal.template.php (eval?)
Line: 97

Any help would greatly be appreciated.
Title: Re: timestamp error?
Post by: JPDeni on June 29, 2008, 05:58:47 AM
Please follow the posting guidelines -- http://www.tinyportal.net/index.php?topic=581.0 -- to help us help you better.

Also, if you could figure out what users are doing when they get the error, it would be a big help as well.
Title: Re: timestamp error?
Post by: tomtom9800 on June 29, 2008, 01:24:52 PM
Sorry about that, I am using TP 0.9.8 and in the error log, this is what is being shown.....

  Today at 02:22:04 am 
xxx.xxx.xxx.xxx     fb4de31863ac870fc8484be233e738e1 
http://www.aceshigh.ws/forum/index.php?www 
2: date() [<a href='function.date'>function.date</a>]: Windows does not support dates prior to midnight (00:00:00), January 1, 1970
File: C:\xxxxxx\xxxxxx\xxxxxx\wwwroot\forum\Themes\default\TPortal.template.php (eval?)
Line: 97

   _AH_Foxbat   Today at 02:22:04 am 
xxx.xxx.xxx.xxx     fb4de31863ac870fc8484be233e738e1 
http://www.aceshigh.ws/forum/index.php?www 
2: date() [<a href='function.date'>function.date</a>]: Windows does not support dates prior to midnight (00:00:00), January 1, 1970
File: C:\xxxxx\xxxxxx\xxxxxx\wwwroot\forum\Themes\default\TPortal.template.php (eval?)
Line: 97

   _AH_Foxbat   Today at 02:21:25 am 
xxx.xxx.xxx.xxx     fb4de31863ac870fc8484be233e738e1 
http://www.aceshigh.ws/forum/index.php?www 
2: date() [<a href='function.date'>function.date</a>]: Windows does not support dates prior to midnight (00:00:00), January 1, 1970
File: C:\xxxxx\xxxxxx\aceshigh.ws\wwwroot\forum\Themes\default\TPortal.template.php (eval?)
Line: 97

Title: Re: timestamp error?
Post by: G6Cad on June 29, 2008, 01:34:03 PM
What on your site or server holds a time set on that date ?  Nothing in eather SMF or TP holds anything even near that.
Title: Re: timestamp error?
Post by: JPDeni on June 29, 2008, 05:21:22 PM
tomtom9800, I *really* need you to completely follow the posting guidelines. It's vitally important for me to be able to see all of the information in the guidelines so that I can have a clue as to what might be causing it. I know that the error message says the file is in TPortal.template.php, but that doesn't mean that it is in that file. The fact that it also says (eval?) indicates that the problem is in some other code.

Actually, it's likely that the problem is somewhere in a block. I went to your site and saw that you have a calendar block, but it's working correctly, so the problem isn't there. Is there another block that has a timestamp?

Here's a little something you can do to narrow it down. Turn off all of your blocks. Clear your error log. Go to your index page. Go to your error log and see if there's an error. If there is, then the problem is with the file, and not in a block. If there isn't, turn on one block. Go to your index page. Go to the error log to see if there's an error. Repeat the turning on one block at a time and checking the results until you get the error in your log. You will then know which block is causing your error.

At that point, you can come back here and post the code for the block -- please use the [ code ] tags to make it readable. The problem is likely on line 97 or before that in the block. We'll help you to figure out how to fix the problem.

G6, the error that was posted indicates that somehow a timestamp is computed as a negative number.
Title: Re: timestamp error?
Post by: IchBin on June 29, 2008, 06:01:00 PM
Do you have any articles on your site with the date set that far back?
Title: Re: timestamp error?
Post by: tomtom9800 on June 30, 2008, 11:14:31 PM
JP, I am sorry I could not go by the guidelines.....I was typing this on my blackberry while on the road.......but here is what I think is causing the problem at it is the calendar.........here is the code:

global $scripturl, $modSettings, $context, $db_prefix, $user_profile;

smf_loadCalendarInfo();

$now = mktime() + $modSettings['time_offset'] * 3600;

$today = date('j',$now);
$year = date('Y',$now);
$month = date('n',$now);

$days = array($today=>array(NULL,NULL,'<a class="smalltext" style="color:steelblue; font-weight:bold; border:solid 1px black; background-color: white; padding: 0px 4px 0px 4px;" href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$today.'" target="_self">'.$today.'</a>'));

$day_name_length = 2; // Change for more letters

$month_href = $scripturl . '?action=calendar&month=' . $month;
$first_day = 0;
$pn = array();

$first_of_month = gmmktime(0,0,0,$month,1,$year);

$day_names = array();                                      #generate all the day names according to the current locale
for($n=0,$t=(3+$first_day)*86400; $n<7; $n++,$t+=86400)    #January 4, 1970 was a Sunday
    $day_names[$n] = ucfirst(gmstrftime('%A',$t));         #%A means full textual day name

list($month, $year, $month_name, $weekday) = explode(',',gmstrftime('%m,%Y,%B,%w',$first_of_month));

$weekday = ($weekday + 7 - $first_day) % 7;                #adjust for $first_day
$title   = htmlentities(ucfirst($month_name)).' '.$year;   #note that some locales don't capitalize month and day names

@list($p, $pl) = each($pn); @list($n, $nl) = each($pn); #previous and next links, if applicable
if($p) $p = '<span class="smalltext">'.($pl ? '<a href="'.htmlspecialchars($pl).'">'.$p.'</a>' : $p).'</span> ';
if($n) $n = ' <span class="smalltext">'.($nl ? '<a href="'.htmlspecialchars($nl).'">'.$n.'</a>' : $n).'</span>';
$calendar = '<table>'.'<caption >'.$p.($month_href ? '<a href="'.htmlspecialchars($month_href).'">'.$title.'</a>' : $title).$n.'</caption><tr>';

/////////////////////////////////////////////////////////////////
//   CALENDAR SECTION
//
if($day_name_length){                                      #if the day names should be shown ($day_name_length > 0)
    foreach($day_names as $d)
    $calendar .= '<th class="smalltext" abbr="'.htmlentities($d).'">'.htmlentities($day_name_length < 4 ? substr($d,0,$day_name_length) : $d).'</th>';
    $calendar .= '</tr><tr style="text-align:right;">';
    }

if($weekday > 0) $calendar .= '<td class="smalltext" colspan="'.$weekday.'"> </td>'; #initial 'empty' days

for($day=1,$days_in_month=gmdate('t',$first_of_month); $day<=$days_in_month; $day++,$weekday++){
    if($weekday == 7){
        $weekday   = 0; #start a new week
        $calendar .= '</tr><tr style="text-align:right;">';
        }

    if(isset($days[$day]) and is_array($days[$day])){
        @list($link, $classes, $content) = $days[$day];
        if(is_null($content))  $content  = $day;
        $calendar .= '<td '.($classes ? ' class="'.htmlspecialchars($classes).'">' : '>').($link ? '<a href="'.htmlspecialchars($link).'">'.$content.'</a>' : $content).'</td>';
        }
    else
        {
        $calendar .= '<td class="smalltext" style="padding-right:4px;"><a';
        if(((($weekday+$first_day) % 7)==0)||((($weekday+$first_day) % 7)==6))
            {
            $calendar .= ' style="color:#C00000;"';
            }
        $calendar .= ' href="'.$scripturl.'?action=calendar;sa=post;month='.$month.';year='.$year.';day='.$day.'" target="_self">'.$day.'</a></td>';
        }
    }

if($weekday != 7) $calendar .= '<td class="smalltext" colspan="'.(7-$weekday).'"> </td>'; #remaining "empty" days

echo $calendar.'</tr>';

/////////////////////////////////////////////////////////////////
//   BIRTHDAY SECTION
//
if (!empty($context['calendar_birthdays']))
{
    echo '<tr><td colspan="2"><hr></td><td colspan="3" class="smalltext" align="center" style="font-weight: bold; color: #' . $modSettings['cal_bdaycolor'] . ';">Birthdays</td><td colspan="2"><hr></td></tr><td colspan="7" class="smalltext">';

    foreach ($context['calendar_birthdays'] as $member)
    {
        $query = db_query(
            "SELECT birthdate
            FROM {$db_prefix}members
            WHERE ID_MEMBER='".$member['id']."'", __FILE__, __LINE__);

        $row = mysql_fetch_assoc($query);
        $birthdate = strtotime($row['birthdate']);

        mysql_free_result($query);

        $dummy = array();
        $dummy[] = $member['id'];
        loadMemberData($dummy);
        $profile = &$user_profile[$member['id']];

        echo '<div align="center">';
        echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . date("n",$birthdate) . '"><strong>' . date("M j",$birthdate) . '</strong></a>';
        echo ' - ';
        echo '<a href="', $scripturl, '?action=profile;u=', $member['id'], '">';
        if (!empty($profile['member_group_color']))
        {
        echo '<font color="' . $profile['member_group_color'] . '">' . $member['name'] . (isset($member['age']) ? '(' . $member['age'] . ')' : '') . '</font>';
        }
        else
        {
        echo $member['name'] . (isset($member['age']) ? '(' . $member['age'] . ')' : '');
        }
        echo '</a>';
        echo '</div>';
    }
    echo '</td></tr>';
}

/////////////////////////////////////////////////////////////////
//   EVENTS SECTION
//
if (!empty($context['calendar_events']))
{
    echo '<tr><td colspan="2"><hr></td><td colspan="3" class="smalltext" align="center" style="font-weight: bold; color: #' . $modSettings['cal_eventcolor'] . ';">Events</td><td colspan="2"><hr></td></tr><td colspan="7" class="smalltext">';

    foreach ($context['calendar_events'] as $event)
    {
        $query = db_query(
            "SELECT startDate
            FROM {$db_prefix}calendar
            WHERE ID_EVENT='".$event['id']."'", __FILE__, __LINE__);

        $row = mysql_fetch_assoc($query);
        $startdate = strtotime($row['startDate']);

        mysql_free_result($query);

        echo '<div align="center">';
        echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . date("n",$startdate) . '"><strong>' . date("M j",$startdate) . '</strong></a>';
        echo ' - ';
        echo $event['link'] ;
        echo '</div>';
    }
    echo '</td></tr>';
}

/////////////////////////////////////////////////////////////////
//   HOLIDAY SECTION
//
if (!empty($context['calendar_holidays']))
{
    echo '<tr><td colspan="2"><hr></td><td colspan="3" class="smalltext" align="center" style="font-weight: bold; color: #' . $modSettings['cal_holidaycolor'] . ';">Holidays</td><td colspan="2"><hr></td></tr><td colspan="7" class="smalltext">';

    foreach ($context['calendar_holidays'] as $holiday)
    {
        $query = db_query(
            "SELECT eventDate
            FROM {$db_prefix}calendar_holidays
            WHERE title='".str_replace("'","''",$holiday)."'
            AND (eventDate LIKE '".date("Y")."%' OR eventDate LIKE '0004%')", __FILE__, __LINE__);

        $row = mysql_fetch_assoc($query);
        $eventdate = strtotime($row['eventDate']);

        mysql_free_result($query);

        echo '<div align="center">';
        echo '<a href="', $scripturl, '?action=calendar;year=' . date("Y") . ';month=' . date("n",$eventdate) . '"><strong>' . date("M j",$eventdate) . '</strong></a>';
        echo ' - ';
        echo $holiday;
        echo '</div>';
    }
    echo '</td></tr>';
}

echo '</table>';
Title: Re: timestamp error?
Post by: JPDeni on June 30, 2008, 11:33:14 PM
I see it now. It's in the birthdate section. It's either not picking up the person's birthday or it's not translating that into a timestamp correctly.

If it was me, I'd add some debugging lines. Look for the section marked "Birthday Section". Starts on line 72. Below that, find


        $row = mysql_fetch_assoc($query);


Add


echo '--' . $row['birthdate'] . '--<br>';


You should get a list of upcoming birthdays in the form of

--yyyy-mm-dd--

If that's what you get, delete the line that you entered. Go down one and after the line


        $birthdate = strtotime($row['birthdate']);


add


echo '--' . $birthdate . '--<br>';


You should get a list of numbers with -- on either side.

My guess is that you're going to get

----

somewhere along the line. When you get it will give me an idea of what the problem is.
Title: Re: timestamp error?
Post by: tomtom9800 on July 01, 2008, 12:03:41 AM
OK thanks for the help, I noticed when I did the first code....all the birthdays showed at 1970 or before..... I did the second code and it came like this with two of the users....

---1--

- AB_Moby(39)

--16174800--

Jul 7 - _AH_Rgaa(38)

I hope this helps, if not let me know what else I can do to help
Title: Re: timestamp error?
Post by: JPDeni on July 01, 2008, 01:25:37 AM
Took me a second, but I think I know what's up. It's a good thing that you mentioned

Quoteall the birthdays showed at 1970 or before

This may be the clue.

Try changing


        $birthdate = strtotime($row['birthdate']);


to


        $newdate = date("Y") . substr($row['birthdate'],4)
        $birthdate = strtotime($row['newdate']);


I think that might do it. The problem is that the script is trying to pull the month and day from a date before 1970. This should set the date to this year, with the month and day the same as the original.

In theory. ;)
Title: Re: timestamp error?
Post by: tomtom9800 on July 02, 2008, 04:12:36 AM
Okay I tried those suggested and at first I received a parse error, so I took the first line and added a ; at the end of it.....everything is working, but now the forum error log shows this:

8: strtotime() [<a href='function.strtotime'>function.strtotime</a>]: Called with empty time parameter
File: C:\Inetpub\wwwroot\aceshigh.ws\wwwroot\forum\Themes\default\TPortal.template.php (eval?)
Line: 88

Did I not do something correct?
Title: Re: timestamp error?
Post by: JPDeni on July 02, 2008, 04:55:53 AM
Sorry about the missing ; That happens from time to time.

I'm not sure what's on line 88 any more, with changes that have been made. I don't know why it's doing this.
Title: Re: timestamp error?
Post by: tomtom9800 on July 02, 2008, 02:53:31 PM
Hey thanks for all the help JP,  Maybe one day it will be a self fixer LOL
Title: Re: timestamp error?
Post by: IchBin on July 02, 2008, 03:48:11 PM
Would checking to see if $row['birthdate'] is empty before trying to run strtotime() on it work?
Title: Re: timestamp error?
Post by: JPDeni on July 02, 2008, 07:52:00 PM
The thing is that it shouldn't be empty. As I understand it, prior to this section of code there has been a search for the birthdays. The only ones that should be processed are the ones that we already know have birthdays.
Title: Re: timestamp error?
Post by: IchBin on July 02, 2008, 08:50:14 PM
Doesn't strtotime require a value to calculate against? Looking at the php site,
strtotime (string, int)
Title: Re: timestamp error?
Post by: Ianedres on July 02, 2008, 09:54:05 PM
Per http://www.php.net/manual/en/function.strtotime.php,

Returns a timestamp on success, FALSE otherwise. Previous to PHP 5.1.0, this function would return -1 on failure.

Wouldn't hurt to echo the value out- just to make sure you're getting something.

Title: Re: timestamp error?
Post by: JPDeni on July 03, 2008, 12:57:12 AM
Quote from: IchBinâ,,¢ on July 02, 2008, 08:50:14 PM
Doesn't strtotime require a value to calculate against? Looking at the php site,
strtotime (string, int)

The integer is optional.

Quote
int strtotime ( string $time [, int $now ] )

The function expects to be given a string containing a US English date format and will try to parse that format into a Unix timestamp (the number of seconds since January 1 1970 00:00:00 GMT), relative to the timestamp given in now , or the current time if now is not supplied.

I might be able to work it out if I had what line 88 is, but since I'm not sure after edits and such, I can't tell.
Title: Re: timestamp error?
Post by: tomtom9800 on July 03, 2008, 03:59:16 AM
Jp I would give you admin rights if you would like to take a look or if you would like for me to send you the file I would do it as long as I can trust you lol, jk
Title: Re: timestamp error?
Post by: JPDeni on July 03, 2008, 04:26:07 AM
Hang on a bit. It would be better if I worked on this when I feel better.
Title: Re: timestamp error?
Post by: tomtom9800 on July 04, 2008, 02:34:24 AM
no problem JP, nothing in the emerency catergory lol!  Thanks for all your help btw