Looking at the Elixir code for this, it's mostly routed to 
`System.convert_time_unit/3` which is a wrapper to 
`erlang.convert_time_unit/3`. Would it make more sense to try upstreaming 
this into erlang/otp?

On Wednesday, June 3, 2020 at 1:31:42 AM UTC-6 Ulisses Almeida wrote:

> Well, if you implementing a fantasy world game, a week can have different 
> days.
>
> For example, in forgotten realms, a week has 10 days.
> https://forgottenrealms.fandom.com/wiki/Calendar_of_Harptos
>
> Em qua., 3 de jun. de 2020 às 10:23, José Valim <[email protected]> 
> escreveu:
>
>> Good point Wojtek.
>>
>> Unfortunately this concern also applies to hours and seconds, which can 
>> change between calendars. I believe seconds today already operates as ISO 
>> seconds, so I would just document that all units are ISO units.
>>
>>
>> On Wed, Jun 3, 2020 at 9:14 AM Wojtek Mach <[email protected]> wrote:
>>
>>> 
>>> Just a word of warning, I believe that while supporting minutes, hours, 
>>> and days is rather trivial since we have such fields on the structs and so 
>>> we could just increment them, supporting weeks is trickier - are all weeks 
>>> composed of 7 days or there are calendars where this is not true? Maybe se 
>>> should start without weeks then? Or there will be a callback for them? Leap 
>>> seconds may or may not be a concern too.
>>>
>>> On 3 Jun 2020, at 08:45, José Valim <[email protected]> wrote:
>>>
>>> 
>>> Thank you for the proposal. I believe this would be a welcome change. My 
>>> only question is if we should support them in the Calendar types or 
>>> directly on the System module. Given the System module does many 
>>> conversions between time units, supporting those there is slightly more 
>>> complicated.
>>>
>>> Perhaps we start with support on Calendar types and then we move it to 
>>> System if necessary? This means:
>>>
>>> 1. Support minute and hour in Time
>>> 2. Support week in Date
>>> 3. Support minute, hour, day and week in NaiveDateTime
>>> 4. Support minute, hour, day and week in DateTime
>>>
>>>
>>> On Wed, Jun 3, 2020 at 5:34 AM Parker Selbert <[email protected]> 
>>> wrote:
>>>
>>>> *Problem*
>>>>
>>>> Functions that convert or work with time units, i.e. 
>>>> `System.convert_time_unit/1`, `DateTime.add/3` and `Time.add/3` are 
>>>> limited 
>>>> to working with a subset of possible time units. The current subset of 
>>>> *named 
>>>> units* includes `:second`, `:millisecond`, `:microsecond`, and 
>>>> `:nanosecond`. It is extremely common to manipulate dates and times by 
>>>> larger units such as minutes, hours or days. Currently we have to convert 
>>>> any values to seconds and then use that to change the value, which isn't 
>>>> particularly explicit or expressive. For example, to get the date for one 
>>>> week from now I need to write:
>>>>
>>>> DateTime.add(DateTime.utc_now(), 7 * 24 * 60 * 60, :second)
>>>>
>>>> *Proposal*
>>>>
>>>> I propose the addition of larger pre-defined units to make conversion 
>>>> more expressive. Units could include some or all of the following:
>>>>
>>>>    - `:minute`
>>>>    - `:hour`
>>>>    - `:day`
>>>>    - `:week`
>>>>
>>>> Some larger units such as `month` or `year` are not fixed or standard 
>>>> units and could be omitted.
>>>>
>>>> This enables more expressive time calculations such as "one hour from 
>>>> now", "one day from now", etc.:
>>>>
>>>> utc_now = DateTime.utc_now()
>>>> DateTime.add(utc_now, 30, :minute)
>>>> DateTime.add(utc_now, 1, :hour)
>>>> DateTime.add(utc_now, 1, :day)
>>>>
>>>> In my experience it is extremely common to find module attributes or 
>>>> variables that declar a unit of time to make larger values comprehensible. 
>>>> It is much clearer to specify `1, :day` instead of `@one_day_in_seconds, 
>>>> :second` or something similar.
>>>>
>>>> -- 
>>>> You received this message because you are subscribed to the Google 
>>>> Groups "elixir-lang-core" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send 
>>>> an email to [email protected].
>>>> To view this discussion on the web visit 
>>>> https://groups.google.com/d/msgid/elixir-lang-core/7ca22377-aadc-4e5b-a57f-ad0c52fc5ba8%40googlegroups.com
>>>>  
>>>> <https://groups.google.com/d/msgid/elixir-lang-core/7ca22377-aadc-4e5b-a57f-ad0c52fc5ba8%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>> .
>>>>
>>> -- 
>>> You received this message because you are subscribed to the Google 
>>> Groups "elixir-lang-core" group.
>>> To unsubscribe from this group and stop receiving emails from it, send 
>>> an email to [email protected].
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/elixir-lang-core/CAGnRm4KTjtL-4K3-hj%2Bf%3D7sqHrkOJ52_C9VJ9u_Ekc35C_dY_A%40mail.gmail.com
>>>  
>>> <https://groups.google.com/d/msgid/elixir-lang-core/CAGnRm4KTjtL-4K3-hj%2Bf%3D7sqHrkOJ52_C9VJ9u_Ekc35C_dY_A%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>>> -- 
>>> You received this message because you are subscribed to the Google 
>>> Groups "elixir-lang-core" group.
>>> To unsubscribe from this group and stop receiving emails from it, send 
>>> an email to [email protected].
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/elixir-lang-core/FF8AE738-AF6D-4B5C-8EB9-55F86DC49D8D%40wojtekmach.pl
>>>  
>>> <https://groups.google.com/d/msgid/elixir-lang-core/FF8AE738-AF6D-4B5C-8EB9-55F86DC49D8D%40wojtekmach.pl?utm_medium=email&utm_source=footer>
>>> .
>>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "elixir-lang-core" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to [email protected].
>>
> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/elixir-lang-core/CAGnRm4Je5HVRyv8CCKjoTSOVsh7C9eVB7ZQa9WbNN2N7KaDBgQ%40mail.gmail.com
>>  
>> <https://groups.google.com/d/msgid/elixir-lang-core/CAGnRm4Je5HVRyv8CCKjoTSOVsh7C9eVB7ZQa9WbNN2N7KaDBgQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
>> .
>>
>
>
> -- 
> *Ulisses H. F. de Almeida*
>
> *[email protected][email protected]*
>

-- 
You received this message because you are subscribed to the Google Groups 
"elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elixir-lang-core/7bbbcba0-c85f-43d8-859f-62eb136c4110n%40googlegroups.com.

Reply via email to