Goal: Based on todays date and month, get actual and the next two days values from XML.
Issue: Although my c.Attribute(\"Day\").Value changes, my c.Attribute(\"Month\").
I would suggest you change your "model" class to use DateTime
instead of string
for the date. Transform all the elements into your model class, and then filter. It'll be a lot simpler than trying to do arithmetic based on the attributes.
Also note that using the explicit conversions from XAttribute
is simpler than calling int.Parse
everywhere. I would actually suggest creating a static FromXElement
method in your model class, so you can write:
DateTime start = DateTime.Today;
// We'll use this as an *exclusive* upper bound
DateTime end = start.AddDays(3);
var query = from c in loadedCustomData.Descendants("PrayerTime")
let bonn = Bønn.FromXElement(c)
where bonn.Dato >= start && bonn.Dato < end;
select bonn;
Or in extension method syntax:
// start and end as before
var query = loadedCustomData.Descendants("PrayerTime")
.Select(c => Bønn.FromXElement(c))
.Where(bonn => bonn.Dato >= start && bonn.Dato < end);