@@ -43,7 +43,7 @@ class Publication:
4343 }
4444
4545 def __init__ (self , title = None , instance_of = None , subtitle = None , authors = None ,
46- publication_date = None , original_language_of_work = None ,
46+ publication_date = None , publication_date_precision = None , original_language_of_work = None ,
4747 published_in_issn = None , published_in_isbn = None ,
4848 volume = None , issue = None , pages = None , number_of_pages = None , cites = None ,
4949 editor = None , license = None , full_work_available_at = None , language_of_work_or_name = None ,
@@ -105,6 +105,7 @@ def __init__(self, title=None, instance_of=None, subtitle=None, authors=None,
105105 self ._authors = authors
106106 self .title = title
107107 self .publication_date = publication_date
108+ self .publication_date_precision = publication_date_precision
108109 self .volume = volume
109110 self .issue = issue
110111 self .pages = pages
@@ -234,8 +235,8 @@ def set_label(self, item):
234235 def set_description (self , item ):
235236 # item is a WDItemEngine
236237 if item .get_description () == "" and self .publication_date :
237- item .set_description ("{} published on {}" .format (self .instance_of .replace ("_" , " " ),
238- self .publication_date .strftime ("%d %B % Y" )))
238+ item .set_description ("{} published in {}" .format (self .instance_of .replace ("_" , " " ),
239+ self .publication_date .strftime ("%Y" )))
239240 elif item .get_description () == "" :
240241 item .set_description ("{}" .format (self .instance_of .replace ("_" , " " )))
241242
@@ -248,8 +249,18 @@ def make_statements(self):
248249
249250 if self .publication_date :
250251 date = self .publication_date .strftime ("+%Y-%m-%dT00:00:00Z" )
251- self .statements .append (
252- wdi_core .WDTime (date , PROPS ['publication date' ], references = [self .reference ]))
252+ if self .publication_date_precision == "year" :
253+ self .statements .append (
254+ wdi_core .WDTime (date , PROPS ['publication date' ], precision = 9 , references = [self .reference ] )
255+ )
256+ elif self .publication_date_precision == "month" :
257+ self .statements .append (
258+ wdi_core .WDTime (date , PROPS ['publication date' ], precision = 10 , references = [self .reference ])
259+ )
260+ else :
261+ self .statements .append (
262+ wdi_core .WDTime (date , PROPS ['publication date' ], references = [self .reference ]))
263+
253264 if self .published_in_qid :
254265 self .statements .append (
255266 wdi_core .WDItemID (self .published_in_qid , PROPS ['published in' ], references = [self .reference ]))
@@ -331,10 +342,12 @@ def crossref_api_to_publication(ext_id, id_type="doi"):
331342 # p.publication_date = datetime.datetime.fromtimestamp(int(r['created']['timestamp']) / 1000)
332343 year = r ['issued' ]['date-parts' ][0 ][0 ]
333344 if len (r ['issued' ]['date-parts' ][0 ]) == 1 :
334- p .publication_date = datetime .datetime (year = year )
345+ p .publication_date = datetime .datetime (year = year , month = 7 , day = 2 ) # middle of the year is July 2nd
346+ p .publication_date_precision = "year"
335347 if len (r ['issued' ]['date-parts' ][0 ]) == 2 :
336348 month = r ['issued' ]['date-parts' ][0 ][1 ]
337- p .publication_date = datetime .datetime (year = year , month = month )
349+ p .publication_date = datetime .datetime (year = year , month = month , day = 15 ) # middle of the month is the 15th
350+ p .publication_date_precision = "month"
338351 if len (r ['issued' ]['date-parts' ][0 ]) == 3 :
339352 day = r ['issued' ]['date-parts' ][0 ][2 ]
340353 month = r ['issued' ]['date-parts' ][0 ][1 ]
0 commit comments