简体   繁体   中英

Using Timex Interval

I've got

Interval.new(from: start_date, until: end_date)

with [start_date, end_date] = [~N[2019-02-12 00:00:00.000000, ~N[2019-02-15 00:00:00.000000]

The problem is, this generates the dates:

[~N[2019-02-12 00:00:00.000000], ~N[2019-02-13 00:00:00.000000],
 ~N[2019-02-14 00:00:00.000000]]

but misses the last day (15th Feb). Is there a way I can coax Timex to adding that boundary to the list?

Timex.Interval.new/1 has a perfect documentation that clearly mentions right_open: true parameter.


The documentation is not quite accurate though :) It should be right_open: false FWIW.

[start_date, end_date] =
  [~N[2019-02-12 00:00:00.000000], ~N[2019-02-15 00:00:00.000000]]

Timex.Interval.new(
  from: start_date, until: end_date,
  left_open: false, right_open: false
)
|> Enum.to_list
#⇒ [~N[2019-02-12 00:00:00.000000], ~N[2019-02-13 00:00:00.000000],
#   ~N[2019-02-14 00:00:00.000000], ~N[2019-02-15 00:00:00.000000]]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM