Time datatypes polyfill for old elixir versions

77 views
Skip to first unread message

Alexander

unread,
Jul 3, 2016, 6:33:33 AM7/3/16
to elixir-lang-talk
The idea:
Create separate hex package which contains following code:

if 1.3 datatypes do not exist, then register exact copies of them

Now All the date/time libraries can just use new datatypes without bothering about its absence

Does it makes sense?
Is it possible?

Peter Hamilton

unread,
Jul 3, 2016, 2:28:35 PM7/3/16
to elixir-lang-talk
https://github.com/hamiltop/calendar_polyfill

A few issues I found in the process:

1. A breaking change between 1.2 and 1.3 that isn't called out is the move from `:micro_seconds` to `:microseconds` in `System.convert_time_unit/3
2. There's a lot of `with` usage that depends on 1.3 functionality (else, guards, etc) That required some rewriting.

Not going to publish to hex until we get a few kinks worked out, but I plan to use this in the rethinkdb driver.

--
You received this message because you are subscribed to the Google Groups "elixir-lang-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-ta...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-talk/7373d4af-a4af-4250-80ee-10e3ca54fbb9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Michał Muskała

unread,
Jul 3, 2016, 2:48:57 PM7/3/16
to elixir-l...@googlegroups.com
On 03 Jul 2016, at 20:28, Peter Hamilton <petergh...@gmail.com> wrote:

1. A breaking change between 1.2 and 1.3 that isn't called out is the move from `:micro_seconds` to `:microseconds` in `System.convert_time_unit/3

But the old names should just work and nothing should be broken.

Michał.

signature.asc

Peter Hamilton

unread,
Jul 3, 2016, 3:01:26 PM7/3/16
to elixir-l...@googlegroups.com

The old names work, but the new names don't work on older elixir.

The polyfill accepts new names regardless of Elixir version.


--
You received this message because you are subscribed to the Google Groups "elixir-lang-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-ta...@googlegroups.com.

Ben Wilson

unread,
Jul 3, 2016, 3:37:06 PM7/3/16
to elixir-lang-talk
I'm confused. If you write a library on elixir 1.3 there's no reason to believe it should work as expected on Elixir 1.2

Peter Hamilton

unread,
Jul 3, 2016, 5:13:51 PM7/3/16
to elixir-lang-talk

Unless called out as a new function or as explicit changes, I would expect a function that exists in 1.2.6 and 1.3.0 to behave the same. Now that I know it accepts old arguments I don't think it's a breaking change.

My point is less about whether this is right or wrong. I'm just providing a data point that greater than zero library developers find this difference between minor versions is confusing and not well documented.


José Valim

unread,
Jul 3, 2016, 5:32:18 PM7/3/16
to elixir-l...@googlegroups.com

My point is less about whether this is right or wrong. I'm just providing a data point that greater than zero library developers find this difference between minor versions is confusing and not well documented.

In which sense is this confusing?  Where did you look for information and you could not find? I am trying to see what we can do to improve it.

Other than that, we are backwards compatible but it is expected new versions will receive new arguments and options that are not handled by previous versions.

Peter Hamilton

unread,
Jul 3, 2016, 5:52:10 PM7/3/16
to elixir-l...@googlegroups.com

Let me provide the narrative to give better context.

1. I ran code written for 1.3 on 1.2.6.
2. It spit out an error about convert_time_units not supporting :micro_seconds.
3. I looked at the change log and found nothing about convert_time_units.
4. I looked at the 1.3 documentation and found the type to be http://elixir-lang.org/docs/master/elixir/System.html#t:time_unit/0 . I saw a good explanation of why Elixir uses different unit names than Erlang.
5. I looked at the 1.2.6 documentation and found Erlang time units were required.
6. I assumed that Erlang time units were no longer supported (because there is a clear change in spec that says they aren't).
7. I adapted my code on the assumption that users of 1.3 would need to use micro_seconds and users of 1.2.6 would need to use microseconds. I can probably simplify it to always use microseconds for now.


--
You received this message because you are subscribed to the Google Groups "elixir-lang-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-ta...@googlegroups.com.

José Valim

unread,
Jul 3, 2016, 5:54:38 PM7/3/16
to elixir-l...@googlegroups.com
> 3. I looked at the change log and found nothing about convert_time_units.

This is the bug. :) I will update the CHANGELOG.



José Valim
Skype: jv.ptec
Founder and Director of R&D

Onorio Catenacci

unread,
Jul 5, 2016, 8:35:45 AM7/5/16
to elixir-lang-talk
+1 with Ben here.  If I write code against a newer version of a language/compiler, if it works on an older version that's nice but it's not something I would count on.  Even if I solely used constructs available in the older version I wouldn't take it for granted that the code would work with the older version. 

--
Onorio
Reply all
Reply to author
Forward
0 new messages