mirror of
https://github.com/zotero/zotero.git
synced 2026-08-28 05:25:31 +00:00
Support citing EDTF dates in the Date field and Extra
EDTF dates -- ranges ("2021/2026"), uncertain/approximate dates
("2004-06~"), and BCE dates ("-0429") -- and common equivalent notations
("1995-1996", "2021-22", "~1995", "ca. 1995", "429 BCE") are now passed
to citeproc-js as CSL date ranges, circa flags, and negative years.
Previously, such dates were mangled or dropped entirely unless entered as
CSL variables in Extra.
CSL date variables in Extra get the same parsing.
Other date handling in the client doesn't understand EDTF yet: the y/m/d
indicator in the date field doesn't reflect EDTF parsing, date searches
only match a range by its start date, and BCE dates still can't be
sorted.
Addresses #637
This commit is contained in:
parent
399a63ade2
commit
8ac1273acb
4 changed files with 49 additions and 1 deletions
|
|
@ -1 +1 @@
|
|||
Subproject commit 1dd38e27edf81e9d9c4161c957b7efb7f5681ac3
|
||||
Subproject commit 2b125a7a4b3e38cb6dcf8612dd2d351bafd112a8
|
||||
|
|
@ -38,6 +38,7 @@ const xpcomFilesAll = [
|
|||
'dataDirectory',
|
||||
'debug',
|
||||
'error',
|
||||
'utilities/edtf',
|
||||
'utilities/date',
|
||||
'utilities/utilities',
|
||||
'utilities/utilities_item',
|
||||
|
|
|
|||
|
|
@ -38,6 +38,35 @@ describe("Zotero.Cite", function () {
|
|||
});
|
||||
});
|
||||
|
||||
describe("EDTF dates", function () {
|
||||
async function makeBibliography(fields) {
|
||||
let item = new Zotero.Item;
|
||||
item.fromJSON(Object.assign({
|
||||
itemType: "book",
|
||||
title: "Test Book"
|
||||
}, fields));
|
||||
await item.saveTx();
|
||||
|
||||
let style = Zotero.Styles.get('http://www.zotero.org/styles/chicago-notes-bibliography');
|
||||
let cslEngine = style.getCiteProc('en-US');
|
||||
return Zotero.Cite.makeFormattedBibliographyOrCitationList(cslEngine, [item], "text");
|
||||
}
|
||||
|
||||
it("should render a date range", async function () {
|
||||
assert.include(await makeBibliography({ date: '2021/2026' }), '2021–2026');
|
||||
});
|
||||
|
||||
it("should render a BCE date", async function () {
|
||||
assert.match(await makeBibliography({ date: '-429' }), /429\s?BC/);
|
||||
});
|
||||
|
||||
it("should render an EDTF range in Extra, overriding the Date field", async function () {
|
||||
let output = await makeBibliography({ date: '1999', extra: 'issued: 2021/2026' });
|
||||
assert.include(output, '2021–2026');
|
||||
assert.notInclude(output, '1999');
|
||||
});
|
||||
});
|
||||
|
||||
describe("#retrieveLocale()", function () {
|
||||
it("should handle locale with script code", async function () {
|
||||
var item = new Zotero.Item;
|
||||
|
|
|
|||
|
|
@ -29,5 +29,23 @@ describe("Zotero.Utilities.Item", function () {
|
|||
|
||||
assert.deepEqual(fromZoteroItem, fromExportItem, 'conversion from Zotero Item and from export item are the same');
|
||||
});
|
||||
|
||||
it("should preserve EDTF ranges and circa dates from CSL JSON", function () {
|
||||
let item = new Zotero.Item('book');
|
||||
Zotero.Utilities.Item.itemFromCSLJSON(item, { type: 'book', issued: { "date-parts": [[2021], [2026]] } });
|
||||
assert.equal(item.getField('date'), '2021/2026');
|
||||
|
||||
item = new Zotero.Item('book');
|
||||
Zotero.Utilities.Item.itemFromCSLJSON(item, { type: 'book', issued: { "date-parts": [[-429]], circa: true } });
|
||||
assert.equal(item.getField('date'), '-0429~');
|
||||
});
|
||||
|
||||
it("should convert an EDTF date stored on an item", async function () {
|
||||
let item = new Zotero.Item('book');
|
||||
item.setField('date', '-429?');
|
||||
await item.saveTx();
|
||||
let cslItem = Zotero.Utilities.Item.itemToCSLJSON(item);
|
||||
assert.deepEqual(cslItem.issued, { "date-parts": [[-429]], circa: true });
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue