How to check if event's date is within a date range? - ruby

I have events (from an Event model) that have a starts_at: value in the form of a datetime. e.g.:
2016-02-18 11:00:00:00000
What I want to be able to do is check whether an event is starting this week.
I want to be able to make a list of events that are occuring this week (starting from the latest Monday).
#events = #calendar.events.where( ... )
I thought something along the lines of this:
start_week = Date.today.beginning_of_week(:monday).day()
end_week = Date.today.beginning_of_week(:monday).day()+6
range = start_week..end_week
#events = #calendar.events.where(starts_at: in range)
But it doesn't take into account the month or year. Also I'm not sure how to write the 'where' clause. How should I go about doing this? Thanks

Try this:
start_week = Date.today.beginning_of_week(:monday)
end_week = Date.today.beginning_of_week(:monday)+6
range = start_week..end_week
#events = #calendar.events.where(starts_at: range)

Assuming you want all the events from the current week, something like this should work:
#events = #calendar.events.where(starts_at: Time.zone.today.all_week)
all_week returns a Date range covering the current week.

Related

var with fixed value that doesnt change with slicer dax

I have a date table which I use as a slicer. I want date1 to get the minimum date from that range. I then use that date to calculate the number of new user from KPI_summary table andIi want this to be a fixed unchanging value which is returned as newUsers.
However when I plot this with dates the values change. am I missing something? pls see codes below
NewUsers =
var date1 = MIN('Date Table'[Date]) -- get the first date from the slicer
var newUsers = calculate(sum(KPI_SUMMARY[NEW_USERS]), KPI_SUMMARY[JOIN_DATE] = date1) --get the new users from the first date
return
newUsers -- I want to always return the newUsers from the first date of the slicer. it shouldnt change
Try something like this:
NewUsers =
-- get the first date from the slicer
var _date1 =
CALCULATE(
MIN('Date Table'[Date]),
ALLSELECTED('Date Table')
)
var _newUsers =
calculate(
sum(KPI_SUMMARY[NEW_USERS]),
KPI_SUMMARY[JOIN_DATE] = _date1
) --get the new users from the first date
return
_newUsers -- i want to always return the newUsers from the first date of the slicer. it shouldnt change
I used ALLSELECTED() function inside CALCULATE() function to change _date1 variable calculation context.
Also, as you can see, I would advice you to name your variables with "_" prefix. It's much easier to recognize them then.

Date range comparison in CQ using XPATH

I'm using the following query to get nodes based on last modified date in CQ.
/jcr:root/content/scaffoldes/properties//*[#jcr:primaryType = 'nt:unstructured' and (#sling:resourceType = 'acme/components/content/scaffoldItem' or #sling:resourceType = 'acme-core/components/data/property') and #jcr:content/cq:lastModified >= xs:dateTime('2000-01-01T00:00:00.000-08:00') and #jcr:content/cq:lastModified < xs:dateTime('2014-12-31T00:00:00.000-08:00') and not(#isHidden)] order by #jcr:score
we have used
http://localhost:4502/crx/explorer/ui/search.jsp
To test this query. But, even after giving a huge date range (2000 - 2016) this query is returning nothing.
But If we remove the date range part, this query returns nodes.
Any pointer to correct this would be helpful.
Thanks and Regards,
San
Notes
The date string is create with the following code:
Calendar cal = Calendar.getInstance();
cal.setTime(start);
String startDate = ValueFactoryImpl.getInstance().createValue(cal).getString();
Sorry for any confusion caused. I found that the node which I'm trying to query doesn't have a cq:lastModified property. So modified the query to include the cq:lastReplicated in the condition.
... and ((#jcr:content/cq:lastModified >= xs:dateTime('2000-01-01T00:00:00.000-08:00') and #jcr:content/cq:lastModified < xs:dateTime('2016-02-11T15:52:57.090-08:00')) or (#jcr:content/cq:lastReplicated >= xs:dateTime('2000-01-01T00:00:00.000-08:00') and #jcr:content/cq:lastReplicated < xs:dateTime('2016-02-11T15:52:57.090-08:00'))) and ...

Office 365 dll querying Calendarview doesn't support StartDateTime or EndDateTime

Similar to this question
When querying CalendarView, it doesn't seem to support Start and End ( so they don't get translated into the correct values).
My code returns an error because i didn't include the parameters.
Is there any way to add these parameters through the OutlookServicesClient?
My current code looks like this:
Dim calendarView = exClient.Me.CalendarView
' For Each Attendee In AttendeesFilter.Split(New Char() {Char.Parse(";")}, StringSplitOptions.RemoveEmptyEntries)
' calendarView.Where(Function(dl) dl.Attendees.Any(Function(el) el.EmailAddress.Equals(Attendee)))
' Next 'Office365 doesnt seem to filter on attendees
startDate = DateTime.Now.AddMonths(-1)
endDateTime = DateTime.Now
If startDate.HasValue AndAlso endDateTime.HasValue Then
calendarView.Where(Function(dl) dl.Start.Value <= startDate.Value AndAlso dl.End.Value <= endDateTime.Value) 'doesnt seem to filter on dates
End If
The exact error i receive is :
Type: Microsoft.OData.Core.ODataErrorException
Message: This request requires a time window specified by the query string parameters startDateTime and endDateTime.
Although i can't seem to find a proper way on how to add the time window :s
There is a function:
exClient.Me.Calendar.GetCalendarView(startDateOffset, endDateOffset)
This filters between start and endDate instead of adding it to the Query
You can get a CalendarView as follows:
var eventResults = await exClient.Me.Calendar
.GetCalendarView(startDateTime,endDateTime)
.Take(10)
.ExecuteAsync();

How do I iterate through each date between two defined dates in ruby?

I have two dates, the begins_at (datetime) and the ends_at (datetime). I now simply want to iterate through every date between these two (including the ends_ and begins_at dates).
begins_at = Date.strptime("12/10/2014", "%m/%d/%Y")
ends_at = Date.strptime("12/20/2014", "%m/%d/%Y")
//iterate through all dates in this range kind of like this:
range = DateRange(begins-at,ends-at)
range.DateTime.each do |date|
....
end
Does anyone have an idea how I could achieve this?
You should use Range:
(begins_at..ends_at).each do |date|
# ...
end

How to show reminder by month for Windows phone

How to show reminder by month?
I have created this partial code and I am stucked how to manipulate to check and get reminder by month.
reminders = ScheduledActionService.GetActions<Reminder>();
if (reminders.Count<Reminder>() > 0)
{
}
else
{
}
If there is reminder I want to check the month and get the month i want.
try this one:
var month = 5; // your month
var remindersOfMonth = ScheduledActionService.GetActions<ScheduledAction>()
.Where(a=> a.BeginTime.Month == month);
According to this when you use GetActions() it will return you a list of
ScheduledAction. Now according to this ScheduledAction has a property called BeginTime which is of type DateTime so it has Month property which is your interest.
variable "a" in the statement is in fact each of ScheduledAction in the collection which are begin evaluated again the month.

Resources