mardi 12 juillet 2022

c# Split Time Period based on the Shift Time Period

My Payroll App is working with a Class PayrollLineItems and SpecialShifts

public class PayrollLineitems
{
   public int PayrollLineItemID {get;set;} // eg : 1
   public DateTime ScheduleDate {get;set;} // eg : 01-01-2022
   public DateTime StartTime    {get;set;} // eg : 01-01-2022 10:00 
   public DateTime EndTime     {get;set}  // eg :  01-01-2022 18:00
}

public class SpecialShifts
{
  public TimeSpan Start { get; set; } //e.g. 08:00
  public TimeSpan End { get; set; } //e.g. 17:00
  public string Days { get;set; } //e.g. 6,7 => 6-> Saturday, 7 -> Sunday
}

I want to split the Payroll Line Item records as per the Special Shifts.

For eg : Below are the details of PayrollLineItem class

ScheduleDate StartTime EndTime
01-01-2022 01-01-2022 10:00 01-01-2022 18:00
01-02-2022 01-02-2022 19:00 01-02-2022 21:00

Below are the details of SpecialShifts

Start End Days
16:00 17:00 5,6
15:00 20:00 1,7

if PayrollLineItems record matches the ScheduleDate,Day of Week and Start Time.

Result

ScheduleDate StartTime EndTime
01-01-2022 01-01-2022 10:00 01-01-2022 16:00
01-01-2022 01-01-2022 16:00 01-01-2022 17:00
01-01-2022 01-01-2022 17:00 01-01-2022 18:00
01-02-2022 01-02-2022 19:00 01-02-2022 20:00
01-02-2022 01-02-2022 20:00 01-02-2022 21:00

I tried TimePeriod library but it didn't work. is there any design pattern to handle the above Problem?

Any help is much appreciated.

Aucun commentaire:

Enregistrer un commentaire