组合两个Joda-Time Interval对象 [英] Make a union of two Joda-Time Interval objects

查看:121
本文介绍了组合两个Joda-Time Interval对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Joda-Time 中,有没有办法创建一个 Interval 作为另外两个间隔的联合。我知道交叉路口方法称为 重叠 (和重叠)。但是我看不到任何联合方法。

In Joda-Time, is there any way to create a Interval as a union of two other intervals. I know there is intersection method which is called overlap (and overlaps). But I can not see any union methods.

推荐答案

如果你想要一个覆盖其他的间隔,只需创建一个新的间隔从 min(a.start,b.start)运行到 max(a.end,b.end)

If you want an interval that "covers" two others, just create a new interval that runs from min(a.start, b.start) to max(a.end, b.end).

如果您还需要表示差距,那么您需要编写自己的类来处理所需的行为。没有什么内置于Joda-time,因为有几种可能的解释,它对联合不连续的间隔意味着什么。

If you need to represent the gap as well, then you'll need to write your own classes to handle the behavior you want. There's nothing builtin to Joda-time for this as there are several possible interpretations of what it means to "union" non-contiguous intervals.

这篇关于组合两个Joda-Time Interval对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆