Coder Social home page Coder Social logo

calendar_interval's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

calendar_interval's Issues

Make new/3 public

Calendar.Interval.new/3 is currently a private function however it has valid public use cases where creating an interval between two arbitrary naive_date_times with a given precision is a requirement. Consider making it public?

Pass function to next/2, prev/2

It is sometimes convenient to find "next Monday" or "last Friday", I think we can neatly achieve it with this API:

# next Monday
iex> CalendarInterval.next(~I"2020-07-09", &Date.day_of_week(&1.first) == 1)
~I"2020-07-13"

v0.1

  • Fix bug:
    iex> ~I"2018" |> I.nest(:minute) |> Enum.at(-1) # => ~I"2019-12-31 23:58"
    is wrong
  • Decide if we keepnext(~I"2018/2019") #=> ~I"2020" or it should be #=> ~I"2020/2021"
  • Decide if we allow to use all precisions in nest/2 and enclosing/2

Wrong last element of the interval at years end

Today we have:

iex> Enum.to_list(~I"2020-10/11")
[~I"2020-10", ~I"2020-11/12"]

and consequently we have:

iex> CalendarInterval.relation(~I"2020-10/11", ~I"2020-10/12")
:equal

which is wrong, we should have:

iex> Enum.to_list(~I"2020-10/11")
[~I"2020-10", ~I"2020-11"]

TBD: change precision representation

Currently the precision is an atom:

iex> ~I[2019-01-01].precision
:day

and so if there's a function that just wants to print, say, day from a given interval it needs to check it like that:

def print_day(%CalendarInterval{precision: precision} = i when precision in [:day, :minute, :second, {:microsecond, 0}, {:microsecond, 1}, ..., {:microsecond, 6}] do
  IO.puts "#{i.day}"
end
def print_day(%CalendarInterval{} =i) do
  raise ArgumentError, "#{inspect(i)} does not have :day precision"
end

An idea is to store which time components we have instead:

iex> ~I[2019-01-01].components
#MapSet<[:year, :month, :day]>
def print_day(%CalendarInterval{} = i) do
  if :day in i.components do
    IO.puts "#{i.day}"
  else
    raise ArgumentError, "#{inspect(i)} does not have :day precision"
  end
end

This is how https://github.com/domainlanguage/time-count handles it.

relation/2 and different precisions

Currently we can only compute the relation of intervals with the same precision:

CalendarInterval.relation(~I"2020", ~I"2020-01/12")
** (FunctionClauseError) no function clause matching in CalendarInterval.relation/2

this restriction seems arbitrary and I think conceptually comparing these makes sense and we should have:

iex> CalendarInterval.relation(~I"2020", ~I"2020-01/12")
:equal

iex> CalendarInterval.relation(~I"2020", ~I"2020-01/11")
:started_by

# etc

wdyt @kipcole9?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.