|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #80145 date_sunrise / date_sunset skip a day in specific case
Submitted: 2020-09-24 11:47 UTC Modified: 2022-05-13 15:53 UTC
From: craigpvmts at gmail dot com Assigned:
Status: Wont fix Package: Date/time related
PHP Version: 7.4.10 OS: Raspian 10 (Buster - Debian)
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: craigpvmts at gmail dot com
New email:
PHP Version: OS:


 [2020-09-24 11:47 UTC] craigpvmts at gmail dot com
Hi all,

I wrote some php code that operates & logs data on a solar PV system. It makes use of date_sunrise / date_sunset methods to determine approximately when the system should be active. The system failed to start today because the next sunrise time was off by 24h. After evaluating the code and writing a short script, confirmed that the date_sunrise / date_sunset functions appear to skip a day at midnight Sept 23-24, 2020 - at least when given lat/long coordinates in New Zealand when the local machine is set to NZST (UTC+12). When given a time after Sept 24th, the returned sunrise/sunset times will be 1 day in the future.

Attaching sample code to reproduce the issue.

Thanks for any update.

Test script:

$today=1600776000;	// 2020-09-23 00:00:00 NZST (= 2020-09-22 12:00:00 UTC)
while ($i<=72)
	print($today." ".date('Y-m-d H:i:s',$today)." Rise:".
	date_sunrise($today,SUNFUNCS_RET_TIMESTAMP,-38.6623,178.0176)." Set:".

Expected result:
Test code should generate a list of 72 entries by hour. Every 24 entries the Rise/Set values for sunrise/sunset should increment by roughly 86400 (1 day in seconds).  I'm not actually clear on exactly when this method is expected to increment the date - it appears to depend on the current timezone setting (or perhaps solar midnight at the lat/long?). Regardless, at local (NZST) midnight on Sept 23/24 the returned values increment by 2 days. Here is a sample line from the output on Sept 23 when run in New Zealand Standard Time that works as expected:

1600819200 2020-09-23 12:00:00 Rise:1600797323 Set:1600841112

Actual result:
Here is a portion of the result for 4 key points in time when run on a Raspberry Pi set to New Zealand Standard Time:

1600819200 2020-09-23 12:00:00 Rise:1600797323 Set:1600841112
1600858800 2020-09-23 23:00:00 Rise:1600797323 Set:1600841112
1600862400 2020-09-24 00:00:00 Rise:1600970027 Set:1601013966
1600905600 2020-09-24 12:00:00 Rise:1600970027 Set:1601013966

Lines 1 and 2 are correct / expected, lines 3 and 4 are incorrect - Rise and Set values should be about 86400 (1 day) lower. 


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2020-09-24 14:34 UTC]
-Status: Open +Status: Verified
 [2020-09-24 14:34 UTC]
Simpler reproducer: <>.

This is almost certainly a timelib[1] issue, and might have been
introduced with commit 8d0066f66[2].

[1] <>
[2] <>
 [2022-05-13 15:53 UTC]
-Status: Verified +Status: Wont fix
 [2022-05-13 15:53 UTC]
The date_sunrise function got deprecated with PHP 8.1. If this still happens with the replacement sun_info() function, please file a new ticket at
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Thu Jun 30 23:03:49 2022 UTC