Author Topic: Earthquake Script Gives Time One Hour Too Early  (Read 1546 times)

0 Members and 1 Guest are viewing this topic.

Offline Bunty

  • Forecaster
  • *****
  • Posts: 2432
  • Stillwater, home of Oklahoma State University
    • Welcome to Stillwater Weather
Earthquake Script Gives Time One Hour Too Early
« on: May 29, 2017, 08:06:06 PM »
The earthquake script I'm using gives the time quakes occur as an hour early from the actual time.  I got the time in the script set as America/Chicago, the correct setting for my location.  What else to look for that is wrong?

http://stillwaterweather.com/okareaearthquakes.php
« Last Edit: June 04, 2017, 09:58:13 PM by Bunty »

Also the 2nd home page using modified AltDashboard 6.95 at http://stillwaterweather.com/2ndhome.php

Offline Jáchym

  • Meteotemplate Developer
  • Forecaster
  • *****
  • Posts: 8605
    • Meteotemplate
Re: Earhquake Script Gives Time One Hour Too Early
« Reply #1 on: May 29, 2017, 08:33:57 PM »
Quote
The earthquake script I'm using

Seeing the result without seeing how it was generated is useless, can you post the source code?

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9279
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: Earhquake Script Gives Time One Hour Too Early
« Reply #2 on: May 29, 2017, 10:16:04 PM »
He's using the quake-json.php V1.12 - 21-Feb-2017 (current version).

Running a view-source on your page with ?cache argument (to force a cache reload) shows
Quote
<!-- quake-json.php V1.12 - 21-Feb-2017 -->
<!-- lat=35.46153397 long=-97.52274323 dist=200 mag=2.0 distanceDisplay ='mi' -->
<!-- force cache reload -->
<!-- loading ./quakesjson.txt from https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/1.0_week.geojson -->
<!-- curl fetching 'https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/1.0_week.geojson' -->
<!-- HTTP stats:  RC=200 dest=2600:1404:27:2a2::26b7 port=443 (from sce=2602:ff3c:0:1:20e:b6ff:fe67:ce98)
      Times: dns=0.037 conn=0.045 pxfer=0.074 get=0.197 total=0.271 secs -->
<!-- loading finished. -->
<!-- data last modified Tue, 30 May 2017 02:11:21 GMT -->
<!-- Update time = Tue, May-30-2017 2:11am GMT UTC-->
<!-- Update time = Mon, May-29-2017 9:11pm CDT  Local-->
<!-- content length=759530 -->
<!-- found 1060 earthquake records -->

You are -5 hrs from GMT/UTC so that's correct.  Mine shows the -7 hrs for Pacific time and that's correct also.

The times in the JSON records are all in UTC, and fed to date() using your America/Chicago setting.. so what are you seeing as one hour off??
Ken True/Saratoga, CA, USA main site: saratoga-weather.org
Davis VP1+ FARS, Blitzortung RED, GRLevel3, WD, WL, VWS, Cumulus, Meteobridge
Free weather PHP scripts/website templates - update notifications on Twitter saratogaWXPHP

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9279
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: Earhquake Script Gives Time One Hour Too Early
« Reply #3 on: May 30, 2017, 12:15:45 PM »
I think I found the issue.  The USGS has a tz field in the JSON for the quake details that is not (currently) adjusted for daylight savings time at the lat/long of the quake.

Try changing quake-json.php from
Code: [Select]
  $Qtimestamp = $Qtimestamp+$onequake['properties']['tz']*60;
  $QDateTime = gmdate($timeFormat,$Qtimestamp);
to
Code: [Select]
//   $Qtimestamp = $Qtimestamp+$onequake['properties']['tz']*60;
  $QDateTime = date($timeFormat,$Qtimestamp);
  and see if that fixes the issue.
Ken True/Saratoga, CA, USA main site: saratoga-weather.org
Davis VP1+ FARS, Blitzortung RED, GRLevel3, WD, WL, VWS, Cumulus, Meteobridge
Free weather PHP scripts/website templates - update notifications on Twitter saratogaWXPHP

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9279
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: Earhquake Script Gives Time One Hour Too Early
« Reply #4 on: May 30, 2017, 04:40:48 PM »
I think that may be the fix.  I sent off a note to the USGS webmasters
Quote
On May 30, 2017, at 11:46 AM, Ken True <webmaster@saratoga-weather.org> wrote:

    Gentlefolks,

    I have a script that many use on their websites to display recent earthquake data using
    https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/1.0_week.geojson as the data source.

    Script page at https://saratoga-weather.org/scripts-quake.php#quakePHP

    For an individual quake entry like

        "features": [{
                "type": "Feature",
                "properties": {
                    "mag": 2.21,
                    "place": "17km S of Tehachapi, CA",
                    "time": 1496157394160,
                    "updated": 1496157625392,
                    "tz": -480,
                    "url": "https://earthquake.usgs.gov/earthquakes/eventpage/ci37657247",
                    "detail": "https://earthquake.usgs.gov/earthquakes/feed/v1.0/detail/ci37657247.geojson",
                    "felt": null,
                    "cdi": null,
                    "mmi": null,
                    "alert": null,
                    "status": "automatic",
                    "tsunami": 0,
                    "sig": 75,
                    "net": "ci",
                    "code": "37657247",
                    "ids": ",ci37657247,",
                    "sources": ",ci,",
                    "types": ",geoserve,nearby-cities,origin,phase-data,scitech-link,",
                    "nst": 5,
                    "dmin": 0.2072,
                    "rms": 0.22,
                    "gap": 221,
                    "magType": "ml",
                    "type": "earthquake",
                    "title": "M 2.2 - 17km S of Tehachapi, CA"
                },

    The "tz" value is supposed to be the offset in minutes from GMT/UTC for the quake location.
    For a pacific quake like above, the tz offset is set at -480 minutes (8 hours), but we're in daylight savings time, so it should be -420 minutes.

    I see the same results for quakes in Oklahoma which is on CDT and should be -5 hrs, but is showing as -6 hrs in the tz JSON value.

    Can this be corrected in the GeoJSON feed?

    Thanks in advance!

    --

    Best regards,
    Ken
    Script updates via Twitter at https://twitter.com/saratogaWXPHP

They responded with
Quote
Hello,

Thanks for contacting us about the timezone issues, that dataset has not been updated since 2015 and is slowly being phased out.

I recommend using javascript with the UTC time to format times based on the user timezone offset, rather than our estimate of the epicenter timezone offset.


Thanks,

Jeremy

I'll update the code to use the TZ settings in the script (or Settings.php in the Saratoga template).

Thanks Bunty for the heads-up about the issue :)
Ken True/Saratoga, CA, USA main site: saratoga-weather.org
Davis VP1+ FARS, Blitzortung RED, GRLevel3, WD, WL, VWS, Cumulus, Meteobridge
Free weather PHP scripts/website templates - update notifications on Twitter saratogaWXPHP

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9279
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: Earhquake Script (quake-json.php) Gives Time One Hour Too Early
« Reply #5 on: May 30, 2017, 06:17:26 PM »
Script updated.

quake-json.php V1.13 - 30-May-2017

Standalone:  https://saratoga-weather.org/scripts-quake.php
Saratoga Template: https://saratoga-weather.org/wxtemplates/updates.php with query (Base-*, Plugin-*, 30-May-2017)
Ken True/Saratoga, CA, USA main site: saratoga-weather.org
Davis VP1+ FARS, Blitzortung RED, GRLevel3, WD, WL, VWS, Cumulus, Meteobridge
Free weather PHP scripts/website templates - update notifications on Twitter saratogaWXPHP

Offline R_o_B

  • WxElement panel
  • Senior Member
  • *****
  • Posts: 85
Re: Earhquake Script (quake-json.php) Gives Time One Hour Too Early
« Reply #6 on: May 31, 2017, 07:31:20 AM »
Script updated.

quake-json.php V1.13 - 30-May-2017
Ken, you might want to update the 'quake-json.zip' with the new 'quake-json.php' script...  ;)
R_o_B
---
eMail: weather@herray.net

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9279
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: Earhquake Script Gives Time One Hour Too Early
« Reply #7 on: May 31, 2017, 10:52:44 AM »
Oops.. thanks for the reminder.  It's updated in quake-json.zip now.
Ken True/Saratoga, CA, USA main site: saratoga-weather.org
Davis VP1+ FARS, Blitzortung RED, GRLevel3, WD, WL, VWS, Cumulus, Meteobridge
Free weather PHP scripts/website templates - update notifications on Twitter saratogaWXPHP

Offline Bunty

  • Forecaster
  • *****
  • Posts: 2432
  • Stillwater, home of Oklahoma State University
    • Welcome to Stillwater Weather
Re: Earhquake Script Gives Time One Hour Too Early
« Reply #8 on: June 05, 2017, 01:35:39 AM »
I think I found the issue.  The USGS has a tz field in the JSON for the quake details that is not (currently) adjusted for daylight savings time at the lat/long of the quake.

Try changing quake-json.php from
Code: [Select]
  $Qtimestamp = $Qtimestamp+$onequake['properties']['tz']*60;
  $QDateTime = gmdate($timeFormat,$Qtimestamp);
to
Code: [Select]
//   $Qtimestamp = $Qtimestamp+$onequake['properties']['tz']*60;
  $QDateTime = date($timeFormat,$Qtimestamp);
  and see if that fixes the issue.

It worked.  Thanks.  Will this script have to be readjusted back to the way it was when daylight time changes back to standard time?

I didn't realize it needed fixed until the drama on Monday, May 29th, when earthquakes started acting up in the immediate Stillwater area for the first time in a good while.  The third and final quake being the strongest startled me with a very loud thunder like explosive noise. It was only 2.9 in magnitude but centered only a mile or so from my home.  The loud roar of nearby low magnitude earthquakes of around 3.0 is mightier than their bite.  Later, noticed the earthquake script reported it an hour too early. 

Meanwhile, I continue have to hope the quakes don't get much stronger.  It's a greater worry of mine than a tornado coming.  I know that quakes in the 5.0 to 6.0 range in Oklahoma in magnitude when centered in or near towns can cause serious damage, especially to older buildings.  Thankfully, quakes that strong are still rare around here.
« Last Edit: June 05, 2017, 01:51:37 AM by Bunty »

Also the 2nd home page using modified AltDashboard 6.95 at http://stillwaterweather.com/2ndhome.php

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9279
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: Earthquake Script Gives Time One Hour Too Early
« Reply #9 on: June 05, 2017, 11:21:50 AM »
Glad it worked.. I did publish that change to the script.

No, you won't have to change the script when daylight savings time changes .. your PHP will automatically do that based on your timezone setting. The USGS is apparently going to discontinue the tz in their JSON, and their website now only reports using UTC for quake times (no more local time at epicenter display).
Ken True/Saratoga, CA, USA main site: saratoga-weather.org
Davis VP1+ FARS, Blitzortung RED, GRLevel3, WD, WL, VWS, Cumulus, Meteobridge
Free weather PHP scripts/website templates - update notifications on Twitter saratogaWXPHP