I have a list of list containing start_time and end_time. something like this
[[3600, 4800], [3600, 4800], [3600, 4800]]
We are storing start_time and end_time as an integer and in minutes. Now I need to how can I somehow convert this to a DateTime. So that I can compare it with local_time or system time.
But in order to do that, I’m struggling with the next step. Do I need to convert this to a second? Or first add them and convert it to a second and add some format to it. What should I do?
You can convert these to Time and compare them with Time.utc_now. Not sure what exactly the minutes represent in your example since 3600 minutes is 60 hours and you can’t convert to datetime unless you have some reference date to add the minutes to.
Then you’d need to get the date for beginning of the week convert it to a datetime with zero time Time.new!(0,0,0), and add minutes * 60 seconds to it. You might also need to use a timezone other than UTC for calculations to be correct (comparing to DateTime.utc_now probably would work fine anyways).
I might not fully understand the problem, but based on minutes being relative to beginning of the week, yes, each minute in your dataset would need to be using a reference date to get a correct datetime.
I have one more question. How can I check if this ~U[2021-09-15 11:44:25.320726Z]
lies between this [~U[2021-09-15 12:00:00Z], ~U[2021-09-16 08:00:00Z]]. Is there any in built function for this?