C#C
C#3y ago
SWEETPONY

✅ How to break date into intervals?

I have this:
/// <summary>
/// List of intervals inside worktime
/// </summary>
[JsonProperty( PropertyName = "schedule_intervals" )]
 public List<WorktimeScheduleInterval> ScheduleIntervals { get; set; }

public class WorktimeScheduleInterval
{
    /// <summary>
    /// Shift of the interval relative to 00:00 of the first day of the cycle
    /// </summary>
    [JsonProperty( PropertyName = "time_shift" )]
    [JsonRequired]
    public TimeSpan TimeShift { get; set; }

    /// <summary>
    /// Duration of interval
    /// </summary>
    [JsonProperty( PropertyName = "duration" )]
    [JsonRequired]
    public TimeSpan Duration { get; set; }

    /// <summary>
    /// Interval type
    /// </summary>
    [JsonProperty( PropertyName = "interval_type" )]
    [JsonRequired]
    public ShiftIntervalType IntervalType { get; set; }

    public WorktimeScheduleInterval Clone( TimeSpan shift )
    {
        return new WorktimeScheduleInterval()
        {
            TimeShift = TimeShift + shift,
            Duration = Duration,
            IntervalType = IntervalType
        };
    }
}


For example, we have following:
"schedule_intervals": [
   {
        "duration": "09:00:00",
        "time_shift": "09:00:00",
        "interval_type": 1
   },
   {
        "duration": "01:00:00",
        "time_shift": "12:00:00",
        "interval_type": 4
    }
]

so I would like to break in into this intervals:

09:00:00 - 12:00:00,
12:00:00 - 13:00:00
13:00:00 - / 18:00:00
Was this page helpful?