有时间间隔的包容/排除结束标准吗? [英] Is there a standard for inclusive/exclusive ends of time intervals?

查看:252
本文介绍了有时间间隔的包容/排除结束标准吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道在定义终点的值的包容性/排他性方面是否存在一种标准或正常解释时间间隔数据终点的手段。但是请注意,我问什么标准(或最常见的) 惯例 是(如果有的话),而不是您个人喜好的论文。如果您真的想提供论文,请附上一个参考某人发布的标准或标准文本。开放标准(我不需要付费阅读)是非常优选的,除非它们有根本的缺陷:)。

I'm wondering if there is a standard or "normal" means of interpreting time interval data end points with respect to inclusiveness/exclusiveness of the value defining the end point. Note however that I am asking what the standard (or most common) convention is (if there is one), not for a dissertation on your personal preference. If you really want to provide a dissertation, please attach it to a reference to someone's published standard or a standard text on the matter. Open standards (that I don't have to pay to read) are greatly preferred unless they are fundamentally flawed :).

当然,有一个时间间隔有4种可能性从A到B:

Of course there are 4 possibilities for a time interval from A to B:


  1. (A,B) - 两端都是排他的。

  2. [ A,B] - 两端都是包容的。

  3. [A,B) - 开始是包容性的,结束是排他

  4. (A,B) - 开始是独一无二的,结束是包容的

  1. (A, B) - Both ends are exclusive.
  2. [A, B] - Both ends are inclusive.
  3. [A, B) - Start is inclusive and end is exclusive
  4. (A, B] - Start is exclusive and end is inclusive

每个都有不同的特征(我看到,随意指出更多)

Each of these has different characteristics (as I see it, feel free to point out more)

[A,B]约定将具有看似不便的属性,B包含在[A,B]和[B,C]中,这是特别是不方便,如果B意在表示午夜的边界,而你正在试图确定哪一天它属于这个例子,而且这意味着间隔的持续时间稍微刺激,因为[A,B]其中A = B应该长度为1, [A,B]的持续时间是(B-A) + 1

The [A, B] convention would have the seemingly inconvenient property that B is contained withing the inteval [A, B] and also [B, C]. This is particularly inconvenient if B is meant to represent the midnight boundary and you are trying to determine which day it falls on for example. Also, this means the duration of the interval is slightly irritatig to calculate since [A, B] where A = B should have a length of 1 and therefore the duration of [A, B] is (B - A) + 1

同样,(A,B) B(A,B)和(B,C)都不在...的困难之中...继续类似于天界,午夜将是两天之间的一部分。这也在逻辑上是不方便的,因为[A,B]其中A = B是持续时间小于零的无意义区间,但反转A和B不会使其成为有效间隔

Similarly the (A, B) convention would have the difficulty that B falls within neither (A,B) nor (B,C)... continuing the analogy with day boundaries, midnight would be part of neither day. This is also logically inconvenient because [A, B] where A = B is a non-sense interval with duration less than zero, but reversing A and B does not make it a valid interval.

所以我想我想要[A,B]或(A,B),我无法弄清楚他们之间如何决定。

So I think I want either [A, B), or (A, B] and I can't figure out how to decide between them.

因此,如果有人链接到标准文档,请参考标准文本或类似内容,澄清公约将是巨大的。或者,如果您可以链接各种标准文档和/或参考文献或多或少完全不同意,那么我可以选择一个似乎有足够的权力给CMA,并完成它:)。

So if someone has a link to a standards document, reference to a standard text or similar that clarify the convention that would be great. Alternately, if you can link a variety of standards documents and/or references that more or less completely fail to agree, then I can just pick one that seems to have sufficient authority to CMA and be done with it :).

最后,我将在Java中工作,所以我特别容易在Java中工作得很好的答案。

Finally, I will be working in Java, so I am particularly susceptible to answers that work well in Java.

推荐答案

在一般情况下, [A,B] 有很多事情,我没有看到任何理由时间间隔不一样。

In the general case, [A, B) has a lot going for it and I don't see any reason why the same wouldn't be true for time intervals.

Djikstra写了一篇很好的文章为什么编号应该从零开始哪个 - 尽管名称 - 主要是这些。

Djikstra wrote a nice article about it Why numbering should start at zero which - despite the name - deals mostly with exactly this.

简短的优点摘要:


  • end - 开始等于列表中的项目数量

  • 上一个间隔的上限是下一个
  • 的下限
  • 允许使用无符号数字从0开始索引间隔[1]

  • end - start equals the number of items in the list
  • upper bound of preceding interval is the lower bound of the next
  • allows to index an interval starting from 0 with unsigned numbers [1]

个人第二点是极其对很多问题有用考虑一个漂亮的标准递归函数(在伪python中):

Personally the second point is extremely useful for lots of problems; consider a pretty standard recursive function (in pseudo python):

def foo(start, end):
    if end - start == 1:
        # base case
    else:
        middle = start + (end - start) / 2
        foo(start, middle)
        foo(middle, end)

使用包含的上限写入相同的错误引起了很多错误。

Writing the same with inclusive upper bound introduces lots of error prone off by one errors.

[1]与(A,B)相比,这个优点是 - 从0开始的间隔更多请注意,还有一个额外的问题:使用两个包含的边界意味着我们可以表示一个长度不能用相同大小表示的序列,它的长度不能超过 MAX_VAL

[1] That's the advantage compared to (A, B] - a interval starting from 0 is MUCH more common than an interval ending in MAX_VAL. Note that also relates to one additional problem: Using two inclusive bounds means we can denote a sequence whose length cannot be expressed with the same size.

这篇关于有时间间隔的包容/排除结束标准吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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