Use correct time-zone offset for access dates in bibliographies
Fixes #1069
This commit is contained in:
parent
5abae48af2
commit
9c0f5998a3
2 changed files with 35 additions and 0 deletions
|
@ -1675,6 +1675,16 @@ Zotero.Utilities = {
|
|||
}
|
||||
|
||||
if(date) {
|
||||
// Convert UTC timestamp to local timestamp for access date
|
||||
if (CSL_DATE_MAPPINGS[variable] == 'accessDate') {
|
||||
// Accept ISO date
|
||||
if (Zotero.Date.isISODate(date) && !Zotero.Date.isSQLDate(date)) {
|
||||
let d = Zotero.Date.isoToDate(date);
|
||||
date = Zotero.Date.dateToSQL(d, true);
|
||||
}
|
||||
let localDate = Zotero.Date.sqlToDate(date, true);
|
||||
date = Zotero.Date.dateToSQL(localDate);
|
||||
}
|
||||
var dateObj = Zotero.Date.strToDate(date);
|
||||
// otherwise, use date-parts
|
||||
var dateParts = [];
|
||||
|
|
|
@ -366,6 +366,31 @@ describe("Zotero.Utilities", function() {
|
|||
assert.deepEqual(cslCreators[4], creators[4].expect, 'institutional author is not parsed');
|
||||
assert.deepEqual(cslCreators[5], creators[5].expect, 'protected last name prevents parsing');
|
||||
});
|
||||
|
||||
it("should convert UTC access date to local time", async function () {
|
||||
var offset = new Date().getTimezoneOffset();
|
||||
var item = new Zotero.Item('webpage');
|
||||
var localDate;
|
||||
if (offset < 0) {
|
||||
localDate = '2019-01-09 00:00:00';
|
||||
}
|
||||
else if (offset > 0) {
|
||||
localDate = '2019-01-09 23:59:59';
|
||||
}
|
||||
// Can't test timezone offset if in UTC
|
||||
else {
|
||||
this.skip();
|
||||
return;
|
||||
}
|
||||
var utcDate = Zotero.Date.sqlToDate(localDate);
|
||||
item.setField('accessDate', Zotero.Date.dateToSQL(utcDate, true));
|
||||
await item.saveTx();
|
||||
let accessed = Zotero.Utilities.itemToCSLJSON(item).accessed;
|
||||
|
||||
assert.equal(accessed['date-parts'][0][0], 2019);
|
||||
assert.equal(accessed['date-parts'][0][1], 1);
|
||||
assert.equal(accessed['date-parts'][0][2], 9);
|
||||
});
|
||||
});
|
||||
describe("itemFromCSLJSON", function () {
|
||||
it("should stably perform itemToCSLJSON -> itemFromCSLJSON -> itemToCSLJSON", function* () {
|
||||
|
|
Loading…
Add table
Reference in a new issue