bitwalker / bitwalker/timex

Timex diff/3 fails when working with a negative date

Open
#765 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Elixir
Stars
1.8k
Forks
407
PR merge metrics
No merged PRs in 30d

Description

This is pretty niche, but I forgot which version of Elixir allowed dates to have negative years, I've been using it for a project of mine with great success, until I needed to use some `Timex.diff/3` on it, granted I could just use `Date.diff/2` in some cases, but if anything outside of days is required, well...

### Steps to reproduce

```elixir
Timex.diff(~D[-1755-01-01], Date.utc_today(), :years)
```

### Description of issue

```
** (FunctionClauseError) no function clause matching in :calendar.last_day_of_the_month/2

The following arguments were given to :calendar.last_day_of_the_month/2:

# 1
-1755

# 2
1

(stdlib 6.1) calendar.erl:373: :calendar.last_day_of_the_month/2
(stdlib 6.1) calendar.erl:222: :calendar.date_to_gregorian_days/3
(stdlib 6.1) calendar.erl:252: :calendar.datetime_to_gregorian_seconds/1
(timex 3.7.11) lib/date/date.ex:16: Timex.Protocol.Date.to_gregorian_microseconds/1
(timex 3.7.11) lib/comparable/diff.ex:15: Timex.Comparable.Diff.diff/3
iex:2: (file)
```

So there might be room to utilize Elixir's date/time modules in more places rather than relying on erlang's calendar, I have no idea what it would take to make this work (not that familiar with the internals of Timex)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.