0

It appears that if the minutes start with a 0, it drops the digit -- see

https://query.yahooapis.com/v1/public/yql?q=select%20astronomy%20from%20weather.forecast%20where%20woeid%20in%20(select%20woeid%20from%20geo.places(1)%20where%20text%3D%22los+angeles%2C%20ca%22)&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys

Returns:

{"query":{"count":1,"created":"2017-03-14T23:40:02Z","lang":"en-us","results":{"channel":{"astronomy":{"sunrise":"7:5 am","sunset":"7:0 pm"}}}}}

While

https://query.yahooapis.com/v1/public/yql?q=select%20astronomy%20from%20weather.forecast%20where%20woeid%20in%20(select%20woeid%20from%20geo.places(1)%20where%20text%3D%22maui%2C%20hi%22)&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys

Returns

{"query":{"count":1,"created":"2017-03-14T23:41:16Z","lang":"en-us","results":{"channel":{"astronomy":{"sunrise":"6:35 am","sunset":"6:35 pm"}}}}}

Any ideas for a fix to this? I guess I could slice the time at the colon and then pad the result to 2 digits, but that seems messy.

Dennis
  • 482
  • 7
  • 17
  • I suggest voting for this issue to be resolved: https://yahoo.uservoice.com/forums/207813-us-weather/suggestions/19171732-sunrise-sunset-times-are-missing-a-digit – Eric Martin May 05 '17 at 16:02

1 Answers1

1

var el = {"query":{"count":1,"created":"2017-03-14T23:49:12Z","lang":"ru-RU","results":{"channel":{"astronomy":{"sunrise":"7:5 am","sunset":"7:0 pm"}}}}};
var a = el.query.results.channel.astronomy;

for(var i in a)
{
    if (/^\d{1,2}\:\d{1}\s/.test( a[i] ))
    {
        var value = /^\d{1,2}(\:\d)\s/.exec(a[i])[1];
        a[i] = a[i].replace( value, ':0' + value.substr(1) )
    }
}

console.log(a)
MypKOT-1992
  • 191
  • 3