stleary / stars-at-night

WordPress plug-in that provides astronomical information based on location and date
MIT License
6 stars 4 forks source link

Heavens-Above Timezone support broken...? #35

Open PatchworkBoy opened 5 years ago

PatchworkBoy commented 5 years ago

Timezone support appears to be broken in current version as the timezone isn’t passed to Heavens-Above. See...

https://github.com/stleary/stars-at-night/blob/750a4de1aabc0cb6a5bceb30ca362ad93169adc4/src/class-planet-passes.php#L66

https://github.com/stleary/stars-at-night/blob/750a4de1aabc0cb6a5bceb30ca362ad93169adc4/src/class-satellite-passes.php#L67

https://github.com/stleary/stars-at-night/blob/750a4de1aabc0cb6a5bceb30ca362ad93169adc4/src/class-satellite-passes.php#L153

That said, Heavens-above isn’t recognising BST as a valid timezone when passed in the URL anyways, so when manually uncommenting those lines for UK users at present date/time, Heavens-above throws an error. When configuring locally on Heavens-Above, GMT produces correct times, so something’s squiffy in their API relating to appropriate use of GMT / BST.

eg:

Have fixed this locally in my copy by uncommenting line at the above locations, and replacing...

https://github.com/stleary/stars-at-night/blob/750a4de1aabc0cb6a5bceb30ca362ad93169adc4/src/class-planet-passes.php#L60

https://github.com/stleary/stars-at-night/blob/750a4de1aabc0cb6a5bceb30ca362ad93169adc4/src/class-satellite-passes.php#L61

https://github.com/stleary/stars-at-night/blob/750a4de1aabc0cb6a5bceb30ca362ad93169adc4/src/class-satellite-passes.php#L147

...with:

$heavensAboveTZ = $dateTime->format ( 'T' ) == 'BST' ? 'GMT' : $dateTime->format ( 'T' );

...as otherwise everything was showing up for me with times an hour earlier than they should’ve been.

stleary commented 5 years ago

Investigating...

stleary commented 5 years ago

Hi @PatchworkBoy, thanks for bringing up this issue. I think in this case, it is working as designed. My recollection is that heavens-above does not use timezone in the UI when selecting locations, so I decided not to use it in the REST API either. It seems to be working correctly. In the shortcode, instead of timezone code 'BST', try using the PHP-supported string, 'Europe/London'. After all, we don't want to make users change their shortcode parameters twice a year. I will take an action item to clarify the documentation regarding how to specify timezones, and look into an enhancement request to allow the use of timezone abbeviations like BST.

PatchworkBoy commented 5 years ago

“...as otherwise everything was showing up for me with times an hour earlier than they should’ve been.”

The above was the case with unaltered code and time zone set to “Europe/London” as per standard configuration instructions for the plugin. It coming back with nonBST times set that way was what caused me to look at the code to start with.

stleary commented 5 years ago

@PatchworkBoy Sorry, missed this comment until just now, will investigate. Suspect there may be a problem with how the PHP lib processes the Europe/London timezone

stleary commented 5 years ago

@PatchworkBoy I checked against Europe/London time and the values seem to be correct.

Some background: This is a WordPress plugin that is implemented in PHP. The WordPress shortcode passes in required parameters including local latitude, longitude, timezone, and number of days to display. It only supports PHP-based timezone names. The algorithms are believed to work correctly even for timezones that are 30 or 45 minutes offset from UTC, and when the number of days spans a time change (e.g. transition from standard time to daylight savings time). Here is how it works:

Sunrise/sunset The latitude, longitude and timezone offset in hours is passed to the PHP functions, _datesunrise() and _datesunset(). These functions are called repeatedly for as many days ahead have been specified in the shortcode.

Moonrise/moonset The latitude, longitude, timezone offset in minutes, and the original timezone value is passed to code ported from this project: https://dxprog.com/entry/calculate-moon-rise-and-set-in-php where the moon times are calculated and returned. This function is called repeatedly for as many days ahead have been specified in the shortcode.

Planets, ISS, and Iridium flares The latitude and longitude are passed via the REST API to the http://www.heavens-above.com webserver. Timestamps are returned in UTC. This value is then rendered in the specified timezone. This function is called repeatedly for as many days ahead have been specified in the shortcode.

Request for more information Since there are 3 different mechanisms for calculating local time, it is unlikely that all of them will be wrong at the same time, unless there is a problem in the php timezone library. If you have noticed that any times are off by more than 2 minutes or so, please include the following information:

I will keep this issue open for a few months in case any problems are discovered.