0

I'm trying to select only results from Date.today + 1.day from a parsed json series, but i have confused myself on how best to implement this.

json is formatted as:

{"status": "ok", "data": {"temperatures": [["2014-09-16 07:00", 14.4], ["2014-09-16 08:00", 17.6], ["2014-09-16 09:00", 20.5], ["2014-09-16 10:00", 23.0], ["2014-09-16 11:00", 24.8], ["2014-09-16 12:00", 26.4]]}} 

Controller

dates = [] temps = [] @forecast['data']['temperatures'].each do |data| dates << data[0] temps << data[1] end dates.flatten.each do |d| dates << DateTime.parse(d).strftime("%d %b - %H:%M") end @results = dates.map {|f| [Date.today + 1.day(f), temps]} 

    1 Answer 1

    1

    If you want to select data where date is greater than one day from now then:

    @forecast['data']['temperatures'].select{|temp| temp[0].to_date > 1.day.from_now.to_date } 

    else if you want to select data where date is greater than or equal to one day from now:

    @forecast['data']['temperatures'].select{|temp| temp[0].to_date >= 1.day.from_now.to_date } 
    0

      Start asking to get answers

      Find the answer to your question by asking.

      Ask question

      Explore related questions

      See similar questions with these tags.