Page 1 of 1

Weather Console date format

Posted: Wed 30 May 2018 9:15 pm
by tmabell
I'm using the Weather Console obtained from here: http://wiki.sandaysoft.com/index.php?ti ... herConsole

There is a function that displays the time of the last connection to the station as well as the time until the next poll. This is an example of what it looks like:
Last contact with station: 30/05/18 17:07:22. Update in: 8 seconds
My issue is the format of the date. I'd like it to be MM/DD/YY but as you can see the year is listed first. Can this be changed somehow?

Here is a screenshot:
https://mymishawakaweather.com/files/Untitled.jpg

Re: Weather Console date format

Posted: Wed 30 May 2018 11:28 pm
by beteljuice
... MM/DD/YY but as you can see the year is listed first
err .. no it isn't :? DD is listed first ;)

If you really need to change it ...
That's from wsconsole.js

Code: Select all

$("#last_contact").html(rawdata[0] +" "+ rawdata[1]);
It is simply reading what is in realtime.txt (fields 0 and 1)

You would have to do some js coding to split and rearrange field[0] !

Re: Weather Console date format

Posted: Thu 31 May 2018 12:00 am
by tmabell
Yes, sorry. Typo. So the wconsole.js is where I need to go?

Re: Weather Console date format

Posted: Thu 31 May 2018 1:43 am
by beteljuice
yes wconsole.js
You would need to change:

Code: Select all

$("#last_contact").html(rawdata[0] +" "+ rawdata[1]);
To something like:

Code: Select all

var thedate = rawdata[0].split('/'); // new array with date components (DD, MM, YY)
$("#last_contact").html(thedate[1] +"/"+ thedate[0] +"/"+ thedate[2] +" "+ rawdata[1]); // stitched to MM/DD/YY
UNTESTED !

Re: Weather Console date format

Posted: Thu 31 May 2018 11:28 am
by tmabell
I tested your code and it works perfectly! Thanks a million :D

Re: Weather Console date format

Posted: Thu 31 May 2018 3:58 pm
by tmabell
Can the time format be changed from 24-hour to 12-hour in a similar manner?

UPDATE Re: Weather Console date format

Posted: Fri 01 Jun 2018 12:10 pm
by tmabell
I found a way to do this however, I can't find a way to remove the preceding zero when the hour is a single digit, i.e. 7:00 AM displays as 07:00 AM.

I replaced this:

Code: Select all

var d = new Date();
With this:

Code: Select all

var d = (h24 = new Date().getHours()) && (h24 - ((h24 == 0)? -12 : (h24 <= 12)? 0 : 12)) + (h24 < 12 ? " am" : " pm");

Re: Weather Console date format

Posted: Fri 01 Jun 2018 12:27 pm
by mcrossley
That will use the time from the client, not the time from the station. For the update time you could do something like this (untested)...

Code: Select all

var thedate = rawdata[0].split('/'); // new array with date components (DD, MM, YY)
var thetime = rawdata[1].split(':'); // new array with time components (hh, hh, ss)
thetime[0] = thetime[0] > 12 ? thetime[0] - 12 : thetime[0] * 1;
rawdata[1] = thetime.join(':');
$('#last_contact').html(thedate[1] +'/'+ thedate[0] +'/'+ thedate[2] +' '+ rawdata[1]); // stitched to MM/DD/YY
I leave it to you to do all the data times - I'd wrap that in a function and call it for each value.

Re: Weather Console date format

Posted: Fri 01 Jun 2018 5:06 pm
by tmabell
Mark,

Many thanks. Your code works right out of the box when inserted into wconsole.js.

However, there is no AM/PM appended to the time. Is this by design?

Tom

Note: Edited to remove an incorrect observation on my part.

Re: Weather Console date format

Posted: Fri 01 Jun 2018 5:24 pm
by mcrossley
Something like this then (untested again)...

Code: Select all

var thedate = rawdata[0].split('/'); // new array with date components (DD, MM, YY)
var thetime = rawdata[1].split(':'); // new array with time components (hh, hh, ss)
var amPm = thetime[0] > 12 ? 'pm' : 'am';
thetime[0] = thetime[0] > 12 ? 1 * thetime[0] - 12 : thetime[0] * 1;
rawdata[1] = thetime.join(':');
$('#last_contact').html(thedate[1] +'/'+ thedate[0] +'/'+ thedate[2] +' '+ rawdata[1]+ ' '+amPm); // stitched to MM/DD/YY

Re: Weather Console date format

Posted: Fri 01 Jun 2018 5:33 pm
by tmabell
Mark,

This version works! I will need to wait until after midnight here to determine if it works for hours that fall in the AM but so far so good.
Here is a sample output from my customization:
Last contact with station: 06/01/2018 at 1:32:30 pm. Next update in 18 seconds.
Thank you for your help.

Tom