基于后续记录值调整活动时间戳的规则实现技术问询
Timestamp Update Logic for Activity Records
Hey there, let's break down how to handle updating timestamps based on subsequent activity records, following your specific rules. Here's a clear, actionable approach:
Core Update Rules
- First, group all activity records by
workID—we only care about comparing activities within the same work group. - Sort each
workIDgroup bystart time(this ensures we're checking the correct "previous" and "next" activities in chronological order). - Iterate through each activity in the sorted group (skip the last one, since there's no subsequent activity):
- Compare the current activity's
end timewith the next activity'sstart time:- If the next activity starts before the current one ends (
next.start < current.end):- Update the current activity's
start timetonext.start - 1 second - Update the current activity's
end timetonext.start - 1 second
- Update the current activity's
- If there's no overlap, leave the current activity's timestamps as-is.
- If the next activity starts before the current one ends (
- Compare the current activity's
Key Notes to Remember
- Duplicate
workAcentries within the sameworkIDare totally fine—no need to remove them. Just process each record in order. - Don't worry about activities where
start timeequalsend time, or where they differ. That's intentional per your requirements, so we ignore those cases and focus only on the overlap rule. - Always make sure you're only comparing activities that share the same
workID—different works don't interfere with each other.
Quick Example to Illustrate
Let's say we have two activities under the same workID:
- Activity A:
start=2024-05-20 10:00:00,end=2024-05-20 10:30:00 - Activity B:
start=2024-05-20 10:20:00,end=2024-05-20 10:40:00
Since Activity B starts before Activity A ends, we adjust Activity A's timestamps:
- Updated Activity A:
start=2024-05-20 10:19:59,end=2024-05-20 10:19:59
Now there's no overlap between the two activities, which fits your requirement perfectly.
内容的提问来源于stack exchange,提问作者kzmlbyrk
相关产品推荐
相关产品推荐

