commit ba171930670696153b7fcce8e2ba648a294d8425
Author: Juergen Spitzmueller <sp...@lyx.org>
Date:   Sun Sep 18 10:33:33 2016 +0200

    Improve info display for biblatex databases
    
    If an entry does not have a year field, check for a date field
    (the common type in biblatex databases) and extract the year(s).
    
    Candidate for branch.
---
 src/BiblioInfo.cpp |   22 ++++++++++++++++++++--
 1 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/src/BiblioInfo.cpp b/src/BiblioInfo.cpp
index af15760..c85eabd 100644
--- a/src/BiblioInfo.cpp
+++ b/src/BiblioInfo.cpp
@@ -316,8 +316,26 @@ docstring const BibTeXInfo::getAbbreviatedAuthor(
 
 docstring const BibTeXInfo::getYear() const
 {
-       if (is_bibtex_)
-               return operator[]("year");
+       if (is_bibtex_) {
+               // first try legacy year field
+               docstring year = operator[]("year");
+               if (!year.empty())
+                       return year;
+               // now try biblatex's date field
+               year = operator[]("date");
+               // Format is [-]YYYY-MM-DD*/[-]YYYY-MM-DD*
+               // We only want the years.
+               static regex const yreg("[-]?([\\d]{4}).*");
+               static regex const ereg(".*/([\\d]{4}).*");
+               smatch sm;
+               string const date = to_utf8(year);
+               regex_match(date, sm, yreg);
+               year = from_ascii(sm[1]);
+               // check for an endyear
+               if (regex_match(date, sm, ereg))
+                       year += char_type(0x2013) + from_ascii(sm[1]);
+               return year;
+       }
 
        docstring const opt = label();
        if (opt.empty())

Reply via email to