-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Jonatan Männchen <jonatan@maennchen.ch>
- Loading branch information
Showing
10 changed files
with
200 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
defmodule Crontab.DateLibrary do | ||
@moduledoc """ | ||
This Behaviour offers Date Library Independant integration of helper | ||
functions. | ||
**This behavious is considered internal. Breaking Changes can occur on every | ||
release.** | ||
Make sure your implementation passes `Crontab.DateLibraryTest`. Otherwise | ||
unexpected behaviour can occur. | ||
""" | ||
|
||
@type time_unit :: :days | :hours | :minutes | :seconds | :years | :months | ||
|
||
@callback shift(NaiveDateTime.t, integer, time_unit) :: NaiveDateTime.t | ||
|
||
@callback beginning_of_year(NaiveDateTime.t) :: NaiveDateTime.t | ||
|
||
@callback end_of_year(NaiveDateTime.t) :: NaiveDateTime.t | ||
|
||
@callback beginning_of_month(NaiveDateTime.t) :: NaiveDateTime.t | ||
|
||
@callback end_of_month(NaiveDateTime.t) :: NaiveDateTime.t | ||
|
||
@callback beginning_of_day(NaiveDateTime.t) :: NaiveDateTime.t | ||
|
||
@callback end_of_day(NaiveDateTime.t) :: NaiveDateTime.t | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
if Code.ensure_compiled?(Timex) do | ||
defmodule Crontab.DateLibrary.Timex do | ||
@moduledoc false | ||
|
||
@behaviour Crontab.DateLibrary | ||
|
||
def shift(date, amount, unit) do | ||
Timex.shift(date, [{unit, amount}]) | ||
end | ||
|
||
defdelegate beginning_of_year(date), to: Timex | ||
|
||
defdelegate end_of_year(date), to: Timex | ||
|
||
defdelegate beginning_of_month(date), to: Timex | ||
|
||
defdelegate end_of_month(date), to: Timex | ||
|
||
defdelegate beginning_of_day(date), to: Timex | ||
|
||
defdelegate end_of_day(date), to: Timex | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Date Library | ||
|
||
This library can be used independent from `timex`. | ||
|
||
Any date library can be used by implementing the `Crontab.DateLibrary` behavior. | ||
|
||
**The library does not respect semver for this behaviour. Breaking Changes will | ||
happen even in patch releases.** | ||
|
||
To use another date library, change the implementation like this: | ||
|
||
```elixir | ||
config :crontab, | ||
date_library: Crontab.DateLibrary.Timex | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.