简体   繁体   English

更新后续开始和结束日期时间的逻辑

[英]Logic to update subsequent start and end date times

Suppose I have a two objects with a [start DateTime] and an [end DateTime] If I change the [start DateTime] and/or [end DateTime] of the 1st object, I want to like to apply that change to the next object's [start DateTime] and/or [end DateTime] .假设我有一个带有[start DateTime][end DateTime]两个对象[开始日期时间]和/或[结束日期时间]

What would be the best way to do this without " The dates overlapping "?没有“日期重叠”的最佳方法是什么?

NOTE: THE NEXT OBJECT SHOULD HAVE [start DateTime] and [end DateTime] AFTER THE FIRST OBJECT'S [start DateTime] and [end DateTime].注意:下一个 OBJECT 应该在第一个对象的 [start DateTime] 和 [end DateTime] 之后具有 [start DateTime] 和 [end DateTime]。

UPDATE THE time difference between each objects start and end time shouldn't change at all.更新每个对象开始和结束时间之间的时间差根本不应该改变。

Example: Same date for all objects in this example.示例:此示例中所有对象的日期相同。 Can be different.可以不同。 OBJECT 1 ->>> START (07:58) END (08:28) OBJECT 2 ->>> START (08:48) END (10:30) OBJECT 1 ->>> 开始 (07:58) 结束 (08:28) OBJECT 2 ->> 开始 (08:48) 结束 (10:30)

When OBJECT 1 is changed to ->> START (07:56) END (10:46) OBJECT 2 should change ->> START (after OBJECT 1 END) END (after OBJECT 2 START) When OBJECT 1 is changed to ->> START (07:56) END (10:46) OBJECT 2 should change ->> START (after OBJECT 1 END) END (after OBJECT 2 START)

The differnce should be similar as well.差异也应该相似。 For example, we added 2 hrs and 18 minutes to OBJECT 1 END, so OBJECT 2 should ideally have times increased by 2 hrs 18 minutes.例如,我们将 2 小时 18 分钟添加到 OBJECT 1 END,因此 OBJECT 2 理想情况下应该增加 2 小时 18 分钟。 Also, we decreased the OBJECT 1 START by 2 minutes.此外,我们将 OBJECT 1 START 减少了 2 分钟。 This should ideally be reflected in OBJECT 2 times as wll.理想情况下,这应该在 OBJECT 中反映 2 次。

Current logic: PSEUDO CODE What I'm currently doing is,当前逻辑:伪代码我目前正在做的是,

var OBJECT1StartDifference = OBJECT1.OriginalStart - OBJECT1.Start;
var OBJECT1EndDifference = OBJECT1.OriginalEnd - OBJECT1.End;

ForEach(nextObject in ParentObject.where(obj => obj.Order > OBJECT1.order))
{
   if(OBJECT1StartDifference.HasValue)
   {
      nextObject.Start.Add(OBJECT1StartDifference);
   }

   if(OBJECT1EndDifference.HasValue)
   {
      nextObject.End.Add(OBJECT1EndDifference);
   }
}

I thought of something that would work.我想到了一些可行的方法。

Instead of calculating the difference between start times and end times, I'm now only calculating the difference between end times for the OBJECT1.我现在只计算 OBJECT1 的结束时间之间的差异,而不是计算开始时间和结束时间之间的差异。

Then I'm applying this difference to OBJECT2 start and end time.然后我将此差异应用于 OBJECT2 开始和结束时间。

This will keep the OBJECT2 times always after OBJECT1 times and keep the difference between OBJECT2 start and end time the same.这将使 OBJECT2 时间始终在 OBJECT1 时间之后,并保持 OBJECT2 开始时间和结束时间之间的差异相同。

Note: I also have a logic to change the OBJECT1 start time if end time is edited, and end time if start time is edited, to keep the difference between start and end time the same always.注意:如果编辑结束时间,我还有一个逻辑来更改 OBJECT1 开始时间,如果编辑开始时间,则更改结束时间,以保持开始时间和结束时间之间的差异始终相同。

PSEUDO CODE:伪代码:

var deltaObject1EndTime = OBJECT1.EndTime - OBJECT1.PreviousEndTime; 

if(deltaObject1EndTime != o)
{
    foreach(var OBJECT in PARENTOBJECT.Objects.Where(obj => obj.Order > OBJECT1.Order))
    {
        OBJECT.StartTime.Add(deltaObject1EndTime);
        OBJECT.EndTime.Add(deltaObject1EndTime);
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM