Ruby code to get the date of next Monday (or any day of the week)

前端 未结 7 479
再見小時候
再見小時候 2020-12-02 14:36

Given an input of, for example,

day = \'Monday\'

how can I calculate the date of day?

def date_of_next(day)
           


        
7条回答
  •  情话喂你
    2020-12-02 14:51

    For stuff like this I rely on the chronic library.

    The Ruby code would be:

    def date_of_next(day)
        Chronic.parse("next #{day}")
    end
    

提交回复
热议问题