Author Topic: wxastronomy.php $marchequinox get_localdate() language  (Read 1367 times)

0 Members and 1 Guest are viewing this topic.

Offline jachen

  • Member
  • *
  • Posts: 39
    • Neue Wetterstation Widen
wxastronomy.php $marchequinox get_localdate() language
« on: January 28, 2020, 05:59:17 AM »
There is something obscure with rendering  the 'localdate' in wxastronomy.php. There are the two functions get_utcdate() anf get_localdate() involved which I am not able to completely understand when it comes to convert the WD-Dates.

In my case the problem appears to be the german Umlat (ä or ä) which renders the correct marchequinox for utc but on the other hand renders 01/01/1970 01:00 for the get_localdate($marchequinox) - Function. I can see this phenomenum on many Sites using wxastronomy.php and its just left as it is.

My workaround was to change the get_localdate($marchequinox) to get_utcdate($marcheequinox) in order not to render the 01/01/1970 01:00.

However I am not happy with this. Particularly when trying to json_encode($marchequinox) for usage in another program php quits.
Well, could easily forget this variable since all the other variables encode perfectly. But it teases me.

Any hint around the mentioned behavior would be appreciated.

Have a nice day everywhere.
     

Offline Jasiu

  • Forecaster
  • *****
  • Posts: 949
    • LexMAWeather
Re: wxastronomy.php $marchequinox get_localdate() language
« Reply #1 on: January 28, 2020, 09:13:03 AM »
In your Settings.php, is "monthNames" set with the months matching what would get passed in the string to get_localdate()? That needs to be the case because that function attempts to convert the month names to English to call strtotime().

If you provide a pointer to the site, some of us can take a look directly to see what might be going on.
https://lexmaweather.info
On Mastodon: @LexMAWeather@toot.community

Offline jachen

  • Member
  • *
  • Posts: 39
    • Neue Wetterstation Widen
Re: wxastronomy.php $marchequinox get_localdate() language
« Reply #2 on: January 28, 2020, 09:54:48 AM »
Thank you for paying attention. You should be able to reach the Site by using the green button on my profile in the left pane here or directly to the wxastronomy.php page https://meteo.widen-online.ch/wxastronomy.php.

Code: [Select]
$SITE['monthNames'] = array(
'Januar','Februar','März','April','Mai','Juni',
'Juli','August','September','Oktober','November','Dezember'
);

I had to change the code of the function invocation from  get_localdate($marchequinox) to get_utcdate($marchequinox) in order to avoid a date of 01/012/1970 01:00.
 
Code: [Select]
<?php if ($SITE['latitude'] >= 0) { // Use Northern Hemisphere dates with images?>
      <td align="center">
  <?php echo get_localdate($marchequinox); ?><br/>
  <small><?php echo get_utcdate($marchequinox); ?></small></td>

I think this issue is not trivial.


Offline Jasiu

  • Forecaster
  • *****
  • Posts: 949
    • LexMAWeather
Re: wxastronomy.php $marchequinox get_localdate() language
« Reply #3 on: January 28, 2020, 10:09:34 AM »
Have a look at

   view-source:https://meteo.widen-online.ch/wxastronomy.php

Search for "after utcstr" in the HTML comments. All of the translations work except for March, so something is amiss in the conversion code in get_localdate.

Code: [Select]
// input dates are assumed to be in English only
 if (isset($SITE['monthNames'])) {
    // convert TO English for strtotime()
    echo "<!-- before utcstr='$utcstr' -->\n";
foreach ($EnglishMonths as $i => $monthEN) {
   $utcstr = preg_replace('| '.$SITE['monthNames'][$i].' |i'," $monthEN ",$utcstr);

    echo "<!-- after utcstr='$utcstr' -->\n";
  }

I'm going to be offline for most of the day but Ken or someone can probably figure this out fairly quickly.
https://lexmaweather.info
On Mastodon: @LexMAWeather@toot.community

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9279
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: wxastronomy.php $marchequinox get_localdate() language
« Reply #4 on: January 28, 2020, 12:13:50 PM »
My suspicion is that the ä  in 'März' is in UTF-8 and not in ISO-8859-1/ANSI in the
Code: [Select]
$SITE['monthNames'] = array(
'Januar','Februar','März','April','Mai','Juni',
'Juli','August','September','Oktober','November','Dezember'
);
in Settings.php.

The März has to be translated to March in order for the strtotime() to be able to handle the month name.. since it can't translate it by lookup, the strtotime() returns a 1970 date for the local date.  Try editing your Settings.php and convert it to ISO-8859-1/ANSI and retype the ä in März and upload your Settings.php again.
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 jachen

  • Member
  • *
  • Posts: 39
    • Neue Wetterstation Widen
Re: wxastronomy.php $marchequinox get_localdate() language
« Reply #5 on: January 30, 2020, 06:02:01 AM »
Thank you very much Ken.

As you mentioned it appeared that Settings.php were UTF-8 on Server. I then changed locally with the VSC-Editor to ISO-8859-1 retyped the ä and uploaded again. But there was no improvement.

Could it be that everything gets converted to UTF-8 again serverside? How to overcome that?

Offline jachen

  • Member
  • *
  • Posts: 39
    • Neue Wetterstation Widen
Re: wxastronomy.php $marchequinox get_localdate() language
« Reply #6 on: January 31, 2020, 05:32:29 AM »
Wxastronomy uses $marchequinox as argument for get_locale() function.

$marchequinox (in testtags.php locally) is continuously uploaded (written to testtags.php on server) from my Client running WD and set to Language German/Swiss. So there is no chance (at least for me) to achieve the desired Output.

If I was to change the PC to US-English I might run into a ton of resettings on the serverside. Probably not worthwhile.

Cheers jachen

Offline jachen

  • Member
  • *
  • Posts: 39
    • Neue Wetterstation Widen
Re: wxastronomy.php $marchequinox get_localdate() language
« Reply #7 on: February 02, 2020, 02:41:50 PM »
It took me a few hours to learn a bit of php to reengineer stuff in wxastronomy.php.

Finally the change of 2 lines did the job:

Code: [Select]
<?php $iso88591 utf8_encode($marchequinox);?>
    <?php echo get_localdate($iso88591);?><br/>

Thanks to everybody for the kind hints and have a good time.

 

anything