gpt4 book ai didi

ruby-on-rails - 减去两个时间范围

转载 作者:行者123 更新时间:2023-12-04 15:42:31 24 4
gpt4 key购买 nike

我有两个时间范围

Fri, 02 Aug 2019 10:09:58 UTC +00:00..Fri, 02 Aug 2019 23:59:59 UTC +00:00
Fri, 02 Aug 2019 11:09:58 UTC +00:00..Fri, 02 Aug 2019 12:09:58 UTC +00:00

从第一个减去第二个最简单的方法是什么

[
Fri, 02 Aug 2019 10:09:58 UTC +00:00..Fri, 02 Aug 2019 11:09:58 UTC +00:00,
Fri, 02 Aug 2019 12:09:58 UTC +00:00..Fri, 02 Aug 2019 23:59:59 UTC +00:00
]

最佳答案

我会做这样的事情:

range_1 = (Time.parse('2019-08-02 10:09:58 UTC') .. Time.parse('2019-08-02 23:59:59 UTC'))
range_2 = (Time.parse('2019-08-02 11:09:58 UTC') .. Time.parse('2019-08-02 12:09:58 UTC'))

[(range_1.begin..range_2.begin), (range_2.end..range_1.end)]
#=> [2019-08-02 10:09:58 UTC..2019-08-02 11:09:58 UTC, 2019-08-02 12:09:58 UTC..2019-08-02 23:59:59 UTC]

关于ruby-on-rails - 减去两个时间范围,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57324451/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com