Skip to content

Add round-trip and leap-year coverage tests for DateTimeConverter (pre/post 1970)#135

Open
Rutuja-Patil-Bosch wants to merge 32 commits into
eclipse-score:mainfrom
bgsw-contrib:main
Open

Add round-trip and leap-year coverage tests for DateTimeConverter (pre/post 1970)#135
Rutuja-Patil-Bosch wants to merge 32 commits into
eclipse-score:mainfrom
bgsw-contrib:main

Conversation

@Rutuja-Patil-Bosch
Copy link
Copy Markdown
Contributor

@Rutuja-Patil-Bosch Rutuja-Patil-Bosch commented Apr 1, 2026

Summary

This PR extends unit test coverage for DateTimeConverter along with necessary code change by adding round-trip validation and additional leap-year scenarios, especially around pre-1970 and post-1970 boundaries.

Changes

  • Updated code to get correct values for date & time.
  • Added round-trip test validation:
    • epoch → DateTime → epoch consistency checks
  • Added test coverage for:
    • Pre-1970 leap year (1968)
    • Post-1970 leap year (1972)
  • Included full month/day sweeps to validate:
    • Leap day handling (Feb 29)
    • Month boundary correctness
    • Internal day-sum adjustments

Motivation

The added tests ensure correctness of:

  • Leap year handling logic
  • Edge cases around Unix epoch (1970)
  • Internal date-to-epoch conversion consistency

This improves confidence in DateTimeConverter for:

  • Historical timestamps (pre-1970)
  • Leap year transitions
  • Boundary conditions in conversion logic

Notes

  • Invalid dates are skipped during iteration
  • Focus is on ensuring no regression in conversion logic
  • No production code changes included

Test Scope

  • Covers both:
    • 'dateTimeToEpoch'
    • 'epochToDateTime'
  • Validates bidirectional consistency

Impact

  • Increased unit test coverage
  • Better validation of edge cases and leap-year logic
  • No impact on runtime behavior

Rutuja-Patil-Bosch and others added 3 commits March 24, 2026 14:04
…lse_isValidDateTimeFormat EpochToDateTime_Before1970_LeapYear_January_AdjustsDaysSum invalid_day_values invalid_month_values
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 1, 2026

The created documentation from the pull request is available at: docu-html

Comment thread score/datetime_converter/datetime_converter_test.cpp Outdated
Comment thread score/datetime_converter/datetime_converter_test.cpp Outdated
Comment thread score/datetime_converter/datetime_converter_test.cpp Outdated
Comment thread score/datetime_converter/datetime_converter_test.cpp Outdated
Comment thread score/datetime_converter/datetime_converter_test.cpp Outdated
Comment thread score/datetime_converter/datetime_converter_test.cpp Outdated
Comment thread score/datetime_converter/datetime_converter_test.cpp Outdated
Comment thread score/datetime_converter/datetime_converter_test.cpp Outdated
Comment thread score/datetime_converter/datetime_converter_test.cpp Outdated
@bgsw-contrib bgsw-contrib Bot had a problem deploying to workflow-approval April 8, 2026 00:23 Failure
@bgsw-contrib bgsw-contrib Bot had a problem deploying to workflow-approval April 8, 2026 00:23 Failure
@AlexanderLanin
Copy link
Copy Markdown
Member

@Rutuja-Patil-Bosch please avoid bot based commits. Feel free to contact me directly.

@bgsw-contrib bgsw-contrib Bot had a problem deploying to workflow-approval April 9, 2026 00:19 Failure
@bgsw-contrib bgsw-contrib Bot had a problem deploying to workflow-approval April 9, 2026 00:19 Failure
@4og 4og mentioned this pull request Apr 9, 2026
@bgsw-contrib bgsw-contrib Bot temporarily deployed to workflow-approval April 10, 2026 00:22 Inactive
@bgsw-contrib bgsw-contrib Bot temporarily deployed to workflow-approval April 10, 2026 00:22 Inactive
@bgsw-contrib bgsw-contrib Bot temporarily deployed to workflow-approval May 14, 2026 00:36 Inactive
@4og
Copy link
Copy Markdown
Member

4og commented May 15, 2026

@gierer, please have a look at this PR

@4og 4og added the comp-datetime Related to score/datetime_converter component label May 15, 2026
@bgsw-contrib bgsw-contrib Bot requested a deployment to workflow-approval May 16, 2026 00:32 Waiting
@bgsw-contrib bgsw-contrib Bot requested a deployment to workflow-approval May 16, 2026 00:32 Waiting
Comment thread score/datetime_converter/datetime_converter_test.cpp Outdated
Comment thread score/datetime_converter/datetime_converter_test.cpp Outdated
Comment thread score/datetime_converter/datetime_converter_test.cpp Outdated
Comment thread score/datetime_converter/datetime_converter_test.cpp Outdated
Comment thread score/datetime_converter/datetime_converter_test.cpp Outdated
@bgsw-contrib bgsw-contrib Bot temporarily deployed to workflow-approval May 22, 2026 00:37 Inactive
@bgsw-contrib bgsw-contrib Bot temporarily deployed to workflow-approval May 22, 2026 00:37 Inactive
@4og 4og requested review from Copilot and removed request for LittleHuba, castler, hoe-jo, nradakovic and ramceb May 22, 2026 20:31
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds additional unit tests for score::common::DateTimeConverter to increase coverage around invalid date inputs and leap-year / pre-/post-1970 conversion edge cases.

Changes:

  • Added tests for invalid month/day values in isValidDateTimeFormat.
  • Added a test ensuring dateTimeToEpoch returns false and does not mutate the output epoch when the input is invalid.
  • Added a few DateTime→epoch→DateTime “round-trip” tests targeting 1968 and 1972 leap-year boundaries.
Comments suppressed due to low confidence (3)

score/datetime_converter/datetime_converter_test.cpp:526

  • Same issue here: the test returns early if dateTimeToEpoch fails, which makes the test pass without validating anything. Use an assertion so failures are visible and the remainder of the test always executes when appropriate.
    time_t epoch{};
    auto dateTimeOriginal =
        std::make_shared<DateTimeType>(1972, 12, 31, 0, 0, 1);
		
    if (!score::common::dateTimeToEpoch(dateTimeOriginal, &epoch))
        return;
		
    auto dateTimeConverted = score::common::epochToDateTime(epoch);

score/datetime_converter/datetime_converter_test.cpp:530

  • The assertion expects the year to change from 1972 to 1973 after a DateTime→epoch→DateTime round-trip, which contradicts the test description (“remain unchanged”) and will lock in incorrect behavior. The round-trip expectation should match the original datetime fields.
    auto dateTimeConverted = score::common::epochToDateTime(epoch);
    ASSERT_NE(dateTimeConverted, nullptr);
	//After  1970 year is adjusted based on daysome
    ASSERT_EQ(dateTimeConverted->m_year, 1973); 
    

score/datetime_converter/datetime_converter_test.cpp:546

  • This test expects epochToDateTime to return nullptr for a valid date (1968-01-01) even though dateTimeToEpoch succeeded, which would encode a conversion bug rather than catch it. If this is intended behavior, it should be documented at the API level; otherwise the test should assert that the round-trip returns a valid DateTime equal to the input.
    RecordProperty("Description",
        "Verify that conversion from DateTime to Epoch to DateTime for pre-1970 leap year boundary (1968-01-01) results in an invalid DateTime, returning nullptr due to daysSum adjustment.");
    RecordProperty("TestType", "requirements-based");
	
    time_t epoch{};
    auto d = std::make_shared<DateTimeType>(1968, 1, 1, 0, 0, 1);
    ASSERT_TRUE(score::common::dateTimeToEpoch(d, &epoch));
	
    auto dt = score::common::epochToDateTime(epoch);
	//InvalidDateTimeFormat due to day some adjustment & returns nullptr
    EXPECT_EQ(dt, nullptr);
}

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +503 to +508
time_t epoch{};
auto dateTimeOriginal =
std::make_shared<DateTimeType>(1968, 12, 31, 0, 0, 1);
if (!score::common::dateTimeToEpoch(dateTimeOriginal, &epoch))
return;
auto dateTimeConverted = score::common::epochToDateTime(epoch);
Comment on lines +504 to +511
auto dateTimeOriginal =
std::make_shared<DateTimeType>(1968, 12, 31, 0, 0, 1);
if (!score::common::dateTimeToEpoch(dateTimeOriginal, &epoch))
return;
auto dateTimeConverted = score::common::epochToDateTime(epoch);
ASSERT_NE(dateTimeConverted, nullptr);
ASSERT_EQ(dateTimeConverted->m_year, 1968);
}
Comment on lines +528 to +545
//After 1970 year is adjusted based on daysome
ASSERT_EQ(dateTimeConverted->m_year, 1973);

}

TEST_F(DateTimeConverterTest, EpochToDateTime_Pre1970_LeapYear_Jan1_InvalidConversion_ReturnsNull)
{
RecordProperty("Description",
"Verify that conversion from DateTime to Epoch to DateTime for pre-1970 leap year boundary (1968-01-01) results in an invalid DateTime, returning nullptr due to daysSum adjustment.");
RecordProperty("TestType", "requirements-based");

time_t epoch{};
auto d = std::make_shared<DateTimeType>(1968, 1, 1, 0, 0, 1);
ASSERT_TRUE(score::common::dateTimeToEpoch(d, &epoch));

auto dt = score::common::epochToDateTime(epoch);
//InvalidDateTimeFormat due to day some adjustment & returns nullptr
EXPECT_EQ(dt, nullptr);
Comment on lines +522 to +530

if (!score::common::dateTimeToEpoch(dateTimeOriginal, &epoch))
return;

auto dateTimeConverted = score::common::epochToDateTime(epoch);
ASSERT_NE(dateTimeConverted, nullptr);
//After 1970 year is adjusted based on daysome
ASSERT_EQ(dateTimeConverted->m_year, 1973);

Comment on lines +498 to +535
TEST_F(DateTimeConverterTest, EpochToDateTime_Pre1970_LeapYear_DaysSumDecrementedInJanuary)
{
RecordProperty("Description", "Verify that datetime values remain unchanged after roundtrip conversion (DateTime to Epoch to DateTime) for pre 1970 leap years.");
RecordProperty("TestType", "requirements-based");

time_t epoch{};
auto dateTimeOriginal =
std::make_shared<DateTimeType>(1968, 12, 31, 0, 0, 1);
if (!score::common::dateTimeToEpoch(dateTimeOriginal, &epoch))
return;
auto dateTimeConverted = score::common::epochToDateTime(epoch);
ASSERT_NE(dateTimeConverted, nullptr);
ASSERT_EQ(dateTimeConverted->m_year, 1968);
}

TEST_F(DateTimeConverterTest, EpochToDateTime_Post1970_LeapYear_DaysSumDecremented)
{
RecordProperty("Description",
"Verify that datetime values remain unchanged after roundtrip conversion (DateTime to Epoch to DateTime) for post-1970 leap years.");
RecordProperty("TestType", "requirements-based");

time_t epoch{};
auto dateTimeOriginal =
std::make_shared<DateTimeType>(1972, 12, 31, 0, 0, 1);

if (!score::common::dateTimeToEpoch(dateTimeOriginal, &epoch))
return;

auto dateTimeConverted = score::common::epochToDateTime(epoch);
ASSERT_NE(dateTimeConverted, nullptr);
//After 1970 year is adjusted based on daysome
ASSERT_EQ(dateTimeConverted->m_year, 1973);

}

TEST_F(DateTimeConverterTest, EpochToDateTime_Pre1970_LeapYear_Jan1_InvalidConversion_ReturnsNull)
{
RecordProperty("Description",
Comment on lines +498 to +502
TEST_F(DateTimeConverterTest, EpochToDateTime_Pre1970_LeapYear_DaysSumDecrementedInJanuary)
{
RecordProperty("Description", "Verify that datetime values remain unchanged after roundtrip conversion (DateTime to Epoch to DateTime) for pre 1970 leap years.");
RecordProperty("TestType", "requirements-based");

@bgsw-contrib bgsw-contrib Bot requested a deployment to workflow-approval May 23, 2026 00:36 Waiting
@bgsw-contrib bgsw-contrib Bot requested a deployment to workflow-approval May 23, 2026 00:36 Waiting
Rutuja-Patil-Bosch and others added 3 commits May 26, 2026 17:37
…c since daysSum is normalized later. Fixed off-by-one by changing >= to >. Removed related test cases.
Baselib ut code update & relavant test case changes

1. New common function (daysInMonth()) added to get total number of days in month. This will be used at multiple places in code.

2. epochToDateTime() api is update to get correct date time values as discussed in PR eclipse-score#135

3. Accordingly redundant test cases are removed & for updated code test cas has been added
@bgsw-contrib bgsw-contrib Bot temporarily deployed to workflow-approval May 29, 2026 00:40 Inactive
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

}

return true;
return (dateTime->m_day <= daysInMonth(dateTime->m_year, dateTime->m_month));
EXPECT_EQ(dateTimeConverted->m_second, 0);
}

TEST_F(DateTimeConverterTest, EpochToDateTime_Pre1800_ReturnsNull)
namespace common
{

std::int8_t daysInMonth(const std::int16_t year, const std::int8_t month)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-datetime Related to score/datetime_converter component

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

6 participants