Storing Seconds in a Variable (Precise Sunrise & Sunset)


#1

1) Give a description of the problem
I am trying to convert the new sunrise and sunset times into global variables, since that new data actually show seconds (for accuracy)

2) What is the expected behavior?

$twcweather.conditions.sunriseTimeLocal »»» 2019-03-22T06:56:40-0500
$twcweather.conditions.sunsetTimeLocal  »»» 2019-03-22T19:07:28-0500

(Notice the seconds are there at this point)

3) What is happening/not happening?
When I use this code, it does not round, it just deletes the seconds completely:

as seen here:

temp


When I try to get fancy and store it as a string:

I can get all the info into the variable:

temp

but then when I try to convert that into a useful time variable:

temp

… it also deletes the seconds!!

temp


Is it possible to store seconds in a time based variable?!?

Basically, I need a way to get the accurate sunrise and sunset times into global variables, so other pistons can use that time instead of the system variables which do not display seconds.

Any help or guidance would be greatly appreciated.


#2

Well, it seems to be possible. I’m not at my computer but I did this test.

Perhaps if you can capture the seconds and add them in to the conversion? Kluge but it might work.


#3

Thanks @guxdude… I was trying to avoid that, but you are right, it works.
(although it took 8 lines of code and 6 variables)

… which yields:

temp


Here’s my latest import code if anyone is able to condense this code a bit…
(something tells me this can be done in 2 lines… or 4 if you count the globals)

Global results look good:

temp

… although maybe the long code doesn’t matter, since this will only be running once per day.


#4

Sorry, just got to a computer. Not sure if you wanted the shortened time string for anything but here is a possible alternative. I was able to combine the last two steps in your example using the time() function.

One question might be even once you have these correct times, if you do any operations with them will it make a difference or will the operations truncate the seconds? Food for thought…


#5

Thanks @guxdude!! I always forget about time()

I do want to keep that string, but I incorporated both of our ideas here in 6 lines:

temp

I will share the full import code once I pinpoint at what time the data for the new day rolls over.
(unfortunately, it is not midnight)

I might end up snagging tomorrow’s data at 11:59pm to keep my times sharp.


#6

It sticks :sunglasses:

temp


#7

Ugg. The deeper I dig, the less and less impressed I am with $twcweather…

For some strange reason, the sunrise times changes hourly when I query:
$twcweather.forecast.sunriseTimeLocal[0]

temp

So far, I have only noticed the seconds changing, but that tells me a lot about their infrastructure & accuracy.


#8

interesting. When I was playing with it, I thought it changed once but chalked it up to bad memory.


#9

More analysis on TWC.Forecasts
(and why they should be avoided for sun times)
over in this thread.

(the Wiki has been updated)