Check if date range is within another date range for fullcalendar.io display












2















I'm implementing the server side code to fetch events for fullcalendar.io.



There are two scenarios:




  1. Event has a start and end date

  2. 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:




  1. Does any part of the event's date range fall within the visible range emitted from the calendar - if so, show it.

  2. 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();









share|improve this question























  • 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
















2















I'm implementing the server side code to fetch events for fullcalendar.io.



There are two scenarios:




  1. Event has a start and end date

  2. 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:




  1. Does any part of the event's date range fall within the visible range emitted from the calendar - if so, show it.

  2. 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();









share|improve this question























  • 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














2












2








2








I'm implementing the server side code to fetch events for fullcalendar.io.



There are two scenarios:




  1. Event has a start and end date

  2. 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:




  1. Does any part of the event's date range fall within the visible range emitted from the calendar - if so, show it.

  2. 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();









share|improve this question














I'm implementing the server side code to fetch events for fullcalendar.io.



There are two scenarios:




  1. Event has a start and end date

  2. 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:




  1. Does any part of the event's date range fall within the visible range emitted from the calendar - if so, show it.

  2. 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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 23 '18 at 22:05









user1447679user1447679

1,31151746




1,31151746













  • 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



















  • 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

















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












1 Answer
1






active

oldest

votes


















2














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:



Rudimentary mockup






share|improve this answer





















  • 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











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
});


}
});














draft saved

draft discarded


















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









2














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:



Rudimentary mockup






share|improve this answer





















  • 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














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:



Rudimentary mockup






share|improve this answer





















  • 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








2







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:



Rudimentary mockup






share|improve this answer















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:



Rudimentary mockup







share|improve this answer














share|improve this answer



share|improve this answer








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














  • 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




















draft saved

draft discarded




















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

404 Error Contact Form 7 ajax form submitting

How to know if a Active Directory user can login interactively

TypeError: fit_transform() missing 1 required positional argument: 'X'