Page MenuHomePhabricator

add WbTime.today() to pywikibot
Closed, ResolvedPublic

Description

Method for turning todays date into a WbTime. This is used whenever setting fetch dates etc. for references.

Something like:

def today_as_WbTime():
    """Get todays date as a WbTime object.

    @return: Todays date correctly formated
    @rtype: pywikibot.WbTime
    """
    today = datetime.today()
    date = pywikibot.WbTime(year=today.year,
                            month=today.month,
                            day=today.day)
    return date

Related Objects

Event Timeline

Alternatively instead of sticking this in __-init.py__.WbTime it could go inte some helper class... if someone can recommedn a good place.

Couldn't Timestamp be used for that?

True if we introduce a fromTimestamp() to __-init.py__.WbTime which goes from (possibly both ways) pywikibot.Timestamp to WbTime

then:
today = pywikibot.WbTime.fromTimestamp(pywikibot.Timestamp.today()) should do it.

techically this can be done already using
today = pywikibot.WbTime.fromTimestr(pywikibot.Timestamp.today().isoformat()) but I think it would make sense to have a converter to go from one of our time formats to the other.

Where do we need to use this today value in wikidata? i.e. What is an example use for this, in a statement for which property?

Any time a statement is sourced/referenced using a web page accessed during the run (i.e. P813). I.e. essentially any bot which adds references.

Change 281301 had a related patch set uploaded (by Lokal Profil):
Make WbTime from Timestamp and vice versa

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

Found the open patchset related to this. There is still a need for it and the patch should still be mergeable (I just rebased it).

If someone would be willing to review or argue for why it isn't needed.

Thanks for the feedback @jayvdb I've implemented the suggestions in a new patch-set.

Xqt claimed this task.
Xqt triaged this task as High priority.

Change 281301 merged by jenkins-bot:
[pywikibot/core@master] Make WbTime from Timestamp and vice versa

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