【问题标题】:Remove datetime range from a datetime range C#从日期时间范围 C# 中删除日期时间范围
【发布时间】:2023-01-10 14:20:29
【问题描述】:

我有计时日期时间范围:

clockingTime: [{In: "10-Jan-2023 1:45PM", Out: "10-Jan-2023 3:00PM"},{In: "10-Jan-2023 4:45PM", Out: "11-Jan-2023 8:13AM"}]

这是实际工作时间:

workingTime: {In: "10-Jan-2023 9:00PM", Out "11-Jan-2023 7:00AM"}  //to remove

我想从时钟时间中删除工作时间并为剩余的日期时间创建新范围。

[{In: "10-Jan-2023 1:45PM", },
{In: "10-Jan-2023 4:45PM", Out: "10-Jan-2023 9:00PM"},
{In: "11-Jan-2023 7:00AM", Out: "11-Jan-2023 8:13AM"}]

我不知道如何开始。也许给出一个想法就足够了。谢谢!

【问题讨论】:

  • 什么是 clockingTime,一个日期时间数组,字符串?什么是periods,什么是workingTime?请显示更多代码

标签: c# datetime time-and-attendance


【解决方案1】:

您只需要列出所有可能性,然后使用 if-elseif-else 分支输出日期时间范围。

[clocking time]
                  [working time]

ct.out <= wt.in --> (ct.in, ct.out)

[clocking time]
         [working time]

ct.in < wt.in && ct.out > wt.in && ct.out < wt.out --> (ct.in, wt.in)

[clockinggggg time]
   [workin time]

ct.in < wt.in && ct.out > wt.out --> (ct.in, wt.in), (wt.out, ct.out)

  [clocking time]
[workinggggggg time]

ct.in >= wt.in && ct.out <= wt.out --> ()

        [clocking time]
[working time]

ct.in >= wt.in && ct.in < wt.out && ct.out >= wt.out --> (wt.out, ct.out)

              [clocking time]
[workin time]

ct.in >= wt.out --> (ct.in, ct.out)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-03-04
    • 1970-01-01
    • 2018-03-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-17
    相关资源
    最近更新 更多