Get a set of the next 7 given days - ruby-on-rails

I allow teachers to set schedules for days they're working. Saved in the DB with their week days 0..6. Now what I want to achieve is to give a method a date, often todays date and retrieve the next 7 days they'll be able to work. Take note that for example if their TimeSlot only have a week_day column stored as 1 then the 7 next Mondays should be retrieved.
If it's Mondays and Wednesdays then they'll be returned until 7 days have been stored and returned.
Do anybody have experience in how I might handle this. I struggeling with how to find a good solution to iterate over dates.

Related

Is there a cleaner, shorter version of this Google Sheets formula for determining the next date based on a recently input date?

I have a sheet with the date of an initial assessment. A review for each assessment needs to be done every 90 days.
This is what the table looks like:
Initial
Last Review
Next Review
5/5/22
8/3/22
In the second column, the last review will be entered so the next review will also update. However, the review date is based on the initial assessment, not the date of the review. So if the review is done early or late, the next review date will still be based on the initial assessment.
This is what the table should look like
Initial
Last Review
Next Review
5/5/22
6/12/22
11/1/22
For now I am using this IFS formula in the third column that looks at the second column and updates the date for the next review:
=IFS(B1="",A1+90,(B1>=A1+0)*(B1<=A1+90),A1+180,(B1>=A1+90)*(B1<=A1+180),A1+270,(B1>=A1+180)*(B1<=A1+270),A1+360,(B1>=A1+270)*(B1<=A1+360),A1+450,(B1>=A1+360)*(B1<=A1+450),A1+540,(B1>=A1+450)*(B1<=A1+540),A1+630)
This works perfectly fine, but some reviews can potentially be more than 630 days later. Is there a way to shorten this formula, or will need to keep adding more and more to calculate the dates past 630 days?
Edit: So I had a realization after messing around with some of the dates and the answers provided. If the review is done late, the formula will skip a review date.
Using the example I included, if the first review is done on 8/6/22, then the next review will be shown as 1/30/23 instead of 11/1/22.
From the answers provided #Martin 's answer =IF(B1="",A1+90,A1+(1+ROUNDUP((B1-A1+1)/90))*90 works perfectly if the review is done early or on time. #Arav 's answer =IF(B1="",A1+90,B1+90-MOD(B1-A1,90)) will only work if the review is late.
You can try with ROUNDUP:
=IF(B1="",A1+90,A1+(1+ROUNDUP((B1-A1+1)/90))*90
That will calculate the amount of 90 days passed and round up to the next one 90s
UPDATE
I think that the only case in which a date would change the calculations is when it's done early. Meaning, as you stated in your comments, 14 days before the next revision. Considering that, the formula would be with those 14 days summing:
=IF(B1="",A1+90,A1+(+ROUNDUP((B1-A1+14)/90))*90)
What should you do if the date is more than 30 days later?? If it's late, the date of the next revision shouldn't stay but keep in the next multiple of 90 days lapse. What you can do is to use some conditional formatting, for example:
=(MOD((B1-A1),90)>30)*(MOD((B1-A1),90)<76)
That considers the dates going from more than 30 days to less than 76 (because then it would be an early review of the next date)
See this conditional formatting operating in this example, in which I mapped 5 days lapse to see how the dates are changing. As you can see, the orange is for the out-of-date revisions with the previous conditional formatting; and in green I marked the places where the dates change:
Let me know!
The formula you've provided is checking for specific ranges of days between the initial assessment and the last review, and then returning the next review date based on those ranges. It's a bit long and can be hard to read.
To shorten the formula and make it more flexible for future assessments, you could use the MOD function to check if the number of days between the initial assessment and the last review is a multiple of 90. If it is, the next review date would be 90 days after the last review. If not, you could add the remainder of days to 90 to get the next review date.
Here's an example of what that formula might look like:
=IF(B1="",A1+90,B1+90-MOD(B1-A1,90))
This formula checks if the last review is empty, if yes it returns the date of initial assessment plus 90 days, otherwise it returns the date of last review plus 90 days minus the remainder when last review date minus initial assessment date is divided by 90. This way, it will always give you the next review date after 90 days of the last review date, regardless of how many days past the last review date is.

How do I automatically append a value to an array at the end of each day?

I am working on a calorie tracking app where the user inputs values to keep a running calorie total throughout the day. I would like to automatically append this daily value to an array at the end of each day so I can present running averages for the last seven days, fourteen days, and thirty days from the array data.
This seems like a straightforward enough issue, but I've been having trouble finding an answer or relevant example on here or googling in general. Thanks in advance for any assistance or relevant links.
Don't append the value at the end of the day, append it the first time someone performs an action on the next day. You can use Date() to work out what day it is. If the day has changed since the last input then append the previous totals to the array.

iOS / Swift - Limiting access to view controllers to once per day

I am fairly new to swift development but i would like to implement limiting access to specified view controllers to once per day, ideally 3am this would reset but 12am is also fine.
How could I implement this?
Thanks in advance for any help.
When you visit the view controller, save the current date to user defaults.
Next time the user clicks a button to get to the view controller, read the saved date. If there is no saved date, or the difference between the saved date and the current date is > 24 hours, allow it.
If the difference is < 12 hours, you need to check to see if the date has changed (for midnight) or if 3 am is between those 2 dates.
To see if the 2 saved Dates are on different days, use the Calendar function isDate(_:inSameDayAs:)
To see if 3 AM has passed since the last time is more complicated. Off the top of my head, I'd probably take the current Date, Date(), and use the function
date(bySettingHour:minute:second:of,matchingPolicy:repeatedTimePolicy: direction:) to create a date for 3 AM today, if it has already passed, and then see if 3AM today is between my saved date and now.

How to Link custom week numbers with an existing time tree graph up to minutes in Neo4J?

I already have a graph (time tree) that contains Year, Month, Day, Hour and Minutes. It is something like that of what Mark Needham shows in his blog link but it goes until Minutes instead of days. So the link looks something like this :
2017-[:HAS_MONTH]-2-[:HAS_DAY]-25-[:HAS_HOUR]-16-[:HAS_MINUTE]-45
I also have Year to week number relation. The starting and ending dates of the Workweek are custom. For eg my week 2 in 2017 starts from 2017-01-05 19:00 (yyyy-mm-dd hh:mm) and ends on 2017-01-12 18:59. I have all the nodes between those 2 dates in my time tree but I am not able link them to week 2 node. Is there a way to do this? I am not using graphaware. I managed to do something for this one week by collecting all the days from 5th to 12th and then removing the hours 0 to 18 from 5th and 20th to 23rd on 12. But I need to do this for a couple of years and this method may be very cumbersome. Is there a better way for this?
You can use apoc plugin already :)
apoc.date.format uses JAVA simpledateformat under the hood I think. Looking at http://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html this is already possible. But you have to first parse it into unix and then back.
with "2017-01-05 19:00" as date
with apoc.date.parse(date,"s","yyyy-MM-dd HH:mm") as unix
return apoc.date.format(unix,"s","yyyy ww")

how to find number of working days for particular month in rails

I am having problem in calculating number of working days for particular month. I have attendance model.which contains, school_id,course_id,section_id,student_id,attendance_date attributes.These fields for making attendance for particular section in particular school
For viewing attendance report, I have school,course,section and month fields.when I select the month it will show the number of working days for that particular month.So, I have to calculate working days by attendance_date field from attendance model. I am having confusion in that. Please help me.
You might want to take a look at business_time
Example:
4.business_days.from_now
8.business_days.after(some_date)

Resources