"Date Modified" problem
When storing files as items (i.e. not as attachments), the "Date Modified" date shown in the middle panel column does not match the "Modified:" date shown in the info pane. The info pane one is correct, but the "Date Modified" date shows the date the file was first added (I think). Is this a know issue? Is there any way to fix this?
Date Modified in the middle pane is the date of the attachment item, not the file. We could consider showing the file modification time instead — it'd be fair to argue that that'd be more useful — but that's not what it's doing now.
If so, than I think that this behavior is really confusing. The documentation says "Zotero can also be used for managing files." But in other file managers, like the ones built into the OS, the filename and icon (what Zotero calls an 'attachment item') represents the file directly; it's not dealt with as a separate item with separate characteristics. In a file manager, 'date modified' means the date the file was modified. And 'size' means the size of the file, not the size of the 'item' pointing to the file.
I understand that Zotero allows different names for 'attachment items' and attachments, so I guess they could hypothetically have different modification times, but I'm not sure why its useful to allow that distinction. And I think there is little benefit to showing a user when the 'attachment item' was modified in the middle pane, but clear benefit to showing when the attachment was modified in the middle pane, so they don't have to click on the item to find out the last attachment modification date.
If you agree that date modified in the middle pane should reflect the time the file was modified, perhaps you could add as a ticket/suggestion?
I have this issue as well. It would be really useful to be able to choose a default behavior. For example, when adding a file attachment, I would like Zotero to use the date modified of the file as the Date value when creating parent items.
Is there any way to show the file attachment's date information in the middle pane?
Is there a way to search by the file attachment's date information?
Thank you.
Can someone tell me what the name of that field is in Zotero
The thing we might consider is using the file modification time as the Date Modified of the attachment item (and the creation time for Date Added on platforms where it's available), though there are performance concerns that make that not as straightforward as it might seem.
attachmentModificationTime
is the file mtime in millisecondsI do not know much about programming, but the example script below I attempted to repurpose from one that successfully updates date added from the date modified of the first attachment.
But this script produces an Error: Invalid SQL date: false. I have been trying to find a resolution on google, but I have not been able to convert the milliseconds into a format that will be accepted.
Can anyone help?
//Get Items
var zoteroPane = Zotero.getActiveZoteroPane();
var selected = zoteroPane.getSelectedItems();
//Iterate Selected Items
for (let item of selected) {
if (item.isRegularItem()) {
// Get 1st File Attachment
let attachmentIDs = item.getAttachments();
let att = Zotero.Items.get(attachmentIDs[0]);
if (att && !att.isNote()) {
var dte = att.getField('attachmentModificationTime');
var d = dte.toLocaleString("en-US");
item.setField('dateModified', d);
await item.save({skipDateModifiedUpdate: true});
}
}
};
If someone gives you a pointer to something, and there aren't examples on the API page, it means you should search through the existing codebase on GitHub to see how it's used or commented.
attachmentModificationTime
is a property, not a field name, and it returns a promise, so it requiresawait
.getField()
on an invalid field returns an empty string, sodte
is an empty string.toLocaleString()
is defined on Object in JS and isn't overridden on String, so it's a no-op. Sod
here is just an empty string, which isn't a valid value fordateModifed
.var items = ZoteroPane.getSelectedItems();
var d = new Date(await items[0].attachmentModificationTime);
return Zotero.Date.dateToSQL(d);
d
to the item's date Modified or Added the time is offset by -7 hours.For example: this date/time: 1/27/2021, 4:29:05 PM (the local time)
will display on the item as: 1/27/2021, 9:29:05 AM
d
returns "2021-01-27T23:29:05.914Z"Zotero.Date.dateToSQL(d);
returns 2021-01-27 16:29:05item.setField('dateModified', Zotero.Date.dateToSQL(d));
displays 1/27/2021, 9:29:05 AM on the item in the client, same for date added.assigning the same value to the "Date" field on the item shows the correct time
item.setField('date', Zotero.Date.dateToSQL(d));
displays 2021-01-27 16:29:05I have not been able to find a way to resolve the time discrepancy. Are there any suggestions?
Thank you.
dateAdded
anddateModified
are UTC. You can useZotero.Date.dateToSQL(d, true)
to create UTC dates.