Support integer parts-per-second time unit#2227
Open
petermm wants to merge 2 commits into
Open
Conversation
dad612d to
1f640b2
Compare
0303a59 to
4dff77a
Compare
4dff77a to
b5006b8
Compare
b5006b8 to
fe55a5f
Compare
bettio
requested changes
Jun 8, 2026
bettio
left a comment
Collaborator
There was a problem hiding this comment.
tests are not working on the BEAM, let's fix this first.
log from run-tests:
datetime:OK
Raised {badmatch,fail}, stacktrace:
[{test_system_time,test_bad_integer_unit_universal_time,0,
[{file,"/__w/AtomVM/AtomVM/tests/erlang_tests/test_system_time.erl"},
{line,259}]},
{test_system_time,start,0,
[{file,"/__w/AtomVM/AtomVM/tests/erlang_tests/test_system_time.erl"},
{line,45}]},
{erl_eval,do_apply,7,[{file,"erl_eval.erl"},{line,915}]},
{erl_eval,try_clauses,10,[{file,"erl_eval.erl"},{line,1233}]},
{erl_eval,expr,6,[{file,"erl_eval.erl"},{line,663}]},
{erl_eval,exprs,6,[{file,"erl_eval.erl"},{line,271}]},
{init,start_it,1,[]},
{init,start_em,1,[]}]
test_system_time:
test_system_time:FAILED
Contributor
Author
|
thank you, shall blame the CI blunder on it being backed up;-) let me know if a squash is needed. |
f713183 to
c817ad6
Compare
This comment was marked as outdated.
This comment was marked as outdated.
bettio
requested changes
Jun 9, 2026
bettio
left a comment
Collaborator
There was a problem hiding this comment.
Just a couple of minor fixes. Feel free to cleanup PR history and push it for merge.
4c19344 to
df30d10
Compare
69a2fdd to
b751fb0
Compare
…bounds - Add support for integer parts-per-second time units (e.g. 1_000_000 for microseconds) - Refactor time-unit conversion into shared helper functions - Harden calendar and integer time unit conversion bounds - Fix input validation and negative rounding in calendar:system_time_to_universal_time/2 - Ensure BEAM compatibility for monotonic_time and system_time tests - Use AVM_INT range for calendar year and add year boundary tests Signed-off-by: Peter M <petermm@gmail.com>
b751fb0 to
18642d9
Compare
Reserve heap space for calendar years that exceed the immediate integer range and construct them as boxed integers. This prevents malformed year terms on 32-bit builds while preserving support for representable large dates. Add a regression test that crosses the 32-bit small-integer boundary and remains portable to platforms with limited time_t or gmtime_r ranges. Signed-off-by: Peter M <petermm@gmail.com>
Contributor
Author
|
Hit some complexities - namely OTP only support "extreme" values in calendar since OTP29 - erlang/otp#10449 then further complexities around negative numbers, what esp32/newlib uses, and some theoretical issues for years +-134 millions and beyond on some 32bit system :/ time is always fun, should be ready now. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add support for positive integer time units ("parts per second") in erlang:monotonic_time/1, erlang:system_time/1, and calendar:system_time_to_universal_time/2.
Used in elixir DynamicSupervisor - completes the timeunit support.
Restrict integer-unit handling to int64 inputs in the affected NIF paths. Use checked int64 decomposition for monotonic/system time conversion to avoid signed overflow in intermediate arithmetic. For calendar integer units, floor negative fractional values to whole seconds before converting to UTC.
Add focused Erlang tests for integer-unit parity, badarg on non-positive integer units, and negative fractional calendar conversion for integer units.
These changes are made under both the "Apache 2.0" and the "GNU Lesser General
Public License 2.1 or later" license terms (dual license).
SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later