Page MenuHomePhabricator

Improve handling of invalid offsets in UserTimeCorrection
Closed, ResolvedPublic

Description

As noted in T318455#8301251, UserTimeCorrection::parse silently clamps offsets between -12 and +14, without saying anything to its callers (and thus, to users). This should be changed so that invalid values can be handled as appropriate, e.g. by informing the user that they entered an invalid value.

Event Timeline

matmarex subscribed.

This annoys me, I hope you don't mind reviewing a patch.

Sure, it annoys me as well, so I'll definitely review it. We would also benefit from proper error handling in CampaignEvents.

Change 840309 had a related patch set uploaded (by Bartosz Dziewoński; author: Bartosz Dziewoński):

[mediawiki/core@master] preferences: Show errors about invalid timezone instead of silently correcting

https://gerrit.wikimedia.org/r/840309

Change 840309 merged by jenkins-bot:

[mediawiki/core@master] preferences: Show errors about invalid timezone instead of silently correcting

https://gerrit.wikimedia.org/r/840309

Func subscribed.

We would also benefit from proper error handling in CampaignEvents.

Then I think the validation should happen in HTMLTimezoneField::validate() instead of validation-callback for user preferences only.

Commit d716fee for CampaignEvents extension added more validations, do we need that in core?

We would also benefit from proper error handling in CampaignEvents.

Then I think the validation should happen in HTMLTimezoneField::validate() instead of validation-callback for user preferences only.

Sounds reasonable.

Commit d716fee for CampaignEvents extension added more validations, do we need that in core?

I would say yes

Change 881381 had a related patch set uploaded (by Func; author: Func):

[mediawiki/core@master] Move validation of timezone to HTMLTimezoneField

https://gerrit.wikimedia.org/r/881381

Commit d716fee for CampaignEvents extension added more validations, do we need that in core?

I would say yes

I tested the given cases manually, and all of them can be identified as invalid correctly by ( new UserTimeCorrection( $value ) )->isValid(), so I didn't include extra validations.

Commit d716fee for CampaignEvents extension added more validations, do we need that in core?

I would say yes

I tested the given cases manually, and all of them can be identified as invalid correctly by ( new UserTimeCorrection( $value ) )->isValid(), so I didn't include extra validations.

Right, because the code in CampaignEvents uses PHP's DateTimeZone directly. I think we *may* have to reconsider this as part of T322352, but that's for another day.

Change 881381 merged by jenkins-bot:

[mediawiki/core@master] Move validation of timezone to HTMLTimezoneField

https://gerrit.wikimedia.org/r/881381