php-general Digest 7 Mar 2012 21:29:07 -0000 Issue 7716
php-general Digest 7 Mar 2012 21:29:07 - Issue 7716 Topics (messages 316932 through 316934): Function mktime() documentation question 316932 by: Tedd Sperling 316933 by: admin 316934 by: Daniel Brown Administrivia: To subscribe to the digest, e-mail: php-general-digest-subscr...@lists.php.net To unsubscribe from the digest, e-mail: php-general-digest-unsubscr...@lists.php.net To post to the list, e-mail: php-gene...@lists.php.net -- ---BeginMessage--- Hi gang: I am using the getdate(mktime()) functions to get month data (i.e., name of month, first weekday, last day, number of days). To get the number of days for a specific month, I use: // $current_month is the month under question $next_month = $current_month + 1; $what_date = getdate(mktime(0, 0, 0, $next_month, 0, $year)); $days_in_current_month = $what_date['mday']; That works for me! However, if you read the documentation, namely: http://php.net/manual/en/function.mktime.php It states: --- quote day The number of the day relative to the end of the previous month. Values 1 to 28, 29, 30 or 31 (depending upon the month) reference the normal days in the relevant month. Values less than 1 (including negative values) reference the days in the previous month, so 0 is the last day of the previous month, -1 is the day before that, etc. Values greater than the number of days in the relevant month reference the appropriate day in the following month(s). --- un-quote From my code, the number of days in a month can be found by using 0 as the first index of the next month -- not the last day of the previous month. As such, I would re-write the relevant portion of the paragraph to be: day The number of the day relative to the end of the previous month. Values 1 to 28, 29, 30 or 31 (depending upon the month) reference the normal days in the relevant month. Values less than 0 reference the days in the previous month. For example, -1 is the day before the first day of the relevant month. The value 0 is the zero index of the next month, which is also equal to the last day of the relevant month. Values greater than zero are the number of days in the relevant month reference the appropriate day in the following month(s). What say you? Cheers, tedd _ tedd.sperl...@gmail.com http://sperling.com ---End Message--- ---BeginMessage--- Tedd, This area was always a little grey to me. I have used -1 to obtain the previous months for some time now. 0 always indicated the beginning index of the current month but the explanation never seemed to fit the bill. Having worked extensively in time manipulation in many of the development projects I have come up with a rule of thumb. $this_month = date('Y-m-d 00:00:00',mktime(0,0,0,date('m'),1,date('Y'))); $previous_month = date('Y-m-d 00:00:00',mktime(0,0,0,date('m')-1,1,date('Y'))); $next_month = date('Y-m-d 00:00:00',mktime(0,0,0,date('m')+1,1,date('Y'))); To get the days of any given month or just about anything you need to just use the strtotime $days_in_month = date('j',strtotime($this_month)); -Original Message- From: Tedd Sperling [mailto:tedd.sperl...@gmail.com] Sent: Wednesday, March 07, 2012 3:04 PM To: PHP-General List Subject: [PHP] Function mktime() documentation question Hi gang: I am using the getdate(mktime()) functions to get month data (i.e., name of month, first weekday, last day, number of days). To get the number of days for a specific month, I use: // $current_month is the month under question $next_month = $current_month + 1; $what_date = getdate(mktime(0, 0, 0, $next_month, 0, $year)); $days_in_current_month = $what_date['mday']; That works for me! However, if you read the documentation, namely: http://php.net/manual/en/function.mktime.php It states: --- quote day The number of the day relative to the end of the previous month. Values 1 to 28, 29, 30 or 31 (depending upon the month) reference the normal days in the relevant month. Values less than 1 (including negative values) reference the days in the previous month, so 0 is the last day of the previous month, -1 is the day before that, etc. Values greater than the number of days in the relevant month reference the appropriate day in the following month(s). --- un-quote From my code, the number of days in a month can be found by using 0 as the first index of the next month -- not the last day of the previous month. As such, I would re-write the relevant portion of the paragraph to be: day The number of the day relative to the end of the previous month. Values 1 to 28, 29, 30 or 31 (depending upon the month) reference the normal days in the relevant month. Values less than 0 reference the days in the previous month. For example, -1 is the day before the first day of the relevant month. The value 0 is the zero index of the
[PHP] cURL and SSL
Hi, I want to change a SOAP call to curl due to ssl timeout bug of PHP Soap. My PHP version is PHP 5.2.6-1+lenny13 with Suhosin-Patch 0.9.6.2. I'm using the following SOAP call and it's handling SSL very good: $client = new SoapClient('https://92.42.55.82:8442', array('trace' = True, 'local_cert' = 'BehnamCa/newkey.pem')); But when i want to use cURL and overwrite the __doRequest function using the following code: $curl = curl_init($location); curl_setopt($curl, CURLOPT_VERBOSE, TRUE); curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($curl, CURLOPT_POST, TRUE); curl_setopt($curl, CURLOPT_POSTFIELDS, $request); curl_setopt($curl, CURLOPT_HEADER, FALSE); curl_setopt($curl, CURLOPT_HTTPHEADER, array(Content-Type: text/xml)); curl_setopt($curl, CURLOPT_TIMEOUT, $this-timeout); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 1); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 1); curl_setopt($curl, CURLOPT_CAPATH, '/home/sasan/CA2/BehnamCa/'); curl_setopt($curl, CURLOPT_SSLCERT, '/home/sasan/CA2/BehnamCa/newkey.pem'); curl_setopt($curl, CURLOPT_SSLCERTTYPE, 'PEM'); curl_setopt($curl, CURLOPT_SSLKEY, '/home/sasan/CA2/BehnamCa/private.key'); curl_setopt($curl, CURLOPT_CAINFO, '/home/sasan/CA2/BehnamCa/private.crt'); $response = curl_exec($curl); I'm receiving the following: * About to connect() to 92.X.X.X port 8443 (#0) * Trying 92.X.X.X... * connected * Connected to 92.X.X.X (92.X.X.X) port 8443 (#0) * successfully set certificate verify locations: * CAfile: /home/sasan/CA2/BehnamCa/private.crt CApath: /home/sasan/CA2/BehnamCa/ * SSL certificate problem, verify that the CA cert is OK. Details: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed * Closing connection #0 string(146) SSL certificate problem, verify that the CA cert is OK. Details: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed As you can see, i'm trying every possible way to tell curl about my keys, but still no success. Am i doing something wrong or this is a bug? -- Best Regards Sasan Rose signature.asc Description: OpenPGP digital signature
[PHP] Function mktime() documentation question
Hi gang: I am using the getdate(mktime()) functions to get month data (i.e., name of month, first weekday, last day, number of days). To get the number of days for a specific month, I use: // $current_month is the month under question $next_month = $current_month + 1; $what_date = getdate(mktime(0, 0, 0, $next_month, 0, $year)); $days_in_current_month = $what_date['mday']; That works for me! However, if you read the documentation, namely: http://php.net/manual/en/function.mktime.php It states: --- quote day The number of the day relative to the end of the previous month. Values 1 to 28, 29, 30 or 31 (depending upon the month) reference the normal days in the relevant month. Values less than 1 (including negative values) reference the days in the previous month, so 0 is the last day of the previous month, -1 is the day before that, etc. Values greater than the number of days in the relevant month reference the appropriate day in the following month(s). --- un-quote From my code, the number of days in a month can be found by using 0 as the first index of the next month -- not the last day of the previous month. As such, I would re-write the relevant portion of the paragraph to be: day The number of the day relative to the end of the previous month. Values 1 to 28, 29, 30 or 31 (depending upon the month) reference the normal days in the relevant month. Values less than 0 reference the days in the previous month. For example, -1 is the day before the first day of the relevant month. The value 0 is the zero index of the next month, which is also equal to the last day of the relevant month. Values greater than zero are the number of days in the relevant month reference the appropriate day in the following month(s). What say you? Cheers, tedd _ tedd.sperl...@gmail.com http://sperling.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Function mktime() documentation question
Tedd, This area was always a little grey to me. I have used -1 to obtain the previous months for some time now. 0 always indicated the beginning index of the current month but the explanation never seemed to fit the bill. Having worked extensively in time manipulation in many of the development projects I have come up with a rule of thumb. $this_month = date('Y-m-d 00:00:00',mktime(0,0,0,date('m'),1,date('Y'))); $previous_month = date('Y-m-d 00:00:00',mktime(0,0,0,date('m')-1,1,date('Y'))); $next_month = date('Y-m-d 00:00:00',mktime(0,0,0,date('m')+1,1,date('Y'))); To get the days of any given month or just about anything you need to just use the strtotime $days_in_month = date('j',strtotime($this_month)); -Original Message- From: Tedd Sperling [mailto:tedd.sperl...@gmail.com] Sent: Wednesday, March 07, 2012 3:04 PM To: PHP-General List Subject: [PHP] Function mktime() documentation question Hi gang: I am using the getdate(mktime()) functions to get month data (i.e., name of month, first weekday, last day, number of days). To get the number of days for a specific month, I use: // $current_month is the month under question $next_month = $current_month + 1; $what_date = getdate(mktime(0, 0, 0, $next_month, 0, $year)); $days_in_current_month = $what_date['mday']; That works for me! However, if you read the documentation, namely: http://php.net/manual/en/function.mktime.php It states: --- quote day The number of the day relative to the end of the previous month. Values 1 to 28, 29, 30 or 31 (depending upon the month) reference the normal days in the relevant month. Values less than 1 (including negative values) reference the days in the previous month, so 0 is the last day of the previous month, -1 is the day before that, etc. Values greater than the number of days in the relevant month reference the appropriate day in the following month(s). --- un-quote From my code, the number of days in a month can be found by using 0 as the first index of the next month -- not the last day of the previous month. As such, I would re-write the relevant portion of the paragraph to be: day The number of the day relative to the end of the previous month. Values 1 to 28, 29, 30 or 31 (depending upon the month) reference the normal days in the relevant month. Values less than 0 reference the days in the previous month. For example, -1 is the day before the first day of the relevant month. The value 0 is the zero index of the next month, which is also equal to the last day of the relevant month. Values greater than zero are the number of days in the relevant month reference the appropriate day in the following month(s). What say you? Cheers, tedd _ tedd.sperl...@gmail.com http://sperling.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Function mktime() documentation question
On Wed, Mar 7, 2012 at 15:03, Tedd Sperling tedd.sperl...@gmail.com wrote: Hi gang: I am using the getdate(mktime()) functions to get month data (i.e., name of month, first weekday, last day, number of days). To get the number of days for a specific month, I use: // $current_month is the month under question $next_month = $current_month + 1; $what_date = getdate(mktime(0, 0, 0, $next_month, 0, $year)); $days_in_current_month = $what_date['mday']; That works for me! However, if you read the documentation, namely: http://php.net/manual/en/function.mktime.php It states: --- quote day The number of the day relative to the end of the previous month. Values 1 to 28, 29, 30 or 31 (depending upon the month) reference the normal days in the relevant month. Values less than 1 (including negative values) reference the days in the previous month, so 0 is the last day of the previous month, -1 is the day before that, etc. Values greater than the number of days in the relevant month reference the appropriate day in the following month(s). --- un-quote From my code, the number of days in a month can be found by using 0 as the first index of the next month -- not the last day of the previous month. I fail to follow. Your code is looking ahead to next month (April), then using the 0 day, which means it's getting the last day (31) of the current month (March). There's no such thing as a 0 April, hence anything less than one should count backward. -- /Daniel P. Brown Network Infrastructure Manager http://www.php.net/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Function mktime() documentation question
To get the number of days for a specific month, I use: // $current_month is the month under question $next_month = $current_month + 1; I use this $next_month = $current_month + 1; $next_month_1= mktime(0, 0, 0, $next_month, 1, date(Y) ); $current_month_1= mktime(0, 0, 0, $current_month, 1, date(Y) ); $mdays = ($current_month_1 - $next_month_1)/(3600*24); It's much more easier if you use DateTime and DateInterval class -- Shiplu.Mokadd.im ImgSign.com | A dynamic signature machine Innovation distinguishes between follower and leader
Re: [PHP] Function mktime() documentation question
Hi, All To bring a work-around into this discussion I myself would not see it as a good way to do it like that - even if the documentation provides some information around that. Here's what I have done in all new projects I worked with time-calculation: @Tedd: Lets pick up your first example and work with the DateTime-Object instead: $date = new DateTime($year . '-' . $current_month . '-1'); $date-add( new DateInterval( 'P1M' ) ); // Add a period of 1 month to the date-instance (haven't tried that with the 30th of Jan ... would be kind-of interesting) $days_in_current_month = $date-format('j'); // Get the date of the month As this does not solve the problem (as we still should update the documentation or the code if it does not match) it's not a solution, but a suggestion to coding-style at all. It seems a bit cleaner to me as you don't have to worry about the 13th month, time-zones or other things that can be difficult to calculate yourself. Bye Simon 2012/3/8 shiplu shiplu@gmail.com: To get the number of days for a specific month, I use: // $current_month is the month under question $next_month = $current_month + 1; I use this $next_month = $current_month + 1; $next_month_1 = mktime(0, 0, 0, $next_month, 1, date(Y) ); $current_month_1= mktime(0, 0, 0, $current_month, 1, date(Y) ); $mdays = ($current_month_1 - $next_month_1)/(3600*24); It's much more easier if you use DateTime and DateInterval class -- Shiplu.Mokadd.im ImgSign.com | A dynamic signature machine Innovation distinguishes between follower and leader -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Function mktime() documentation question
On Thu, Mar 8, 2012 at 7:01 AM, Simon Schick simonsimc...@googlemail.com wrote: $date = new DateTime($year . '-' . $current_month . '-1'); $date-add( new DateInterval( 'P1M' ) ); // Add a period of 1 month to the date-instance (haven't tried that with the 30th of Jan ... would be kind-of interesting) $days_in_current_month = $date-format('j'); // Get the date of the month I think you'd need to subtract it with 1 day date_create(date('Y-m'))-add(new DateInterval('P1M'))-sub(new DateInterval('P1D'))-format('d'); -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php