Skip to content

Conversation

@SATVIKsynopsis
Copy link

This PR adds a snapshot test for Date::try_add_with_options to ensure that date addition using DateDuration behaves as expected and produces stable results.

It is a clean recreation of the previous PR (#7221), which was linked to:

The earlier PR accidentally included unintended changes across many files after a rebase issue.
This one only contains the intended snapshot test additions under components/calendar/tests/.

@Manishearth
Copy link
Member

This still changes a lot of files that it shouldn't.

Please verify your PRs before making them.

Are you using AI to make these? I think we're giving you the same feedback multiple times.

@SATVIKsynopsis
Copy link
Author

The 3rd last commit which i did did all those changes you asked for perfectly. but then some workflows were failing. so I then again ran the commands and then did git add . for that purpose.

@SATVIKsynopsis
Copy link
Author

I see now - I will ensure my subsequent PRs only contain the file change that was intended.

I am not using AI to create code- but I have been learning and validating everything manually, using guidance to understand how to do that better.

I will tidy this up in due course and submit a more focused PR.

@Manishearth
Copy link
Member

Please use one PR instead of opening new PRs every time.

@SATVIKsynopsis
Copy link
Author

Thank you for your explanation!
From now on, I will keep updates within one PR and push commits there, instead of creating new PRs.
Thanks for clarifying this, as I will clean this branch and update the same PR.

@SATVIKsynopsis
Copy link
Author

SATVIKsynopsis commented Nov 7, 2025

I did a rebase onto the latest main branch and confirmed the only changes are in the snapshot test files under components/calendar/tests/. I also ran cargo fmt and clippy locally with no warnings.

The snapshot tests are working and are ready for review. Also, thanks for the feedback earlier — I've ensured this is PR is only on the tests I intended to cover.

@SATVIKsynopsis
Copy link
Author

Hi Manishearth
Thanks again for your earlier feedback — I’ve made sure this PR now only includes the necessary file changes and verified everything locally before pushing.

Just to clarify, I’m not using AI-generated code; I’ve been writing and testing these changes manually but was still learning the correct workflow for your repo.
I really appreciate your patience and guidance — it’s helped me understand how to structure contributions properly.

Copy link
Member

@Manishearth Manishearth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I would prefer the output snapshot to be a single file with all of the individual snapshots contained in it.

You can do this by collecting up a big string.

expression: "(format!(\"Start: {:?}-{:?}-{:?}\", y, m, d),\nformat!(\"Calendar: {:?}\", cal_kind),\nformat!(\"Duration added: {:?}\", duration),\nformat!(\"Resulting ISO date: {:?}\", result_iso))"
---
(
"Start: 2023-1-1",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggested format so that this fits in one line:

y-m-d (Buddhist) + DateDuration {....} = Date(y-m-d, ....)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Though I'm not sure if we should try and fit it on one line

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it — thank you for the suggestion

I’ll modify the test to collect all individual snapshot outputs into a single string and assert once, as you suggested.

I’ll also experiment with the one-line format you mentioned to see if it remains readable.

I’ll push the updated version shortly.

@SATVIKsynopsis
Copy link
Author

I combined all the earlier individual snapshot tests into a single, more readable snapshot that loops through multiple ISO dates, calendar types (Iso, Gregorian, Buddhist), and different duration combinations. I have also removed the old redundant snapshot files to keep the test cleaner and easier to maintain. Hope this resolves the issue.

let calendars = vec![
AnyCalendarKind::Iso,
AnyCalendarKind::Gregorian,
AnyCalendarKind::Buddhist,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue: please include all calendars here.

for (y, m, d) in &iso_dates {
for duration in &durations {
for cal_kind in &calendars {
let cal = AnyCalendar::new(*cal_kind);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is now just outputting a single file, instead of trying to collapse everything in one line, perhaps we can generate a nested list? Something like

  • 2025-12-31
    • Buddhist (Date (...))
      • add(DateDuration {...}): Date(...)
      • add(DateDuration {...}): Date(...)
      • add(DateDuration {...}): Date(...)
    • Iso
      • ...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we actually produce a nested list instead of syntax heavy output?

I want this to be relatively readable, this is currently very messy

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’ve reformatted the snapshot output into a nested list structure for better readability.

Each ISO start date now groups all calendars, and each calendar lists the durations and their resulting ISO dates in an indented format.

Hope this is the output you expected.

Copy link
Author

@SATVIKsynopsis SATVIKsynopsis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’ve restructured the test output to generate a nested snapshot format as suggested.

The results are now grouped by start date → calendar → applied durations, so it’s much easier to inspect the behavior across different calendars for each date.

This structure also keeps the snapshot compact while still covering all possible combinations.

date.try_add_with_options(*duration, opts)
.expect("Addition should succeed");

let result_iso = date.to_iso();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be outputting the result in that calendar, not in ISO.

writeln!(&mut output, "{}-{}-{}", y, m, d).unwrap();

for cal_kind in &calendars {
writeln!(&mut output, " {:?}", cal_kind).unwrap();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: let's compute date here and include it in the output, since the per-calendar date will be different

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’ve updated the test to output results in their respective calendars instead of converting to ISO. Each calendar section now includes both its localized starting date and all resulting dates within that same calendar.

Copy link
Member

@Manishearth Manishearth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this test looks better now.

Potentially would be nice to have a more compact representation of per-calendar dates instead of the Debug output but that's a change that can be figured out later.

@sffc are there cases you'd like to see covered here?

@SATVIKsynopsis
Copy link
Author

Glad the structure looks good now.
I agree, a more compact representation would make it cleaner once the API supports it. Happy to adjust that later when ready.

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.

Add snapshot test of Date add/until

2 participants