C
C#2y ago
Ami2

❔ Calculating reading duration percentages for different time periods

I'm working on a project where I need to calculate the reading duration percentages for different time periods based on user reading data. The time periods include dawn, night, evening, morning, and afternoon. I have the start and end times for each reading session, and I want to determine the percentage of reading time spent in each period. I've already defined the time ranges for each period (e.g., dawn from 4:30am to 5:30am, night from 9pm onwards), and I need help with the logic to calculate the percentages. Additionally, there are cases where a reading session may span multiple periods (e.g., morning and afternoon). I'm using .NET 6 linq, and any guidance or code snippets on how to approach this calculation would be greatly appreciated.
var downStart = new TimeSpan(4, 30, 0); //4:30am
var morningStart = new TimeSpan(5, 30, 0); // 5:30am
var afternoonStart = new TimeSpan(12, 0, 0); // 12pm
var eveningStart = new TimeSpan(16, 0, 0); // 4pm
var nightStart = new TimeSpan(19, 0, 0); // 9pm
var downStart = new TimeSpan(4, 30, 0); //4:30am
var morningStart = new TimeSpan(5, 30, 0); // 5:30am
var afternoonStart = new TimeSpan(12, 0, 0); // 12pm
var eveningStart = new TimeSpan(16, 0, 0); // 4pm
var nightStart = new TimeSpan(19, 0, 0); // 9pm
public class ReadingSession
{
public DateTime StartAt {get;set;}
public DateTime EndAt {get;set;}
}
public class ReadingSession
{
public DateTime StartAt {get;set;}
public DateTime EndAt {get;set;}
}
2 Replies
JakenVeina
JakenVeina2y ago
is this for homework or something?
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server