diff --git a/src/SUMMARY.md b/src/SUMMARY.md index bcaef37..ca3b6da 100644 --- a/src/SUMMARY.md +++ b/src/SUMMARY.md @@ -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) diff --git a/src/dev/elixir/dates.md b/src/dev/elixir/dates.md new file mode 100644 index 0000000..0316889 --- /dev/null +++ b/src/dev/elixir/dates.md @@ -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