Check if date range is within another date range for fullcalendar.io display
I'm implementing the server side code to fetch events for fullcalendar.io.
There are two scenarios:
- Event has a start and end date
- Event has a start date, and it's set to all day
Model:
public Class CalendarEvent {
public DateTimeOffset Start { get; set; }
public DateTimeOffset? End { get; set; }
public bool AllDay { get; set; }
}
When https://fullcalendar.io loads a view, it emits a date range, which is basically the days that can be seen on the calendar (i.e. 10/8/18 to 12/8/18) and I send that to my controller to fetch relevant events for that range.
I basically need to check the following:
- Does any part of the event's date range fall within the visible range emitted from the calendar - if so, show it.
- If it's an AllDay event, does the start date fall within the view.
Pseudo Example:
var rep = context.GetRepository<Event>();
events = rep.Get().Where(e => /* need help here */).AsQueryable();
c# linq fullcalendar
add a comment |
I'm implementing the server side code to fetch events for fullcalendar.io.
There are two scenarios:
- Event has a start and end date
- Event has a start date, and it's set to all day
Model:
public Class CalendarEvent {
public DateTimeOffset Start { get; set; }
public DateTimeOffset? End { get; set; }
public bool AllDay { get; set; }
}
When https://fullcalendar.io loads a view, it emits a date range, which is basically the days that can be seen on the calendar (i.e. 10/8/18 to 12/8/18) and I send that to my controller to fetch relevant events for that range.
I basically need to check the following:
- Does any part of the event's date range fall within the visible range emitted from the calendar - if so, show it.
- If it's an AllDay event, does the start date fall within the view.
Pseudo Example:
var rep = context.GetRepository<Event>();
events = rep.Get().Where(e => /* need help here */).AsQueryable();
c# linq fullcalendar
I would changeAllDay
as read-only and the get method asreturn End == null
. It kinda simplifies it and you don't need to assign it every time you create one. Assuming you have control over it
– sertsedat
Nov 23 '18 at 22:35
@sertsedat good call
– user1447679
Nov 23 '18 at 22:37
add a comment |
I'm implementing the server side code to fetch events for fullcalendar.io.
There are two scenarios:
- Event has a start and end date
- Event has a start date, and it's set to all day
Model:
public Class CalendarEvent {
public DateTimeOffset Start { get; set; }
public DateTimeOffset? End { get; set; }
public bool AllDay { get; set; }
}
When https://fullcalendar.io loads a view, it emits a date range, which is basically the days that can be seen on the calendar (i.e. 10/8/18 to 12/8/18) and I send that to my controller to fetch relevant events for that range.
I basically need to check the following:
- Does any part of the event's date range fall within the visible range emitted from the calendar - if so, show it.
- If it's an AllDay event, does the start date fall within the view.
Pseudo Example:
var rep = context.GetRepository<Event>();
events = rep.Get().Where(e => /* need help here */).AsQueryable();
c# linq fullcalendar
I'm implementing the server side code to fetch events for fullcalendar.io.
There are two scenarios:
- Event has a start and end date
- Event has a start date, and it's set to all day
Model:
public Class CalendarEvent {
public DateTimeOffset Start { get; set; }
public DateTimeOffset? End { get; set; }
public bool AllDay { get; set; }
}
When https://fullcalendar.io loads a view, it emits a date range, which is basically the days that can be seen on the calendar (i.e. 10/8/18 to 12/8/18) and I send that to my controller to fetch relevant events for that range.
I basically need to check the following:
- Does any part of the event's date range fall within the visible range emitted from the calendar - if so, show it.
- If it's an AllDay event, does the start date fall within the view.
Pseudo Example:
var rep = context.GetRepository<Event>();
events = rep.Get().Where(e => /* need help here */).AsQueryable();
c# linq fullcalendar
c# linq fullcalendar
asked Nov 23 '18 at 22:05
user1447679user1447679
1,31151746
1,31151746
I would changeAllDay
as read-only and the get method asreturn End == null
. It kinda simplifies it and you don't need to assign it every time you create one. Assuming you have control over it
– sertsedat
Nov 23 '18 at 22:35
@sertsedat good call
– user1447679
Nov 23 '18 at 22:37
add a comment |
I would changeAllDay
as read-only and the get method asreturn End == null
. It kinda simplifies it and you don't need to assign it every time you create one. Assuming you have control over it
– sertsedat
Nov 23 '18 at 22:35
@sertsedat good call
– user1447679
Nov 23 '18 at 22:37
I would change
AllDay
as read-only and the get method as return End == null
. It kinda simplifies it and you don't need to assign it every time you create one. Assuming you have control over it– sertsedat
Nov 23 '18 at 22:35
I would change
AllDay
as read-only and the get method as return End == null
. It kinda simplifies it and you don't need to assign it every time you create one. Assuming you have control over it– sertsedat
Nov 23 '18 at 22:35
@sertsedat good call
– user1447679
Nov 23 '18 at 22:37
@sertsedat good call
– user1447679
Nov 23 '18 at 22:37
add a comment |
1 Answer
1
active
oldest
votes
I like this one (overlapping dates)! In general the formula is:
var dateFrom = ;// start of week
var dateTo = ; // end of week
var events = rep.Get()
.Where(e => e.Start <= dateTo && e.End >= dateFrom)
.AsQueryable();
Because you need things contained by the range, starting in the range and extending out, starting before the range and ending in, and starting before and ending after the range.
But if you need to handle a nullable
.End
then maybe more like:
var dateFrom = ;// start of week
var dateTo = ; // end of week
var events = rep.Get()
.Where(e => e.Start <= dateTo && (e.End ?? e.Start) >= dateFrom)
.AsQueryable();
(very) rudimentary mockup to help visualize:
2
You can simplify the null case - and hence all cases - down to.Where(e => e.Start <= dateTo && (e.End ?? e.Start) >= dateFrom)
– sellotape
Nov 23 '18 at 22:29
Props for the drawing :)
– user1447679
Nov 23 '18 at 22:41
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53453381%2fcheck-if-date-range-is-within-another-date-range-for-fullcalendar-io-display%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I like this one (overlapping dates)! In general the formula is:
var dateFrom = ;// start of week
var dateTo = ; // end of week
var events = rep.Get()
.Where(e => e.Start <= dateTo && e.End >= dateFrom)
.AsQueryable();
Because you need things contained by the range, starting in the range and extending out, starting before the range and ending in, and starting before and ending after the range.
But if you need to handle a nullable
.End
then maybe more like:
var dateFrom = ;// start of week
var dateTo = ; // end of week
var events = rep.Get()
.Where(e => e.Start <= dateTo && (e.End ?? e.Start) >= dateFrom)
.AsQueryable();
(very) rudimentary mockup to help visualize:
2
You can simplify the null case - and hence all cases - down to.Where(e => e.Start <= dateTo && (e.End ?? e.Start) >= dateFrom)
– sellotape
Nov 23 '18 at 22:29
Props for the drawing :)
– user1447679
Nov 23 '18 at 22:41
add a comment |
I like this one (overlapping dates)! In general the formula is:
var dateFrom = ;// start of week
var dateTo = ; // end of week
var events = rep.Get()
.Where(e => e.Start <= dateTo && e.End >= dateFrom)
.AsQueryable();
Because you need things contained by the range, starting in the range and extending out, starting before the range and ending in, and starting before and ending after the range.
But if you need to handle a nullable
.End
then maybe more like:
var dateFrom = ;// start of week
var dateTo = ; // end of week
var events = rep.Get()
.Where(e => e.Start <= dateTo && (e.End ?? e.Start) >= dateFrom)
.AsQueryable();
(very) rudimentary mockup to help visualize:
2
You can simplify the null case - and hence all cases - down to.Where(e => e.Start <= dateTo && (e.End ?? e.Start) >= dateFrom)
– sellotape
Nov 23 '18 at 22:29
Props for the drawing :)
– user1447679
Nov 23 '18 at 22:41
add a comment |
I like this one (overlapping dates)! In general the formula is:
var dateFrom = ;// start of week
var dateTo = ; // end of week
var events = rep.Get()
.Where(e => e.Start <= dateTo && e.End >= dateFrom)
.AsQueryable();
Because you need things contained by the range, starting in the range and extending out, starting before the range and ending in, and starting before and ending after the range.
But if you need to handle a nullable
.End
then maybe more like:
var dateFrom = ;// start of week
var dateTo = ; // end of week
var events = rep.Get()
.Where(e => e.Start <= dateTo && (e.End ?? e.Start) >= dateFrom)
.AsQueryable();
(very) rudimentary mockup to help visualize:
I like this one (overlapping dates)! In general the formula is:
var dateFrom = ;// start of week
var dateTo = ; // end of week
var events = rep.Get()
.Where(e => e.Start <= dateTo && e.End >= dateFrom)
.AsQueryable();
Because you need things contained by the range, starting in the range and extending out, starting before the range and ending in, and starting before and ending after the range.
But if you need to handle a nullable
.End
then maybe more like:
var dateFrom = ;// start of week
var dateTo = ; // end of week
var events = rep.Get()
.Where(e => e.Start <= dateTo && (e.End ?? e.Start) >= dateFrom)
.AsQueryable();
(very) rudimentary mockup to help visualize:
edited Nov 23 '18 at 22:31
answered Nov 23 '18 at 22:19
JonathanJonathan
2,70921630
2,70921630
2
You can simplify the null case - and hence all cases - down to.Where(e => e.Start <= dateTo && (e.End ?? e.Start) >= dateFrom)
– sellotape
Nov 23 '18 at 22:29
Props for the drawing :)
– user1447679
Nov 23 '18 at 22:41
add a comment |
2
You can simplify the null case - and hence all cases - down to.Where(e => e.Start <= dateTo && (e.End ?? e.Start) >= dateFrom)
– sellotape
Nov 23 '18 at 22:29
Props for the drawing :)
– user1447679
Nov 23 '18 at 22:41
2
2
You can simplify the null case - and hence all cases - down to
.Where(e => e.Start <= dateTo && (e.End ?? e.Start) >= dateFrom)
– sellotape
Nov 23 '18 at 22:29
You can simplify the null case - and hence all cases - down to
.Where(e => e.Start <= dateTo && (e.End ?? e.Start) >= dateFrom)
– sellotape
Nov 23 '18 at 22:29
Props for the drawing :)
– user1447679
Nov 23 '18 at 22:41
Props for the drawing :)
– user1447679
Nov 23 '18 at 22:41
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53453381%2fcheck-if-date-range-is-within-another-date-range-for-fullcalendar-io-display%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
I would change
AllDay
as read-only and the get method asreturn End == null
. It kinda simplifies it and you don't need to assign it every time you create one. Assuming you have control over it– sertsedat
Nov 23 '18 at 22:35
@sertsedat good call
– user1447679
Nov 23 '18 at 22:37