Search code examples
wikipediawikipedia-apiwikidatawikidata-api

Understanding date precision on Wikidata date properties


The Wikidata API provides date-based fields as a datavalue$type == "time". For example consider Harvard Universities Inception Date (Property value == P571):

$mainsnak
$mainsnak$snaktype
[1] "value"

$mainsnak$property
[1] "P571"

$mainsnak$hash
[1] "5efb5e7d891727df657771128dcb0512f7f18e10"

$mainsnak$datavalue
$mainsnak$datavalue$value
$mainsnak$datavalue$value$time
[1] "+1636-01-01T00:00:00Z"

$mainsnak$datavalue$value$timezone
[1] 0

$mainsnak$datavalue$value$before
[1] 0

$mainsnak$datavalue$value$after
[1] 0

$mainsnak$datavalue$value$precision
[1] 9

$mainsnak$datavalue$value$calendarmodel
[1] "http://www.wikidata.org/entity/Q1985727"


$mainsnak$datavalue$type
[1] "time"


$mainsnak$datatype
[1] "time"


$type
[1] "statement"

$id
[1] "q13371$cf938885-4a4d-697c-a957-b2d7effe8bbb"

$rank
[1] "normal"

The mainsnak$datavalue$value$time is "+1636-01-01T00:00:00Z" which when parsed to a date is 1636-01-01. But on the webpage, the only the year is displayed:

enter image description here

I'm sure this is because the time accuracy is only as good as the year - Harvard was founded in 1636, the day and month are unknown/ambiguous/not relevant. So my question is how do I use the API to parse just the time accuracy of this date? I suspect it has something to do with $mainsnak$datavalue$value$precision

PS the full json from Wikidata for Harvard is pulled in R with:

library(tidyverse)
wikidata_id <- "Q13371"
res <- httr::GET(url = paste0('https://www.wikidata.org/wiki/Special:EntityData/',wikidata_id,'.json')) %>%
    httr::content() %>%
    .[['entities']] %>%
    .[[wikidata_id]]

Solution

  • Per https://www.wikidata.org/wiki/Help:Dates precision of 9 is year, 10 is month, 11 is day.