Skip to content

Implement system macro make_timestamp #988

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

nirosys
Copy link
Contributor

@nirosys nirosys commented Jul 10, 2025

Issue #, if available: #942 (and a little of #970)

Description of changes:
This PR implements the make_timestamp system macro. It's a bigger PR than I really wanted, but I also wanted something to handle the timestamp builder a little better.

There are a few changes in here that are not directly related to make_timestamp, but do get used in the implementation:

  • Added an implementation of Sub for Decimal. I originally added this thinking some arithmetic operations on Decimals would make handling the fractional second Decimal nicer. Ultimately I didn't use it.
  • I added fract and trunc to Decimal to handle extracting the whole and fractional values from the decimal. This mirrors the floating point types in Rust.
  • I extended the SystemMacroArguments type to be a little more generic. It takes a generic argument that is AsRef<str>, which lets you provide a type that can be used to return a &str for the parameter name. In the make_timestamp implementation this is used to provide an enum that can be used to provide both the argument's position, as well as the name. Right now the only 2 implementations that are using it are make_decimal and make_timestamp, so it seems a bit overkill, but I'll circle back around and revisit the other system macros where it could be used.

The TimestampBuilderWrapper type that I'm using to handle the changing TimestampBuilder types adds a lot of bulk to the diff and I'm not too thrilled about that.

Conformance Test

Conformance tests for make_timestamp are passing:

Running tests: ion-tests/conformance/system_macros/make_timestamp.ion
  make_timestamp can be invoked                                          ...  [Ok]
  make_timestamp produces a single, unannotated timestamp                ...  [Ok]
  the arguments may have annotations, which are silently dropped         ...  [Ok]
  the year argument                                                      ...  [Ok]
  the month argument                                                     ...  [Ok]
  the day argument                                                       ...  [Ok]
  the hour argument                                                      ...  [Ok]
  the minute argument                                                    ...  [Ok]
  the hour and minute arguments are encoded in binary as tagged values   ...  [Ok]
  the seconds argument                                                   ...  [Ok]
  the offset argument                                                    ...  [Ok]

CLI

I have a local edit of the ion-cli to work with ion-rust HEAD. So I've been able to test the newer system macros that weren't part of rc6:

echo '$ion_1_1 (:make_timestamp 1 2 3 4 5 6.05 272)' | target/release/ion dump
0001-02-03T04:05:06.05+04:32

This has been super helpful.


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Copy link

codecov bot commented Jul 10, 2025

Codecov Report

Attention: Patch coverage is 86.79245% with 35 lines in your changes missing coverage. Please review.

Project coverage is 78.55%. Comparing base (79d6e05) to head (75aaeb0).

Files with missing lines Patch % Lines
src/lazy/expanded/macro_evaluator.rs 86.49% 7 Missing and 25 partials ⚠️
src/types/decimal/mod.rs 92.00% 2 Missing ⚠️
src/lazy/expanded/template.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #988      +/-   ##
==========================================
+ Coverage   78.47%   78.55%   +0.08%     
==========================================
  Files         138      138              
  Lines       33385    33636     +251     
  Branches    33385    33636     +251     
==========================================
+ Hits        26198    26422     +224     
- Misses       5179     5185       +6     
- Partials     2008     2029      +21     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@nirosys nirosys marked this pull request as ready for review July 10, 2025 20:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant