php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #67204 In midnight,date("h") return 12,is it correct?
Submitted: 2014-05-05 03:36 UTC Modified: 2014-05-05 03:38 UTC
From: zws at ahtvu dot ah dot cn Assigned:
Status: Not a bug Package: Date/time related
PHP Version: Irrelevant OS: Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: zws at ahtvu dot ah dot cn
New email:
PHP Version: OS:

 

 [2014-05-05 03:36 UTC] zws at ahtvu dot ah dot cn
Description:
------------
When I browse cacti.log, I find some date information are strange. I list them bellow.

05/04/2014 11:55:17 PM - SPINE: Poller[0] Host[25] TH[1] DS[525] WARNING: SNMP timeout detected [2000 ms], ignoring host '10.1.10.12'
05/04/2014 11:55:25 PM - SPINE: Poller[0] Host[25] TH[1] DS[525] WARNING: SNMP timeout detected [2000 ms], ignoring host '10.1.10.12'
05/04/2014 11:56:28 PM - SYSTEM STATS: Time:86.5674 Method:spine Processes:1 Threads:1 Hosts:84 HostsPerProcess:84 DataSources:4237 RRDsProcessed:1129
05/04/2014 11:56:28 PM - SYSTEM THOLD STATS: Time:0.0173 Tholds:1 DownHosts:0
05/04/2014 11:56:28 PM - WEATHERMAP: Poller[0] Weathermap 0.97c starting - Normal logging mode. Turn on DEBUG in Cacti for more information

05/04/2014 11:56:28 PM - WEATHERMAP: Poller[0] STATS: Weathermap 0.97c run complete - Sun, 04 May 14 23:56:28 +0800: 0 maps were run in 0 seconds with 0 warnings.
05/05/2014 12:01:18 AM - SYSTEM STATS: Time:77.6253 Method:spine Processes:1 Threads:1 Hosts:84 HostsPerProcess:84 DataSources:4237 RRDsProcessed:1124
05/05/2014 12:01:18 AM - SYSTEM THOLD STATS: Time:0.0188 Tholds:1 DownHosts:0
05/05/2014 12:01:18 AM - WEATHERMAP: Poller[0] Weathermap 0.97c starting - Normal logging mode. Turn on DEBUG in Cacti for more information

05/05/2014 12:01:18 AM - WEATHERMAP: Poller[0] STATS: Weathermap 0.97c run complete - Mon, 05 May 14 00:01:18 +0800: 0 maps were run in 0 seconds with 0 warnings.
05/05/2014 12:05:17 AM - SPINE: Poller[0] Host[25] Hostname[10.1.10.12] ERROR: HOST EVENT: Host is DOWN Message: Host did not respond to SNMP
05/05/2014 12:06:19 AM - SYSTEM STATS: Time:78.5439 Method:spine Processes:1 Threads:1 Hosts:84 HostsPerProcess:84 DataSources:4237 RRDsProcessed:1124
05/05/2014 12:06:19 AM - SYSTEM THOLD STATS: Time:0.0186 Tholds:1 DownHosts:0
05/05/2014 12:06:19 AM - WEATHERMAP: Poller[0] Weathermap 0.97c starting - Normal logging mode. Turn on DEBUG in Cacti for more information

.....................#ommit

05/05/2014 12:51:28 AM - WEATHERMAP: Poller[0] STATS: Weathermap 0.97c run complete - Mon, 05 May 14 00:51:28 +0800: 0 maps were run in 0 seconds with 0 warnings.
05/05/2014 12:56:19 AM - SYSTEM STATS: Time:78.3940 Method:spine Processes:1 Threads:1 Hosts:84 HostsPerProcess:84 DataSources:4237 RRDsProcessed:1124
05/05/2014 12:56:19 AM - SYSTEM THOLD STATS: Time:0.0189 Tholds:1 DownHosts:0
05/05/2014 12:56:19 AM - WEATHERMAP: Poller[0] Weathermap 0.97c starting - Normal logging mode. Turn on DEBUG in Cacti for more information

05/05/2014 12:56:19 AM - WEATHERMAP: Poller[0] STATS: Weathermap 0.97c run complete - Mon, 05 May 14 00:56:19 +0800: 0 maps were run in 0 seconds with 0 warnings.
05/05/2014 01:00:19 AM - SPINE: Poller[0] Host[25] TH[1] DS[252] WARNING: SNMP timeout detected [2000 ms], ignoring host '10.1.10.12'
05/05/2014 01:00:19 AM - SPINE: Poller[0] Host[25] TH[1] DS[252] WARNING: SNMP timeout detected [2000 ms], ignoring host '10.1.10.12'
05/05/2014 01:00:19 AM - SPINE: Poller[0] Host[25] TH[1] DS[519] WARNING: SNMP timeout detected [2000 ms], ignoring host '10.1.10.12'
05/05/2014 01:00:19 AM - SPINE: Poller[0] Host[25] TH[1] DS[519] WARNING: SNMP timeout detected [2000 ms], ignoring host '10.1.10.12'

The date column is 
05/04/2014 11:56:28 PM
...
05/05/2014 12:01:18 AM
....
05/05/2014 01:00:19 AM

It should be wrong,so I do some test to confirm it.

[root@CactiEZ ~]# uname -a
Linux CactiEZ.local 2.6.32-71.el6.i686 #1 SMP Fri Nov 12 04:17:17 GMT 2010 i686 i686 i386 GNU/Linux
[root@CactiEZ ~]# php -v
PHP 5.3.2 (cli) (built: Nov 12 2010 08:16:13) 
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
[root@CactiEZ ~]# date -s 00:01:01 
Mon May  5 00:01:01 CST 2014
[root@CactiEZ ~]# php -r 'echo date("h");'
12[root@CactiEZ ~]# 

related information in php.ini
[Date]
date.timezone = PRC

I follow the source file, and find related code line in function date_format (ext/date/php_date.c)

static char *date_format(char *format, int format_len, timelib_time *t, int localtime)
{
...
			case 'h': length = slprintf(buffer, 32, "%02d", (t->h % 12) ? (int) t->h % 12 : 12); break;
...
}

I think this code line shoud be

case 'h': length = slprintf(buffer, 32, "%02d", t->h % 12); break;


Test script:
---------------
php -r 'echo date("h");'

Expected result:
----------------
I think the result should be 00.



Actual result:
--------------
The actual result is 12.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-05-05 03:38 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2014-05-05 03:38 UTC] requinix@php.net
> In midnight,date("h") return 12,is it correct?
Yes. There is no hour 0 on the 12-hour clock.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 09 23:01:33 2025 UTC