SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict
    Join Date
    Mar 2005
    Posts
    319
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Start of date month offset

    The below code should highlight and space a calendar properly, but I'm having some issues.

    http://forums.wuggawoo.co.uk/calendar (scroll and select feb 2008) and you'll notice the 'clear' is given too early.

    This happens on quite a few months and I wondered if anyone can spot why by looking at my code.

    Code PHP:
    	public static function GetDateRange($month, $year) {
     
    		$range 		= array();	
    		$date 		= mktime(12, 0, 0, $month, 1, $year);
     
    		$firstDay 	= date('w', $date);
    		$lastDay 	= date('t', $date);
     
    		$start = strtotime("$year-$month-1");
    		$end = strtotime("$year-$month-$lastDay");
     
    		$previousDate 		= strtotime('-1 month', $start);
    		$previousLastDay	= date('t', $previousDate);
     
    	  	while($lastDay <= $previousLastDay) {
    			$range[] =  mktime(12, 0, 0, date('m', strtotime('-1 month', $start)), $lastDay, date('Y', strtotime('-1 month', $start)));
    			$lastDay++;
    	 	 }
     
    			while($start <= $end) {
    				$range[] = Time::Datetime_To_Timestamp(date('Y-m-d', $start)." 0:0:0");
     
    				if(date('D', $start) == 'Sat') {
    					$range[] = 'clear';
    				}
     
    				$start = strtotime('+1 day', $start);
    			}
    		return $range;
    	}

    Help greatly appreciated.

  2. #2
    SitePoint Wizard Young Twig's Avatar
    Join Date
    Dec 2003
    Location
    Albany, New York
    Posts
    1,355
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The clears are going in the right spots. It's the beginning that you've got screwed up.

    Try this:
    PHP Code:
    public static function GetDateRange($month$year) {
     
            
    $range   = array();   
            
    $date     mktime(1200$month1$year);
     
            
    $firstDay   date('w'$date);
            
    $lastDay    date('t'$date);
     
            
    $start strtotime("$year-$month-1 -$firstDay days");
            
    $end strtotime("$year-$month-$lastDay"); 
     
                while(
    $start <= $end) {
                    
    $range[] = Time::Datetime_To_Timestamp(date('Y-m-d'$start)." 0:0:0");
                   
                    if(
    date('D'$start) == 'Sat') {
                        
    $range[] = 'clear';
                    }
     
                    
    $start strtotime('+1 day'$start);
                }
            return 
    $range;
        } 

  3. #3
    SitePoint Addict
    Join Date
    Mar 2005
    Posts
    319
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Genius, thank you for the help


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •