maxlath/wikibase-sdk

Time helpers lose month info on month-precision values

noinkling opened this issue · 1 comments

Example: publication date (P577) claim on Q756866 (JSON) has "month" precision.

datavalue snippet:

{
  "value": {
    "time": "+1990-11-00T00:00:00Z",
    "timezone": 0,
    "before": 0,
    "after": 0,
    "precision": 10,
    "calendarmodel": "http://www.wikidata.org/entity/Q1985727"
  },
  "type": "time"
}

The month is being lost when using wikidataTimeToDateObject/EpochTime/ISOString, but the year stays correct:

> wdk.wikidataTimeToISOString(entity.claims.P577[0].mainsnak.datavalue.value)
'1990-01-01T00:00:00.000Z'

I'm aware that wikidataTimeToSimpleDay will handle it correctly, however sometimes it's just necessary to have a Date object/ISO string/Unix timestamp, even if they can't represent the precision.

The piece of code that seems to be responsible:
https://github.com/maxlath/wikidata-sdk/blob/96b9d15ae562e36458fca8e661840818a65e6d4b/lib/helpers/wikidata_time_to_date_object.js#L39-L45

I believe this issue only effects month-precision values, as day-precision values are already valid and will parse OK, and obviously years are already handled.

should be patched in v6.0.1, thanks for reporting!