File tree 2 files changed +32
-4
lines changed
2 files changed +32
-4
lines changed Original file line number Diff line number Diff line change 11
11
from typing import Any , Dict , List , Optional
12
12
import uuid
13
13
14
+ import iso8601
14
15
from pybtex .database import Entry , Person
15
16
from pybtex .database .output .bibtex import Writer
16
17
from pybtex .plugin import register_plugin
@@ -130,10 +131,14 @@ def add_affiliations(person: rdflib.term.Node) -> None:
130
131
fields ["date" ] = date
131
132
break
132
133
if "date" in fields :
133
- (fields ["year" ], month_number , _ ) = fields ["date" ].split ("-" )
134
- fields ["month" ] = (
135
- f"{ MACRO_PREFIX } :{ calendar .month_abbr [int (month_number )].lower ()} "
136
- )
134
+ try :
135
+ parsed_date = iso8601 .parse_date (fields ["date" ])
136
+ fields ["year" ] = str (parsed_date .year )
137
+ fields ["month" ] = (
138
+ f"{ MACRO_PREFIX } :{ calendar .month_abbr [parsed_date .month ].lower ()} "
139
+ )
140
+ except iso8601 .ParseError :
141
+ pass
137
142
138
143
# identifier, doi, hal_id
139
144
entry_key = None
Original file line number Diff line number Diff line change @@ -276,6 +276,29 @@ def test_affiliation():
276
276
)
277
277
278
278
279
+ def test_invalid_date ():
280
+ assert codemeta_to_bibtex (
281
+ {
282
+ "@context" : "https://doi.org/10.5063/schema/codemeta-2.0" ,
283
+ "author" : {"name" : "Jane Doe" },
284
+ "name" : "Example Software" ,
285
+ "url" : "http://example.org/" ,
286
+ "datePublished" : "TBD" ,
287
+ "license" : "https://spdx.org/licenses/Apache-2.0" ,
288
+ }
289
+ ) == textwrap .dedent (
290
+ """\
291
+ @software{REPLACEME,
292
+ author = "Doe, Jane",
293
+ license = "Apache-2.0",
294
+ date = "TBD",
295
+ title = "Example Software",
296
+ url = "http://example.org/"
297
+ }
298
+ """
299
+ )
300
+
301
+
279
302
def test_cff_empty ():
280
303
assert cff_to_bibtex ("" ) == textwrap .dedent (
281
304
"""\
You can’t perform that action at this time.
0 commit comments