Add elixir dates

This commit is contained in:
Wilfried OLLIVIER 2019-11-06 15:51:46 +01:00
parent 50d46d7daf
commit bb4629f796
2 changed files with 28 additions and 0 deletions

View File

@ -8,6 +8,7 @@
- [Testing](./dev/golang/testing.md)
- [Elixir](./dev/elixir/main.md)
- [GenServer](./dev/elixir/genserver.md)
- [Dates](./dev/elixir/dates.md)
- [Rust](./dev/rust/main.md)
- [serde](./dev/rust/serde.md)
- [Testing](./dev/rust/testing.md)

27
src/dev/elixir/dates.md Normal file
View File

@ -0,0 +1,27 @@
# Dates
When working with dates in Elixir, nerver use "<" or ">", because sometimes, it will not work the way you want
```elixir
iex(16)> first = Timex.parse!("Tue, 29 Oct 2019 16:00:00 +0000", "%a, %d %b %Y %H:%M:%S %z", :strftime)
#DateTime<2019-10-29 16:00:00+00:00 GMT Etc/GMT+0>
iex(17)> second = Timex.parse!("Wed, 06 Nov 2019 23:00:00 +0000", "%a, %d %b %Y %H:%M:%S %z", :strftime)
#DateTime<2019-11-06 23:00:00+00:00 GMT Etc/GMT+0>
iex(18)> first < second
false
```
# [Timex](https://hexdocs.pm/timex/Timex.html)
For example, with `Timex` comes the `compare` function.
```elixir
Timex.compare(first, second)
-1
```
And return value should be considered as follow :
- -1 : first is before second
- 0 : first is equal to second
- 1 : second is before first