1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Fixed Birthday greater than today's date

Discussion in 'Resolved Bug Reports' started by Sasa, Sep 18, 2012.

  1. Sasa

    Sasa Active Member

    I do not know whether it is a bug or not, but forum does not check the entered date of birth, so it happens that is birthday greater than today's date.
    slide.jpg
     
    0xym0r0n, Jake Bunce and Adam Howard like this.
  2. Chris D

    Chris D XenForo Developer Staff Member

    I'd call that a bug. Good find (y)
     
  3. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    Confirmed. Currently the datawriter only checks the year boundary.

    Code fix:

    library/XenForo/DataWriter/User.php

    Add the red code:

    Code:
    	public function checkDob()
    	{
    		if ($this->isChanged('dob_day') || $this->isChanged('dob_month') || $this->isChanged('dob_year'))
    		{
    			if (!$this->get('dob_day') || !$this->get('dob_month'))
    			{
    				$this->set('dob_day', 0);
    				$this->set('dob_month', 0);
    				$this->set('dob_year', 0);
    			}
    			else
    			{
    				$year = $this->get('dob_year');
    				if (!$year)
    				{
    					$year = 2008; // pick a leap year to be sure
    				}
    				else if ($year < 100)
    				{
    					$year += ($year < 20 ? 2000 : 1900);
    					$this->set('dob_year', $year);
    				}
    
    				if ($year > intval(date('Y')) || $year < 1900 || !checkdate($this->get('dob_month'), $this->get('dob_day'), $year)
    					// exactly check the current year
    					|| (
    						$year == intval(date('Y'))
    						&& (
    							$this->get('dob_month') > intval(date('n'))
    							|| (
    								$this->get('dob_month') == intval(date('n')) && $this->get('dob_day') > intval(date('j'))
    							)
    						)
    					)
    				)
    				{
    					if ($this->_importMode)
    					{
    						// don't error, wipe it out
    						$this->set('dob_day', 0);
    						$this->set('dob_month', 0);
    						$this->set('dob_year', 0);
    					}
    					else
    					{
    						$this->error(new XenForo_Phrase('please_enter_valid_date_of_birth'), 'dob');
    					}
    
    					return false;
    				}
    			}
    		}
    
    		return true;
    	}
    
    That makes it so the birthday can at most be the current day. That prevents an age of -1. In the case of age 0 (less than 1 year old) it simply won't show any age because that makes the age false with the current template code. If the devs feel so inclined they may wish to implement a month age for babies.
     
  4. Mike

    Mike XenForo Developer Staff Member

    Fixed. :)

    I haven't bothered with month ages or anything though.
     
    Slavik and TBolley like this.

Share This Page