Coverage Report

Created: 2025-06-13 06:43

/src/php-src/ext/standard/datetime.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
   +----------------------------------------------------------------------+
3
   | Copyright (c) The PHP Group                                          |
4
   +----------------------------------------------------------------------+
5
   | This source file is subject to version 3.01 of the PHP license,      |
6
   | that is bundled with this package in the file LICENSE, and is        |
7
   | available through the world-wide-web at the following url:           |
8
   | https://www.php.net/license/3_01.txt                                 |
9
   | If you did not receive a copy of the PHP license and are unable to   |
10
   | obtain it through the world-wide-web, please send a note to          |
11
   | license@php.net so we can mail you a copy immediately.               |
12
   +----------------------------------------------------------------------+
13
   | Authors: Andi Gutmans <andi@php.net>                                 |
14
   |          Zeev Suraski <zeev@php.net>                                 |
15
   |          Rasmus Lerdorf <rasmus@php.net>                             |
16
   +----------------------------------------------------------------------+
17
 */
18
19
#include "php.h"
20
#include "php_globals.h"
21
22
#include <time.h>
23
#ifdef HAVE_SYS_TIME_H
24
# include <sys/time.h>
25
#endif
26
27
#ifdef HAVE_STRPTIME
28
#ifndef HAVE_DECL_STRPTIME
29
char *strptime(const char *s, const char *format, struct tm *tm);
30
#endif
31
32
/* {{{ Parse a time/date generated with strftime() */
33
PHP_FUNCTION(strptime)
34
0
{
35
0
  char      *ts;
36
0
  size_t        ts_length;
37
0
  char      *format;
38
0
  size_t        format_length;
39
0
  struct tm  parsed_time;
40
0
  char      *unparsed_part;
41
42
0
  ZEND_PARSE_PARAMETERS_START(2, 2)
43
0
    Z_PARAM_STRING(ts, ts_length)
44
0
    Z_PARAM_STRING(format, format_length)
45
0
  ZEND_PARSE_PARAMETERS_END();
46
47
0
  memset(&parsed_time, 0, sizeof(parsed_time));
48
49
0
  unparsed_part = strptime(ts, format, &parsed_time);
50
0
  if (unparsed_part == NULL) {
51
0
    RETURN_FALSE;
52
0
  }
53
54
0
  array_init(return_value);
55
0
  add_assoc_long(return_value, "tm_sec",   parsed_time.tm_sec);
56
0
  add_assoc_long(return_value, "tm_min",   parsed_time.tm_min);
57
0
  add_assoc_long(return_value, "tm_hour",  parsed_time.tm_hour);
58
0
  add_assoc_long(return_value, "tm_mday",  parsed_time.tm_mday);
59
0
  add_assoc_long(return_value, "tm_mon",   parsed_time.tm_mon);
60
0
  add_assoc_long(return_value, "tm_year",  parsed_time.tm_year);
61
0
  add_assoc_long(return_value, "tm_wday",  parsed_time.tm_wday);
62
0
  add_assoc_long(return_value, "tm_yday",  parsed_time.tm_yday);
63
0
  add_assoc_string(return_value, "unparsed", unparsed_part);
64
0
}
65
/* }}} */
66
67
#endif