PHP  
 PHP: Test and Code Coverage Analysis
downloads | QA | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
 

LCOV - code coverage report
Current view: top level - ext/standard - datetime.c (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 16 28 57.1 %
Date: 2014-12-13 Functions: 1 2 50.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :    +----------------------------------------------------------------------+
       3             :    | PHP Version 7                                                        |
       4             :    +----------------------------------------------------------------------+
       5             :    | Copyright (c) 1997-2014 The PHP Group                                |
       6             :    +----------------------------------------------------------------------+
       7             :    | This source file is subject to version 3.01 of the PHP license,      |
       8             :    | that is bundled with this package in the file LICENSE, and is        |
       9             :    | available through the world-wide-web at the following url:           |
      10             :    | http://www.php.net/license/3_01.txt                                  |
      11             :    | If you did not receive a copy of the PHP license and are unable to   |
      12             :    | obtain it through the world-wide-web, please send a note to          |
      13             :    | license@php.net so we can mail you a copy immediately.               |
      14             :    +----------------------------------------------------------------------+
      15             :    | Authors: Andi Gutmans <andi@zend.com>                                |
      16             :    |          Zeev Suraski <zeev@zend.com>                                |
      17             :    |          Rasmus Lerdorf <rasmus@php.net>                             |
      18             :    +----------------------------------------------------------------------+
      19             :  */
      20             : 
      21             : /* $Id$ */
      22             : 
      23             : #include "php.h"
      24             : #include "zend_operators.h"
      25             : #include "datetime.h"
      26             : #include "php_globals.h"
      27             : 
      28             : #include <time.h>
      29             : #ifdef HAVE_SYS_TIME_H
      30             : # include <sys/time.h>
      31             : #endif
      32             : #include <stdio.h>
      33             : 
      34             : char *mon_full_names[] = {
      35             :         "January", "February", "March", "April",
      36             :         "May", "June", "July", "August",
      37             :         "September", "October", "November", "December"
      38             : };
      39             : 
      40             : char *mon_short_names[] = {
      41             :         "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
      42             : };
      43             : 
      44             : char *day_full_names[] = {
      45             :         "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"
      46             : };
      47             : 
      48             : char *day_short_names[] = {
      49             :         "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
      50             : };
      51             : 
      52             : /* {{{ PHPAPI char *php_std_date(time_t t TSRMLS_DC)
      53             :    Return date string in standard format for http headers */
      54           0 : PHPAPI char *php_std_date(time_t t TSRMLS_DC)
      55             : {
      56             :         struct tm *tm1, tmbuf;
      57             :         char *str;
      58             : 
      59           0 :         tm1 = php_gmtime_r(&t, &tmbuf);
      60           0 :         str = emalloc(81);
      61           0 :         str[0] = '\0';
      62             : 
      63           0 :         if (!tm1) {
      64           0 :                 return str;
      65             :         }
      66             : 
      67           0 :         snprintf(str, 80, "%s, %02d %s %04d %02d:%02d:%02d GMT",
      68           0 :                         day_short_names[tm1->tm_wday],
      69             :                         tm1->tm_mday,
      70           0 :                         mon_short_names[tm1->tm_mon],
      71             :                         tm1->tm_year + 1900,
      72             :                         tm1->tm_hour, tm1->tm_min, tm1->tm_sec);
      73             : 
      74           0 :         str[79] = 0;
      75           0 :         return (str);
      76             : }
      77             : /* }}} */
      78             : 
      79             : #if HAVE_STRPTIME
      80             : #ifndef HAVE_STRPTIME_DECL_FAILS
      81             : char *strptime(const char *s, const char *format, struct tm *tm);
      82             : #endif
      83             : 
      84             : /* {{{ proto string strptime(string timestamp, string format)
      85             :    Parse a time/date generated with strftime() */
      86          10 : PHP_FUNCTION(strptime)
      87             : {
      88             :         char      *ts;
      89             :         size_t        ts_length;
      90             :         char      *format;
      91             :         size_t        format_length;
      92             :         struct tm  parsed_time;
      93             :         char      *unparsed_part;
      94             : 
      95          10 :         if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &ts, &ts_length, &format, &format_length) == FAILURE) {
      96           3 :                 return;
      97             :         }
      98             : 
      99           7 :         memset(&parsed_time, 0, sizeof(parsed_time));
     100             : 
     101           7 :         unparsed_part = strptime(ts, format, &parsed_time);
     102           7 :         if (unparsed_part == NULL) {
     103           0 :                 RETURN_FALSE;
     104             :         }
     105             : 
     106           7 :         array_init(return_value);
     107           7 :         add_assoc_long(return_value, "tm_sec",   parsed_time.tm_sec);
     108           7 :         add_assoc_long(return_value, "tm_min",   parsed_time.tm_min);
     109           7 :         add_assoc_long(return_value, "tm_hour",  parsed_time.tm_hour);
     110           7 :         add_assoc_long(return_value, "tm_mday",  parsed_time.tm_mday);
     111           7 :         add_assoc_long(return_value, "tm_mon",   parsed_time.tm_mon);
     112           7 :         add_assoc_long(return_value, "tm_year",  parsed_time.tm_year);
     113           7 :         add_assoc_long(return_value, "tm_wday",  parsed_time.tm_wday);
     114           7 :         add_assoc_long(return_value, "tm_yday",  parsed_time.tm_yday);
     115           7 :         add_assoc_string(return_value, "unparsed", unparsed_part);
     116             : }
     117             : /* }}} */
     118             : 
     119             : #endif
     120             : 
     121             : /*
     122             :  * Local variables:
     123             :  * tab-width: 4
     124             :  * c-basic-offset: 4
     125             :  * End:
     126             :  * vim600: sw=4 ts=4 fdm=marker
     127             :  * vim<600: sw=4 ts=4
     128             :  */

Generated by: LCOV version 1.10

Generated at Sat, 13 Dec 2014 06:16:23 +0000 (7 days ago)

Copyright © 2005-2014 The PHP Group
All rights reserved.