Skip to content

Handle Carbon 3 timestamp parsing and add boundary tests#1132

Open
dati18 wants to merge 7 commits into
mainfrom
carbon3-tests-update
Open

Handle Carbon 3 timestamp parsing and add boundary tests#1132
dati18 wants to merge 7 commits into
mainfrom
carbon3-tests-update

Conversation

@dati18
Copy link
Copy Markdown
Contributor

@dati18 dati18 commented May 19, 2026

  • MWTimestampHelperTest.php: Added coverage to ensure invalid MediaWiki timestamps are normalized into the helper’s expected InvalidFormatException behavior under Carbon 3.
  • SendEmptyWikiNotificationsJobTest.php: Tightened notification-threshold coverage so a wiki that is almost old enough (for example: 29.5 days old) does not trigger an empty-wiki notification early.
  • PlatformStatsSummaryJobTest.php: Added a test to ensure a second-precision lastEdit timestamp exactly at the inactivity cutoff is still counted as active.
  • ConversionMetricTest.php: Added a test to verify fractional day diffs are truncated to the integer values expected by the conversion metrics API.

Bug: T426592

@dati18 dati18 changed the title Handle Carbon 3 timestamp parsing and add boundary regression tests Handle Carbon 3 timestamp parsing and add boundary tests May 19, 2026
@dati18 dati18 force-pushed the carbon3-tests-update branch from 89a0590 to 069c041 Compare May 19, 2026 16:13
public static function getCarbonFromMWTimestamp(string $MWTimestamp): CarbonImmutable {
$carbon = CarbonImmutable::createFromFormat(self::MWTimestampFormat, $MWTimestamp);
if ($carbon === null) {
try {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm a bit unclear about this part.

  1. since Carbon 3 will throw an exception when createFormFormat, I'm not certain it helps to catch it just so we can throw our own. This could even make it harder to spot the reason for why it failed.
  2. the second check also seems obsolete since we either get a CarbonImmutable or an Exception gets thrown

So I think this method could be as simple as just line 19 - if something goes wrong an exception gets thrown as it used to. Is there more context for this additional logic that I'm not aware of?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

you're right to question it, it's an overthinking part from me. My logic is createFromFormat() may throw a non-instance (null/false), so an extra instanceof guard prevents type error when returning $carbon.


public function testGetCarbonFromMWTimestampWithInvalidTimestamp() {
$this->expectException(InvalidFormatException::class);
$this->expectExceptionMessage('Unable to create Carbon object');
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

As line 21 is expecting the Exception already, I struggle to see how this check helps us

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I just want to lock down the exact error message. a bit redundant, yes... WHat do you think? keep it or remove it?

@deer-wmde
Copy link
Copy Markdown
Contributor

The tighter tests look good to me overall
I left some comments on the Timestamp Helper

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.

2 participants