how to iterating days

后端 未结 2 1538
遥遥无期
遥遥无期 2021-01-29 09:15

I have a code for looping days.this to make leaves. I want column signin and signout on attendance will filling automatically start at startdate and end at enddate.



        
相关标签:
2条回答
  • 2021-01-29 10:07

    If startdate is of type Date, why not just do,

    @attendance.signin = @leafe.startdate+i
    @attendance.signout = @leafe.startdate+i
    
    0 讨论(0)
  • 2021-01-29 10:09

    Why you using for loop? It looks like javacode. Use instead block with range like:

    (Time.now.beginning_of_day.to_i..Time.now.to_i).step(3600) do |n|#step one hour for example
      @attendance = Attendance.new
      .......
      @attendance.signin  = @leafe.startdate
      @attendance.signout = @leafe.startdate + n # u can change time interval to any what you want
    
    end
    
    0 讨论(0)
提交回复
热议问题