Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates #1

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions .dialyzer_ignore.exs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
[
{"lib/tox/datetime.ex", :pattern_match, 579},
{"lib/tox/datetime.ex", :pattern_match, 584},
{"lib/tox/datetime.ex", :pattern_match, 587},
{"lib/tox/datetime.ex", :pattern_match, 737},
{"lib/tox/datetime.ex", :pattern_match, 743},
{"lib/tox/datetime.ex", :pattern_match, 746}
{"lib/tox/datetime.ex", :pattern_match, 579},
{"lib/tox/datetime.ex", :pattern_match, 582},
{"lib/tox/datetime.ex", :pattern_match, 738},
{"lib/tox/datetime.ex", :pattern_match, 741}
]
47 changes: 26 additions & 21 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Created with GitHubActions version 0.2.6
# Created with GitHubActions version 0.2.19
name: CI
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -12,29 +12,34 @@ jobs:
strategy:
matrix:
elixir:
- '1.11.4'
- '1.12.3'
- '1.13.4'
- '1.14.2'
- '1.14.5'
- '1.15.7'
- '1.16.0'
otp:
- '21.3'
- '22.3'
- '23.3'
- '24.3'
- '25.2'
- '25.3'
- '26.2'
exclude:
- elixir: '1.11.4'
otp: '25.2'
- elixir: '1.12.3'
otp: '21.3'
otp: '25.3'
- elixir: '1.12.3'
otp: '25.2'
otp: '26.2'
- elixir: '1.13.4'
otp: '21.3'
- elixir: '1.14.2'
otp: '21.3'
- elixir: '1.14.2'
otp: '26.2'
- elixir: '1.14.5'
otp: '22.3'
- elixir: '1.15.7'
otp: '22.3'
- elixir: '1.15.7'
otp: '23.3'
- elixir: '1.16.0'
otp: '22.3'
- elixir: '1.16.0'
otp: '23.3'
steps:
- name: Checkout
uses: actions/checkout@v3
Expand All @@ -58,28 +63,28 @@ jobs:
with:
path: test/support/plts
key: test/support/plts-${{ runner.os }}-${{ matrix.elixir }}-${{ matrix.otp }}-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }}
if: ${{ contains(matrix.elixir, '1.14.2') && contains(matrix.otp, '25.2') }}
if: ${{ contains(matrix.elixir, '1.16.0') && contains(matrix.otp, '26.2') }}
- name: Get dependencies
run: mix deps.get
- name: Compile dependencies
run: MIX_ENV=test mix deps.compile
- name: Compile project
run: MIX_ENV=test mix compile --warnings-as-errors
- name: Check unused dependencies
if: ${{ contains(matrix.elixir, '1.14.2') && contains(matrix.otp, '25.2') }}
if: ${{ contains(matrix.elixir, '1.16.0') && contains(matrix.otp, '26.2') }}
run: mix deps.unlock --check-unused
- name: Check code format
if: ${{ contains(matrix.elixir, '1.14.2') && contains(matrix.otp, '25.2') }}
if: ${{ contains(matrix.elixir, '1.16.0') && contains(matrix.otp, '26.2') }}
run: mix format --check-formatted
- name: Lint code
if: ${{ contains(matrix.elixir, '1.14.2') && contains(matrix.otp, '25.2') }}
if: ${{ contains(matrix.elixir, '1.16.0') && contains(matrix.otp, '26.2') }}
run: mix credo --strict
- name: Run tests
run: mix test
if: ${{ !(contains(matrix.elixir, '1.14.2') && contains(matrix.otp, '25.2')) }}
if: ${{ !(contains(matrix.elixir, '1.16.0') && contains(matrix.otp, '26.2')) }}
- name: Run tests with coverage
run: mix coveralls.github
if: ${{ contains(matrix.elixir, '1.14.2') && contains(matrix.otp, '25.2') }}
if: ${{ contains(matrix.elixir, '1.16.0') && contains(matrix.otp, '26.2') }}
- name: Static code analysis
run: mix dialyzer
if: ${{ contains(matrix.elixir, '1.14.2') && contains(matrix.otp, '25.2') }}
run: mix dialyzer --format github --force-check
if: ${{ contains(matrix.elixir, '1.16.0') && contains(matrix.otp, '26.2') }}
35 changes: 35 additions & 0 deletions .recode.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
[
version: "0.7.2",
# Can also be set/reset with `--autocorrect`/`--no-autocorrect`.
autocorrect: true,
# With "--dry" no changes will be written to the files.
# Can also be set/reset with `--dry`/`--no-dry`.
# If dry is true then verbose is also active.
dry: false,
# Enables or disables color in the output.
color: true,
# Can also be set/reset with `--verbose`/`--no-verbose`.
verbose: false,
# Can be overwritten by calling `mix recode "lib/**/*.ex"`.
inputs: ["{mix,.formatter}.exs", "{apps,config,lib,test}/**/*.{ex,exs}"],
formatters: [Recode.CLIFormatter],
tasks: [
# Tasks could be added by a tuple of the tasks module name and an options
# keyword list. A task can be deactivated by `active: false`. The execution of
# a deactivated task can be forced by calling `mix recode --task ModuleName`.
{Recode.Task.AliasExpansion, []},
{Recode.Task.AliasOrder, []},
{Recode.Task.Dbg, [autocorrect: false]},
{Recode.Task.EnforceLineLength, [active: false]},
{Recode.Task.FilterCount, []},
{Recode.Task.IOInspect, [autocorrect: false]},
{Recode.Task.Nesting, []},
{Recode.Task.PipeFunOne, []},
{Recode.Task.SinglePipe, []},
{Recode.Task.Specs, [exclude: ["test/**/*.{ex,exs}", "mix.exs"], config: [only: :visible]]},
{Recode.Task.TagFIXME, [exit_code: 2]},
{Recode.Task.TagTODO, [exit_code: 4]},
{Recode.Task.TestFileExt, []},
{Recode.Task.UnusedVariable, [active: false]}
]
]
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ The tests and examples are using the time zone database from
[`TimeZoneInfo`](https://github.com/hrzndhrn/time_zone_info)
and the calendars
[`Calendar.ISO`](https://hexdocs.pm/elixir/Calendar.ISO.html#content),
[`Cldr.Calendar.Coptic`](https://github.com/elixir-cldr/cldr_calendars_coptic)
and
[`Cldr.Calendar.Ethiopic`](https://github.com/elixir-cldr/cldr_calendars_ethiopic).
[`Calendar.Holocene`](https://en.wikipedia.org/wiki/Holocene_calendar), which is based on the Proleptic Gregorian calendar with every year + 10000.

## Installation

Expand Down
44 changes: 0 additions & 44 deletions lib/tox/calendar.ex

This file was deleted.

85 changes: 37 additions & 48 deletions lib/tox/date.ex
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ defmodule Tox.Date do
Using `shift/2` with a different calendar.

iex> ~D[2000-12-30]
...> |> Date.convert!(Cldr.Calendar.Coptic)
...> |> Date.convert!(Calendar.Holocene)
...> |> Tox.Date.shift(day: 3)
%Date{year: 1717, month: 4, day: 24, calendar: Cldr.Calendar.Coptic}
%Date{year: 12001, month: 1, day: 2, calendar: Calendar.Holocene}

"""
@spec shift(Calendar.date(), [Tox.duration()]) :: Date.t()
Expand Down Expand Up @@ -71,7 +71,7 @@ defmodule Tox.Date do
iex> Tox.Date.week(~D[2019-12-31])
{2020, 1}
iex> ~D[2020-06-04]
...> |> Date.convert(Cldr.Calendar.Ethiopic)
...> |> Date.convert(Calendar.Holocene)
...> |> Tox.Date.week()
** (FunctionClauseError) no function clause matching in Tox.Date.week/1

Expand All @@ -94,16 +94,15 @@ defmodule Tox.Date do
false

iex> Tox.Date.after?(
...> Date.convert!(~D[2000-01-22], Cldr.Calendar.Coptic),
...> Date.convert!(~D[2000-01-01], Cldr.Calendar.Coptic)
...> Date.convert!(~D[2000-01-22], Calendar.Holocene),
...> Date.convert!(~D[2000-01-01], Calendar.Holocene)
...> )
true

"""
defmacro after?(date1, date2) do
quote do
Date.compare(unquote(date1), unquote(date2)) == :gt
end
@spec after?(Calendar.date(), Calendar.date()) :: boolean
def after?(date1, date2) do
Date.compare(date1, date2) == :gt
end

@doc """
Expand All @@ -121,16 +120,15 @@ defmodule Tox.Date do
true

iex> Tox.Date.after_or_equal?(
...> Date.convert!(~D[2000-01-22], Cldr.Calendar.Ethiopic),
...> Date.convert!(~D[2000-01-01], Cldr.Calendar.Ethiopic)
...> Date.convert!(~D[2000-01-22], Calendar.Holocene),
...> Date.convert!(~D[2000-01-01], Calendar.Holocene)
...> )
true

"""
defmacro after_or_equal?(date1, date2) do
quote do
Date.compare(unquote(date1), unquote(date2)) in [:gt, :eq]
end
@spec after_or_equal?(Calendar.date(), Calendar.date()) :: boolean
def after_or_equal?(date1, date2) do
Date.compare(date1, date2) in [:gt, :eq]
end

@doc """
Expand All @@ -144,18 +142,15 @@ defmodule Tox.Date do
iex> Tox.Date.equal?(~D[2020-01-01], ~D[2020-01-01])
true

iex> ethiopic = Date.convert!(~D[2000-01-01], Cldr.Calendar.Ethiopic)
%Date{year: 1992, month: 4, day: 22, calendar: Cldr.Calendar.Ethiopic}
iex> coptic = Date.convert!(~D[2000-01-01], Cldr.Calendar.Coptic)
%Date{year: 1716, month: 4, day: 22, calendar: Cldr.Calendar.Coptic}
iex> Tox.Date.equal?(ethiopic, coptic)
iex> iso = ~D[2000-01-01]
iex> holocene = Date.convert!(iso, Calendar.Holocene)
iex> Tox.Date.equal?(iso, holocene)
true

"""
defmacro equal?(date1, date2) do
quote do
Date.compare(unquote(date1), unquote(date2)) == :eq
end
@spec equal?(Calendar.date(), Calendar.date()) :: boolean
def equal?(date1, date2) do
Date.compare(date1, date2) == :eq
end

@doc """
Expand All @@ -173,16 +168,15 @@ defmodule Tox.Date do
false

iex> Tox.Date.before?(
...> Date.convert!(~D[2000-01-22], Cldr.Calendar.Ethiopic),
...> Date.convert!(~D[2000-06-01], Cldr.Calendar.Ethiopic)
...> Date.convert!(~D[2000-01-22], Calendar.Holocene),
...> Date.convert!(~D[2000-06-01], Calendar.Holocene)
...> )
true

"""
defmacro before?(date1, date2) do
quote do
Date.compare(unquote(date1), unquote(date2)) == :lt
end
@spec before?(Calendar.date(), Calendar.date()) :: boolean
def before?(date1, date2) do
Date.compare(date1, date2) == :lt
end

@doc """
Expand All @@ -200,16 +194,15 @@ defmodule Tox.Date do
true

iex> Tox.Date.before_or_equal?(
...> Date.convert!(~D[2000-01-22], Cldr.Calendar.Ethiopic),
...> Date.convert!(~D[2000-06-01], Cldr.Calendar.Ethiopic)
...> Date.convert!(~D[2000-01-22], Calendar.Holocene),
...> Date.convert!(~D[2000-06-01], Calendar.Holocene)
...> )
true

"""
defmacro before_or_equal?(date1, date2) do
quote do
Date.compare(unquote(date1), unquote(date2)) in [:lt, :eq]
end
@spec before_or_equal?(Calendar.date(), Calendar.date()) :: boolean
def before_or_equal?(date1, date2) do
Date.compare(date1, date2) in [:lt, :eq]
end

@doc """
Expand Down Expand Up @@ -305,9 +298,7 @@ defmodule Tox.Date do

"""
@spec beginning_of_week(Calendar.date()) :: Calendar.date()
def beginning_of_week(date) do
shift(date, day: Tox.Calendar.beginning_of_week(date))
end
def beginning_of_week(date), do: Date.beginning_of_week(date)

@doc """
Returns a date representing the end of the year.
Expand All @@ -319,9 +310,9 @@ defmodule Tox.Date do
~D[2020-12-31]

iex> ~D[2020-11-11]
iex> |> Date.convert!(Cldr.Calendar.Coptic)
iex> |> Date.convert!(Calendar.Holocene)
iex> |> Tox.Date.end_of_year()
%Date{year: 1737, month: 13, day: 5, calendar: Cldr.Calendar.Coptic}
%Date{year: 12020, month: 12, day: 31, calendar: Calendar.Holocene}

"""
@spec end_of_year(Calendar.date()) :: Calendar.date()
Expand All @@ -339,11 +330,10 @@ defmodule Tox.Date do
iex> Tox.Date.end_of_month(~D[2020-11-11])
~D[2020-11-30]

iex> ~D[2020-12-31]
...> |> Date.convert!(Cldr.Calendar.Coptic)
...> |> Tox.Date.shift(day: 1)
iex> ~D[2020-12-03]
...> |> Date.convert!(Calendar.Holocene)
...> |> Tox.Date.end_of_month()
%Date{year: 1737, month: 4, day: 30, calendar: Cldr.Calendar.Coptic}
%Date{year: 12020, month: 12, day: 31, calendar: Calendar.Holocene}

"""
@spec end_of_month(Calendar.date()) :: Calendar.date()
Expand All @@ -361,10 +351,9 @@ defmodule Tox.Date do
~D[2020-11-15]

iex> ~D[2020-11-11]
...> |> Date.convert!(Cldr.Calendar.Ethiopic)
...> |> Date.convert!(Calendar.Holocene)
...> |> Tox.Date.end_of_week()
%Date{year: 2013, month: 3, day: 6, calendar: Cldr.Calendar.Ethiopic}

%Date{year: 12020, month: 11, day: 15, calendar: Calendar.Holocene}
"""
@spec end_of_week(Calendar.date()) :: Calendar.date()
def end_of_week(%{calendar: calendar, year: year, month: month, day: day} = date) do
Expand Down
Loading
Loading