EZCalendar v0.1.5 EZCalendar
Functions for building calendars.
To use the Repo shortcut functions, add EZCalendar
to your repo.
defmodule MyApp.Repo do
use Ecto.Repo, otp_app: :my_app
use EZCalendar
end
The following functions and their bang! variants then become available.
Repo.calendar(query, calendar_module, params, opts \\ [])
Repo.day_calendar(query, params, opts \\ [])
Repo.week_calendar(query, params, opts \\ [])
Repo.month_calendar(query, params, opts \\ [])
Repo.biweekly_calendar(query, params, opts \\ [])
You can use a keyword list for multiple queries. Each query will use the default field(s) unless provided in the query list or in the options and the results will be accessible by their key in each dates data field.
[
shifts: [Shift, [:starting, :ending]],
events: [Event, :starting_at],
meetings: Meeting,
deliveries: Delivery
]
|> Repo.month_calendar({2016, 11}, field: :scheduled_for)
Params can be a Date, DateTime, erl style tuple or map containing a day month and year. The day can be ommited from the params, doing so will result in the first of the month being used. Tuple and map values will be cast as integers for easy integration with phoenix.
The timezone and query field can be set with :tz
and :field
as options.
If using a biweekly calendar the biweekly_start
can also be set.
Summary
Functions
Builds a calendar struct. Returns a tuple containing :ok
and the calendar or :error
and the reason
Builds a calendar struct. Returns a calendar or raises an error
Functions
Builds a calendar struct. Returns a tuple containing :ok
and the calendar or :error
and the reason.
Takes a calendar module, repo, query, params and options as its arguments.
The params provided in the args are parsed into a date erl
and passed to the calendar modules date_range
function.
The timezone and query field can be set with :tz
and :field
as options
Builds a calendar struct. Returns a calendar or raises an error
Arguments and options are the same as build_calendar/5