Re: detecting leap years?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> On Jan 19, 2018, at 5:42 PM, Jeffry Killen <jekillen@xxxxxxxxxxx> wrote:
> 
> 
>> On Jan 19, 2018, at 5:36 PM, Aziz Saleh <azizsaleh@xxxxxxxxx> wrote:
>> 
>> function is_leap_year($year) {
>> 
>> 	
>> return ((($year % 4) == 0) && ((($year % 100) != 0) || (($year % 400) == 0)));
>> }
> 
> Thank you;
> Jeff k
> 

Thank you Richard for

Or the "L" parameter:

 L  Whether it's a leap year -- 1 if it is a leap year, 0 otherwise.

on the date() function:

This is helpful to know in the future. Meanwhile,

I modified the original code in reply to the following to work in my situation

1: I couldn't seem to get a decisive response from code as posted in reply

were 2018 is from getDate return array
print is_leap_year(2018) // ... nothing, no false, -1, 0 or anything. also no complaints

2: I have had problems with using % alone in php, and reading the manual
    it didn't actually do what it does in javascript: 2.5%1 = .5, so I used fmod
   I wrote a bunch if code in javascript and did an almost verbatim translation
   to php. But every where I used % in the javascript code, I had to use fmod
   in php to get the same result.

3: If the $year value comes in as a string so I didn't want to trust that it would
    be coerced to number type.

4: The return doesn't have to be a string, it is a left over from processing
    string representation of boolean value, as would be sent in a $_GET var.

function getLeap($year)
             {
              settype($year, 'int');
	      if( ( fmod($year, 4) == 0 ) &&  ( ( fmod($year, 100) != 0 ) ||  (fmod($year, 400) == 0) ) )
	        {
	         return 'true';
	         }
	      else
                 {
	           return 'false';
	         }
            }

I hope this considered something of value to list in general. It is not intended as a criticism
of the code offered. I was probably missing some key understanding.

Jeff K



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php





[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux