RE: Function mktime() documentation question

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

 



> -----Original Message-----
> From: Tedd Sperling [mailto:tedd.sperling@xxxxxxxxx]
> Sent: 08 March 2012 23:15
> To: PHP-General List

[previous discussion snipped]
 
 
> Mike:
> 
> Very well put.
> 
> You say:
> 
> > Huh? The 0th day of next month *is* the last day of the current
> month,
> > which gives you the number of days in the current month.
> 
> That IS exactly what I am saying.
> 
> But why does anyone have to use the next month to figure out how
> many days there are are in this month? Do you see my point?

Actually, no. To figure this out, somewhere along the line you've
got to know where the last day of this month / first day of next
month boundary lies, so I don't see how you can ever find the number
of days in a month without bringing the start of next month into it
somehow. (Even if it's implicitly be getting someone else's clever
code to figure out 'last day of this month'!)
 
> It would have been better if one could use:
> 
> $what_date = getdate(mktime(0, 0, 0, $this_month, 0, $year));
> $days_in_this_month = $what_date['nday']; // note an additional key
> for getdate()

But that $what_date would still refer to a day in *last* month!
(Which isn't going to change, as it would be a significant BC break.)

> But instead, we have to use:
> 
> $next_month = $this_month +1;
> $what_date = getdate(mktime(0, 0, 0, $next_month, 0, $year));
> $days_in_this_month = $what_date['mday'];

To me, that's a clever and elegant solution. It's clear that our
brains just work differently on this one.

> Additionally, there's a perception problem. You say that 0 of the
> next month *is* the last day of the current month -- as such,
> apparently months overlap in your (and Dan's) explanation. Well... I
> agree with both of you, but my objection is having to increase the
> month value by one to get the number of days in the current month.

Not overlap as such, I don't think -- there's just a continuum such
that the 0th of a month is the day before the 1st (and hence the last
day of the preceding month!), the -1th is the day before that and so
on; likewise, the 32nd is the day after the 31st, and so on.

> Side-point: I find it interesting that getdate() has all sorts of
> neat descriptions for the current month (such as, what weekday a
> numbered day is), but lacks how many days are in the month. Doesn't
> that seem odd?

Now that's a decent point: I can see where you're coming from with that
one. I don't know what performance penalty there might be (if any) to
calculate that for every call to getdate(), but it certainly seems like
a reasonable feature request.

(And, actually, I think we should be quite grateful that mktime()
*does* take out-of-range values and do appropriate things with them --
if it didn't, I suspect the only way to do this job might be a loop
similar to the one posted by Tedd, but adding chunks of 86400 to a raw
timestamp. Now that really would be a bit obscure!!!)

Cheers!

Mike

-- 
Mike Ford,
Electronic Information Developer, Libraries and Learning Innovation,  
Portland PD507, City Campus, Leeds Metropolitan University,
Portland Way, LEEDS,  LS1 3HE,  United Kingdom 
E: m.ford@xxxxxxxxxxxxxx     T: +44 113 812 4730





To view the terms under which this email is distributed, please go to http://disclaimer.leedsmet.ac.uk/email.htm

-- 
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