inveniosoftware / invenio

Invenio digital library framework
https://invenio.readthedocs.io
MIT License
616 stars 291 forks source link

formatter: error in with date anterior to 1900 #2673

Closed PXke closed 3 years ago

PXke commented 9 years ago

\ User details No client information available

\ Traceback details

Traceback (most recent call last): File "/usr/lib64/python2.7/site-packages/invenio/bibformat_engine.py", line 717, in eval_format_element output_text = function(*_params) File "/usr/lib64/python2.7/site-packages/invenio/bibformat_elements/bfe_meta.py", line 138, in format_element parsed_date = parse_date_for_googlescholar(out[idx]) File "/usr/lib64/python2.7/site-packages/invenio/bibformat_elements/bfe_meta.py", line 232, in parse_date_forgooglescholar return datetime((parsed_datetime[0:6])).strftime('%Y/%m/%d') ValueError: year=1488 is before 1900; the datetime strftime() methods require year >= 1900

jalavik commented 9 years ago

@PXke This is in fact a general Python issue with the datetime library. There exists workarounds for this in the datetime library in Invenio: https://github.com/inveniosoftware/invenio/blob/master/modules/miscutil/lib/dateutils.py#L69

To fix this, we can change the import in bfe_meta.py to use invenio.dateutils: https://github.com/inveniosoftware/invenio/blob/master/modules/bibformat/lib/elements/bfe_meta.py#L28

PXke commented 9 years ago

That would be really cool :) !

jalavik commented 9 years ago

Setting in triage, as this can be a discussion we can have if we should go over and amend this where needed.

PXke commented 9 years ago

up.

jirikuncar commented 9 years ago

@jalavik @PXke what is the desired milestone? Is there a related PR?

PXke commented 9 years ago

We have no PR for it. And no desired milestone for it. Even if like always earlier is better.

I upped it mainly because of the comment of @jalavik about that this can be a discussion.

tiborsimko commented 9 years ago

We have no PR for it. And no desired milestone for it. Even if like always earlier is better.

@PXke If your time permits, perhaps you could take care of this? Our own strftime is a drop-in replacement for the default system function, so it should be relatively straightforward to fix this.

E.g. here is good example from BibAuthorID:

$ git grep strftime modules/bibauthorid/lib/
modules/bibauthorid/lib/bibauthorid_webapi.py:from invenio.dateutils import strftime
modules/bibauthorid/lib/bibauthorid_webapi.py:    strtimestamp = strftime("%Y-%m-%d %H:%M:%S", gmtime())

One needs to amend bfe_meta.py and friends in a similar way...

jalavik commented 9 years ago

Yeah, basically one has to think about where to apply it. The obvious target is to address places like formatting (display/exporting) where we work with records which may have bibliographic metadata dates prior to 1900. As you can imagine, it is not needed to do anything in modules where it deals with dates that are not bibliographic metadata.

jirikuncar commented 9 years ago

@jalavik @egabancho we should then check JSONAlchemy fields definition for __import__('datetime').

tiborsimko commented 9 years ago

@PXke Would you like to have a go at this?

PXke commented 9 years ago

@tiborsimko it is a bit complicated, it will depend of a lot of things and @audub .

tiborsimko commented 9 years ago

OK. Let's keep you as the "driver" of this issue, until a new assignee comes, OK?

PXke commented 9 years ago

Yes no problem. If I have time I will do it :wink:

jalavik commented 9 years ago

@PXke Note that some work is already done in #2728