Page MenuHomePhabricator

Timestamp.fromtimestampformat() class method is failing
Open, HighPublicBUG REPORT

Description

Steps to replicate the issue:
Having a timestamp without seconds e.g. from a discussion thread timestamp Timestamp.fromtimestampformat() raises a ValueError:

from pywikibot import Timestamp as ts
ts.fromtimestampformat('202209151941')

What happens?:

Traceback (most recent call last):
  File "<pyshell#5>", line 1, in <module>
    ts.fromtimestampformat('202209151941')
  File "D:\pwb\GIT\core\pywikibot\time.py", line 263, in fromtimestampformat
    return cls._from_mw(ts)
  File "D:\pwb\GIT\core\pywikibot\time.py", line 122, in _from_mw
    raise ValueError(msg.format(timestr=timestr))
ValueError: time data '202209151941' does not match MW format.

What should have happened instead?:

from pywikibot import Timestamp as ts
ts.fromtimestampformat('202209151941')
Timestamp(2022, 9, 15, 19, 41, 0)

Software version:
Pywikibot 7.5+
rPWBC8455a65

Event Timeline

Xqt triaged this task as High priority.Nov 26 2022, 4:30 PM
Xqt changed the task status from Open to In Progress.Nov 27 2022, 9:38 AM
Xqt claimed this task.

The old implementation also failed by giving a wrong result.

Change 860978 had a related patch set uploaded (by Xqt; author: Xqt):

[pywikibot/core@master] [IMPR] create a timestamp even if hours, minutes or seconds are missing

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

Weird.
Could you give an example where MW outputs a timestamp on 12 digits?

See https://www.mediawiki.org/wiki/Manual:WfTimestamp

Pppery changed the task status from In Progress to Open.Apr 2 2024, 11:46 PM
Pppery edited projects, added Patch-Needs-Improvement; removed Patch-For-Review.