Trixology
WeatherCat => WeatherCat Web Templates => Topic started by: monymony on September 24, 2013, 07:03:13 PM
-
Hello All,
Running into a small issue which I think is coming from the ajax-gizmo.php page from the Saratoga templates. Here is what is happening...
- When I first load my page (i.e. index.php) everything is correct with both the last updated date (Sep-24-2013 1:59p) and the rain rate/hr (0.00in) formats
- After 10 seconds, the gizmo does an update and the updated time changes to a 24-hour clock (09/24/13 13:59). Also my Rain Rate/Hr goes from 0.00in to 0.000in
I been over all of the settings and cannot explain either issue. From my settings.php file my time/date settings are:
- $SITE['timeFormat'] = 'D, M-d-Y g:ia T'; // Day, 31-Mar-2006 6:35pm Tz (USA Style)
- $SITE['timeOnlyFormat'] = 'g:ia'; // USA format h:mm[am|pm\
- $SITE['dateOnlyFormat'] = 'M-d-Y'; // for Mar-31-2008 or 'j/n/Y' for Euro format
My site for the moment is only running internally so I cannot provide a link for anyone to take a look at. I want to get all of these issues resolved before release this to the internet. Any suggestions would be greatly appreciated. I've attached a screenshot to show what I am seeing.
Thanks!
Jay
-
When your page first loads, it is PHP (and the settings inside of Settings.php) that determines how the date/time is put in the HTML of the page returned to the browser. After the page is loaded, the ajaxWCTwx.js JavaScript begins execution in the browser, reads the WCT_realtime.txt, and rewrites parts of the HTML page by replacing contents of the <span class="ajax" id="..."></span> pairs.
The ajaxWCTwx.js has only limited formatting capabilities for date.. mainly whether to display the date as dd/mm/yyyy or mm/dd/yyyy format - the dd-MON-yyyy format is not available in the JavaScript.
I suggest you settle on dd/mm/yyyy or mm/dd/yyyy format for your date format both in PHP and the Javascript.. then the change when the JavaScript begins execution will just be a 'green flash' of the characters.
The time format is flexible in PHP, but again, the JavaScript simply presents the contents of the second field in WCT_realtime.txt, so those contents are determined by WeatherCat template for WCT_realtime.txt .. no additional formatting is available in the JavaScript.
Currently, the WeatherCat tags used in the WCT_realtime.txt template are:
de$|t24s$|
for the first two fields.
Hope this helps...
Best regards,
Ken
-
Thank you Ken!
That was extremely helpful. Working for a European-based company I have gotten into the habit of avoiding using numbers for the month since there is always confusion between mm/dd/yyyy and dd/mm/yyyy.
Now that I knew where to look, I set an array to change the month (tdate[1]) to the appropriate three letter abbreviation. I also used similar logic to get rid of the leading "0" on the time as it was driving me crazy. While I am certainly not a Java programmer, I knew enough about coding in other languages to figure this out. In case anyone is interested this is what I did (approximately line 900 of the ajaxWCTws.js file):
// current date and time of observation in realtime.txt
//JMM (9/24/13) - Added code to put in three letter month abbreviation (i.e. Jan, Feb, etc) since
//Java ignores settings from settings.php
//var ajaxtimeformat = realtime[1]; //JMM
var ajaxdateraw = realtime[0]; // comes in dd/mm/yy, dd-mm-yy or dd.mm.yy format
var tdate = ajaxdateraw.split("/");
if(typeof(tdate[2])=='undefined') {tdate = ajaxdateraw.split("-"); }
if(typeof(tdate[2])=='undefined') {tdate = ajaxdateraw.split("."); }
//JMM - These lines were all changed to add Month and remove leading "0" from time. Also
//updated the WCT_Realtime.txt file to change the t24s$ to t12s$.
var arr = new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
var m = parseInt(tdate[1])-1; //JMM
var ajaxdateformat = arr[m]+"-"+tdate[0]+"-20"+tdate[2];
var ajaxtimeformatraw = realtime[1];
var ttime = ajaxtimeformatraw.split(":");
var ajaxtimeformat = parseInt(ttime[0])+":"+ttime[1]+":"+ttime[2];
//Updates sometimes do not work machines not set to mm/dd/yyyy. If error then will revert to previous code.
if(typeof(arr[m])=='undefined' || parseInt(ttime[0])=="0") {
var ajaxdateformat = tdate[1]+"-"+tdate[0]+"-"+tdate[2];
var ajaxtimeformat = realtime[1];
}
//JMM - End Edits
I also did change my WCT_Realtime.txt file to change the t24s$ to t12s$.
For the other issue where the rain rate was changing to 0.000 in/hr I did find the problem and I believe there is a small bug with the code. In the code:
var rainratehr = convertRain(realtime[8]); // make per hour rate.
set_ajax_obs("ajaxrainratehr",rainratehr.toFixed(dpRain+1) + uomRain);
The 'dpRain+1' seems to be the problem. I am not sure why this is in the code and changing this line to:
set_ajax_obs("ajaxrainratehr",rainratehr.toFixed(dpRain) + uomRain)
does resolve the issue. Best guess is this 'dpRain+1' is for millimeters but honestly I really do not know.
Again thank you for your helpful pointers as I slowing getting things tweaked just as I like and better yet I am learning a lot along the way! Now time will tell if my changes managed to break anything. :D
Jay
-
FYI... I have tweaked my code list above to better handle errors that appear to happen on machines not set to the US mm/dd/yyyy date format. If something strange is detected then code just reverts to the original settings.