Ondřej Láznička

Joined

50 Experience
0 Lessons Completed
0 Questions Solved

Activity

Posted in Redmine Rails

Hi, i have trouble with ruby ( i dont know any ruby basics but im edititing redmine plugin ).

I prepared method
def getDateForRedmine( startDay, endDay, limit, date )

        datetime = Date.strptime(date.to_s,'%Y-%m-%d %H:%M:%s').to_datetime
        hour = datetime.hour.to_i
        minute = datetime.minute.to_i

        if hour >= startDay
            tempTime = hour + limit
            if tempTime < endDay
                return date.change(hour: tempTime).to_s(:db)
            elseif tempTime == endDay
                if minute > 0  then
                  return date.change(hour: startDay, day: 1).to_s(:db)
                else
                  return date.change(hour: tempTime).to_s(:db)
                end
            elseif tempTime > endDay
                if  hour > endDay
                    return getDateForRedmine(startDay,endDay, limit, date.change(hour: 8, day: 1) )
                else
                    remains = tempTime - endDay
                    return getDateForRedmine(startDay,endDay, remains, date.change(hour: 8, day: 1) )
                end
            end
        else

        end
    end

Which based on given values return datetime shifted.

Example of input
startDay = 8
endDay = 16
limit = 4
date = is current date

And it should return date shifted based on workday. But it keep returning nulll..

logo Created with Sketch.

Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more. Icons by Icons8

© 2022 GoRails, LLC. All rights reserved.