Get Google Calendar events that start and end between two dates - google-api

As show in the picture I want to get all events that are in the range (start and end) of my 'My Free Time' event.
In this case there are three events that meet the requirements ('Learning for Exam', 'Homework', 'Coffee').
The 'Running' event start time is out of range of start-end time of 'My Free Time' event.
The 'Cycling' event end time is out of range of start-end time of 'My Free Time' event.
I am using Google Calendar API v3.
I saw the 'timeMax' and 'timeMin' parameters in Google Calendar API Reference:
timeMax - Upper bound (exclusive) for an event's start time to filter by.
timeMin - Lower bound (inclusive) for an event's end time to filter by.
I make the following call:
$optParams = array(
'maxResults' => 10,
'orderBy' => 'startTime',
'singleEvents' => TRUE,
'timeMin' => '2018-11-27T07:30:00+01:00',
'timeMax' => '2018-11-27T17:30:00+01:00',
);
Where timeMin is set to 'My Free Time' event startTime & timeMax is set to 'My Free Time' event endTime.
But in the result there are all the events ('Running', 'Learning for Exam', 'Homework', 'Coffee', 'Cycling'), instead of only 3 events 'Learning for Exam', 'Homework' and 'Coffee'.
The question is: how the timeMin & timeMax parameters should be set to obtain only the 'Learning for Exam' event ?
The following question is similar:
Google Calendar Api get events on current week
but the answers don't fulfill my requirements. My requirements are:
- NOT get the events which start time is BEFORE start-time of the range and the end time is in the range i.e. BEFORE end-time of the range (ex. 'Running' event)
- NOT get the events which end time is AFTER end-time of the range and the start time is in the range i.e. AFTER start-time of the range (ex. 'Cycling' event)

timeMin--> 2018-11-27T10:30:00+01:00
timeMax--> 2018-11-27T15:30:00+01:00

It seems that if you specify the 'timeMin' and 'timeMax' parameters, you will get the events which meets the following condition:
'timeMin' <= 'event end time' < 'timeMax'
In order to get the events that starts and also ends between 'timeMin' and 'timeMax' (as you need), you will have to filter out the returned events which meets the following condition:
'event start time' < 'timeMin'

Related

Restrict Function Not Working Properly with Recurring Items

It seems that the Restrict function is not working properly with Calendar items. Specifically, when a filter is passed to return calendar items within a specified time, then recurring meetings are returned do not occur between the times specified in the filter.
Problem can be reproduced as follows:
Calendar = outlook_mapi.GetDefaultFolder(OlDefaultFolders.olFolderCalendar)
all_messages = calendar.Items
all_messages.IncludeRecurrences = True
all_messages = all_messages.Restrict(f"[Start] >= '{date_str} 12:00AM' And [Start] <= '{date_str} 11:59PM'")
where date_str =f"{month}/{day}/{year}" and month/day/year is the particular date that we want to read the calendar
This then returns all recurring meetings in a user's calendar, irrespective of whether they occur on the specified time above or not.

Find overlapping ranges in Algolia?

How would you search Algolia for overlapping numerical ranges?
For example (my use case), I'm working with events on a calendar. Each event has a date and and endDate and I'm trying to find all events that fall in a month. Right now I'm searching using 'numericFilters` like this:
{
...
"facetFilters":"...",
"numericFilters":"[[
\"date:1517472000000 TO 1524985199999\",
\"endDate:1517472000000 TO 1524985199999\"
]]"
}
This gives me all events that begin or end during a month. But what about events that start last month, and end next month. How do I search for those?
Not sure how you would do this with elasticsearch, however with Algolia this is the right approach. Removing the filtering on date, you could get all events that started anytime and end in this month:
"numericFilters":"[[
\"endDate:1517472000000 TO 1524985199999\"
]]"
But if you want all events that are happening during a month, so that started before or during that month and end during or after it, you would filter to remove those that start after the end of the month and those that end before the begin of the month:
"filters":"date < 1524985199999 AND endDate > 1517472000000"

Calculating the time duration of a particular Log event using Logstash

Objective : I want to to calculate the time duration on how long a particualr event has lasted using logstash.
Scenario : Consider a customer Who is searching for a product to purchase from my page. Each and every page he is visiting has been recorded in the log along with time duration. Now I want to find how long an Average customer is taking to get a product. and how long my server is taking time to respond him back.
Now here is my Log file:
16-09-2004 00:37:22 BEGIN_CUST
ts:16-09-2004T00:37:26+05:30
ID-XYZ456
16-09-2004 00:37:23 PAGE_1
ID-XYZ456
ts:16-09-2004T00:39:26+05:30
16-09-2004 00:37:23 PAGE_2
ID-XYZ456
ts:16-09-2004T00:41:26+05:30
16-09-2004 00:37:23 BUT_REQ
ID-XYZ456
ts:16-09-2004T00:43:26+05:30
16-09-2004 00:37:23 PURCHASE
ID-XYZ456
ts:16-09-2004T00:47:26+05:30
16-09-2004 00:51:22 BEGIN_CUST
ts:16-09-2004T00:52:26+05:30
ID-YUB98I
16-09-2004 00:53:23 PAGE_1
ID-YUB98I
16-09-2004 00:55:23 PURCHASE
ID-YUB98I
In the above log file, It is clear that BEGIN_CUST is the beginning of the event and PURCHASE is the end of an event.
ID (plays as a unique ID for each customer).
I have tried Scripted fields. but it is not yielding me proper results due to the following points,
It is not necessary that a customer needs to purchase it.
Customer Purchase may last even in Seconds.
Is there any way better to plot the duration of an Individual Customer in a separate field in Kibana to visualize it using Logstash.
Thanks in Advance.
So long as you're using ElasticSearch as your store, the elasticsearch filter may do what you need. The trick is to search for the BEGIN_CUST event as soon as you get a PURCHASE event. The documentation for this plugin includes and example that does much of what you're looking for, but here is a summary:
if [trans_type] == "PURCHASE" {
elasticsearch {
hosts => localhost,
query => "trans_type:BEGIN_CUST AND cust_id:%{[cust_id]}],
fields => { "#timestamp" => "started" }
}
date {
match => [ "[started]", "ISO8601" ]
target => "[started]"
}
ruby {
code => "event['shopping_time'] = (event['#timestamp'] - event['started'] rescue nil"
}
}
Which will yield a shopping_time field measured in seconds between when the BEGIN_CUST record arrived and when the first PURCHASE arrived. If a customer purchases twice, then each PURCHASE record will have its own shopping_time field based on the same BEGIN_CUST.
This works by querying ElasticSearch for the BEGIN_CUST record, and using the #timestamp data on that record in the PURCHASE record's started field. The date {} filter then turns that into a datetime data-type. Finally, the ruby {} block computes the difference in time between the current #timestamp field and the one pulled out of ElasticSearch, creating the shopping_time field.

Send Reminder via outlook

We have a set of processes that need to be performed. Some are done daily, some weekly and some monthly. There is a deadline set up for each process before which it should be completed. We need to send a reminder to the team in the following way.
If the process runs daily and needs to be completed before a particular time, then a reminder should be sent 2 hours before that
If it runs weekly on a particular day then a reminder should be sent at 10AM IST of that particular day
If the process runs monthly and needs to be completed before a particular day, then a reminder should be sent just a day before the end date.
How can I create a VB script for the above task?
The Reminder class doesn't provide any property or method for changing the time. But you may create an appointment item on your calendar for each event (it can be a recurrent item) and set the reminder for the item. The ReminderMinutesBeforeStart property of the AppointmentItem class returns an integer indicating the number of minutes the reminder should occur prior to the start of the appointment. The ReminderSet property allows to set a Boolean value that is True if a reminder has been set for this item. For example:
Sub AddAppointment()
Dim apti As Outlook.AppointmentItem
Set apti = Application.CreateItem(olAppointmentItem)
apti.Subject = "Car Servicing"
apti.Start = DateAdd("n", 16, Now)
apti.End = DateAdd("n", 60, apti.Start)
apti.ReminderSet = True
apti.ReminderMinutesBeforeStart = 60
apti.Save
End Sub

Determine the amount of clicks required to reach a specific date using a JQuery calendar?

I have a jquery calendar for the start date of a project.
Using Watir (automated browser driver, a gem for ruby), I have a set date that I would like to enter in.
The calendar start date is always today's date, whatever that may be for the day it is used. I was wondering if there was a way that ruby can process what today's date is, and use the specified date provided by the user, to calculate the difference of months between them.
Here is an example of the Calendar plugin: http://jqueryui.com/datepicker/
example:
today's date is 30/10/2012, if there was a project that were to start on the 20/12/2012, that would be 2 months from now, so 2 clicks on the next month button.
Is there a way I could do this?
Here is how I approached a similar situation with JSdatepicker:
$today = Time.now.strftime("%e").gsub(" ", "") #one digit day of month without leading space
#browser.text_field(:id => /dateAvailable/).click
Watir::Wait.until(60) {#browser.div(:id => /dateAvailable_popup_cal/).td(:text => $today).exists?}
#browser.div(:id => /dateAvailable_popup_cal/).td(:text => $today).click
Set or grab the date.
Click the text_field that fires the JSDatePicker object
Wait until the calendar actually pops up
The current month is shown, so choose today's date number.
In your case, you also need to set the month. Whether prompting the user for this, or choosing "today", the theory is the same:
$month = Date::MONTHNAMES[Date.today.month] #etc
Pseudo-code making lots of assumptions (only future dates, month name shown on calendar as text, etc):
while !#jquerytablewindow.text.include?($month)
next_month_button.click
end
I don't see a specific advantage to my method versus counting each month, unless of course we add a month to the calendar one day and you still want your code to work!
You could do:
#End date converted to date object
specified_date = '20/12/2012'
end_date = Date.parse(specified_date)
#Start date (today - 30/10/2012)
today = Date.today
#Determine difference in months
number_of_months_up_to_today = (today.month + today.year * 12)
number_of_months_up_to_end = (end_date.month + end_date.year * 12)
clicks_required = number_of_months_up_to_end - number_of_months_up_to_today
#=> 2
Basically it is counting the number of months since the year 0 and then finding the difference.

Resources