java - 从基本时间间隔中减去一个间隔后如何获取剩余间隔列表
问题描述
java
在从基本时间间隔中删除子时间间隔后,是否有任何方法可以列出剩余的时间间隔。
示例:考虑存在 0 到 24 小时的时间间隔,如果我从10 AM
到删除时间12AM
,那么剩余的时间间隔应该是0-10
和12-24
。
在这种情况下,基本间隔是 0-24 小时。
解决方案
I did not find method for this in Joda library nor in SDK.
Basically interval is defined as a start and end timestamp. Method for substracting could have this logic:
Base interval (s1,e1)
Subsctracted interval (s2,e2)
If s1<s2
and e2<e1
then complement intervals are (s1, s2) and (e2, e1)
If s2<s1
and e2<e1
then complement is (e2, e1)
If s1<s2
and e1<e2
then complement is (s1, s2)
If base is inside substracted then complement is null
If no intersection result is base interval.
推荐阅读
- java - Java - 创建多个对象后如何避免 StackOverflow?
- javascript - 使用 React Native 显示 Firebase 数据
- gitlab - Gitlab无法启动运行v没有运行
- python - 如何处理从 Optimizer.compute_gradients 获得的梯度?
- ios - 如何在 UI 中显示活动指示器,同时使用文件管理器创建文件
- database - 本机模式下的 Firestore DB 文档写入限制
- python - 如何在 django 中为同一浏览器管理和前端管理单独的会话
- java - 如何获取无线路由器的mac地址?
- react-native - React-native:文本输入框不会在屏幕上呈现
- javascript - 传单检查标记是否在其他标记检查的 5 米范围内