Finding schedule overlaps with Ruby & Runt? - ruby-on-rails

I'm using Ruby on Rails to build a simple application to keep track of a shop's opening and closing times and its appointments, and I'm having some trouble validating the appointments against closings in the shop's schedule.
I've been using Runt to compose the schedule. For example, if the shop is open Monday morning from 9am-12pm closed for an hour for lunch and then open in the afternoon until 5pm, it would look like:
require 'runt'
include Runt
monday = DIWeek.new(Mon)
morning = REDay.new(9,00,12,00)
afternoon = REDAy.new(13,00,17,00)
expr = monday & morning & afternoon
For a given appointment (also a Runt Temporal Expression), how can I make sure that the appointment does overlap with the opening times and does not overlap the lunch hour (or other times before or after the opening times)?
I gather that Runt has an overlaps? method, but if I do something like:
expr.overlaps?(DIWeek.new(Mon) & REDay.new(10,00,11,00)) # the appointment is from 10-11am on Monday and should overlap the morning opening time
I get this error:
NoMethodError: undefined method `overlaps?' for #<Runt::Intersect:0x10483cc>
Can anyone please advises me on how to correct this error or else another way to solve this problem?

The overlaps? method is defined only on Runt::Collection and Runt::DateRange. Perhaps you can create a DateRange object from your expr and then run overlap? on it.

Related

How can I select the data between some specific hours in a specific month?

I already have InfluxDB working and getting monitoring data about some services (the value is just 1 for up and 0 for down). For the management I need to select the values from the database that are in a specific month and either night time or day time. For example: I want to select all the data from April 2019 (doesn't matter if it 1 or 0) between 08:00AM and 07:00PM (day time)
Here is what I've tried:
SELECT value FROM probe_success
WHERE "instance" = 'https://myservice/api' AND time >= '08:00:00' AND time < '19:00:00'
AND time >= '2019-04-01' AND time <= '2019-04-30'
But I've got an error:
{"results":[{"statement_id":0,"error":"invalid operation: time and
*influxql.StringLiteral are not compatible"}]}
Can anyone tell me what I'm doing wrong or point me in the right direction?
Thank you very much!
Ok, so after some research I've found that it is not possible to use the "OR" statement in a "WHERE" clause to specify multiple time ranges. See this. I solved this problem by sending separate requests for each day in a for loop and then concatenate all the results. It's not the best solution, I admit, but since they say it's not possible I guess this is the workaround.

Microsoft Graph get calendar entries happening today (reaching over timeframe)

I'm currently struggeling with the Microsoft Graph REST-API.
What I'm trying to do is list todays events (happening between midnight and midnight). From the documentation, the filter function is very limited.
My current statement looks like this:
https://graph.microsoft.com/v1.0/me/events?$top=100&$select=*&$filter=start/DateTime ge '2017-10-31T00:00:00' AND end/DateTime le '2017-11-1T00:00:00'&$orderby=start/DateTime ASC
The interesting part is here $filter=start/DateTime ge '2017-10-31T00:00:00' AND end/DateTime le '2017-11-1T00:00:00' using the start and the end and checking if start >= TODAY AND end <= TODAY+1. That's all working great for dates that are shorter as 1 day.
My problem is now how to get events that last longer than one day e.g. start = YESTERDAY and end = NEXT WEEK. Which means the start date is before today and the end day is as well not included in this range.
How to get this events?
I believe you should be using Calendar View for your scenario:
https://developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/api/calendar_list_calendarview
The link that Yogesh referenced seems to be removed and not found. Here is the link that I used which shows how to use the calendar view. Hopefully this helps -- https://learn.microsoft.com/en-us/graph/api/calendar-list-calendarview?view=graph-rest-1.0&tabs=http

grails ORM , how to search Date without time

I am using postrges db.
My domain has a date field:
java.util.Date requestedDate;
I am trying to search by date in my controller:
eq ("requestedDate", requestedDate)
This works fine, but the problem is that date and time has to be exactly matching for this. But in application the user will only enter the date to search items (like give me all requests which are made on 2014-02-05 and the browser application will add the current time to the request). So the comparison fails because the user entered time is different from the time during creation of the request.
I tried 'like' but it throws error.
How to compare only date part ?
You could do something like this:
Date now = new Date()
now.clearTime()
def results = Meeting.withCriteria {
between('date', now, now+1)
}
So this strips off the time portion of the current date, and then does a 'between' query (between midnight just gone and midnight 24 hours later).
Still it looks like there is no convenient way to realize this.
You need a small detour by computing the start of the day and the end of the day and use the between operator.
EDIT
I just saw now rcgeorge23 gave you the right example for doing this.

Getting list of available dates from rental app

I am creating a ROR app for an e-commerce site which handles the management of renting items for a period of time. The items will be physically delivered and picked-up. Item are always rented for 30 days.
So the problem I am facing, is I need to somehow get which days an item can be rented and is available for at least 30 days from that point. (for example, a customer couldn't rent an item today if it is reserved to be rented 10 days from now)
In my database I have a rentals table that stores the pickup and delivery date.
I will be using a jQuery datepicker, and just need to load available dates 1 month at a time (I can redo the query each time the next month button is pressed to hide unavailable dates)
What would be the best approach to performing this type of query and getting all the days in a month in which an item is available for 30 days? I could always iterate through every single day in the month and check if there are any other records within 30 days, but that seems like a surplus of queries.
Any help would be greatly appreciated.
Thanks,
Tyler
How do you know the day an item is reserved to be picked up? Make a query based on that. Perhaps your Rental model has a reserved_on attribute?
class Rental < ActiveRecord::Base
scope :available, where('rented = ? AND reserved_on > ?', false, 30.days.from_now)
end
EDIT in response to comments
If are looking at a single object you could create methods on it something like this:
def last_available_day
delivery_date && delivery_date - rental_period # 30 days
end
def is_available_on?(date)
return true unless last_available_day
date <= last_available_day
end

Iterating the dates in ruby on rails

I am developing an application for reporting and analytic,where I need to generate data on a daily basis and put it in a CSV.To be more clear, if I take the report today like day one any how I can get the report thats already done, if I get the report tomorrow I should be able to get the data of today,yesterday. If i take after 4 days I should get the report starting from day 1 to day 4.
How it can be done. Looking for heads up
How about this:
today = Date.today
tomorrow = today.next
four_days_ago = 4.days.ago(today)
four_days_later = 4.days.since(today)
(today..(4.days.since(today)).each {|d| puts d}

Resources