"Date Modified" problem

edited September 19, 2018
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?
  • No response for a week...any ideas on this?
  • (They're all "attachments" in Zotero parlance, by the way.)

    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.
  • I think I get it now. The documentation is confusing about file names/items. You seem to be saying that if I drag-and-drop a file from another window into the middle pane, that what I see created is an 'attachment item', and that is different than the actual file?

    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?
  • Hello -

    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.
  • I have this problem as well. I was able to create a script to change the date but I can't figure out how to access the File's modified Date which does display in the file header information in Zotero's right pane. I found that to be a little confusing as well.

    Can someone tell me what the name of that field is in Zotero
  • 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.
    There's no chance we'd do this, even as an option. There's no reason to think that the modification time of a downloaded file has any relation to the publication date of the item it represents.

    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.
    Can someone tell me what the name of that field is in Zotero
    attachmentModificationTime is the file mtime in milliseconds
  • Hello again. Thanks for the response dstillman. I have not been able to get a script to run successfully. What I would like to do is change the Date Modified of the attached file in the middle pane to reflect the file's date modified displayed in the Item Pane on the right.

    I 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});
  • edited December 23, 2020
    You shouldn't be running code in this window without verifying each step — e.g., by confirming that a value is the value you expect before passing it into a data-modifying function. You'll damage your library. Zotero code is reasonably defensive, but the Run JavaScript window provides absolutely no protections against anything the code allows.

    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 requires await. getField() on an invalid field returns an empty string, so dte is an empty string. toLocaleString() is defined on Object in JS and isn't overridden on String, so it's a no-op. So d here is just an empty string, which isn't a valid value for dateModifed.

    var items = ZoteroPane.getSelectedItems();
    var d = new Date(await items[0].attachmentModificationTime);
    return Zotero.Date.dateToSQL(d);
  • @dstillman, Thank you for the explanation. I was able to run the above code and the date/time display correctly in the return value window. But when I assign the value in 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:05

    item.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:05

    I have not been able to find a way to resolve the time discrepancy. Are there any suggestions?

    Thank you.
  • edited January 28, 2021
    dateAdded and dateModified are UTC. You can use Zotero.Date.dateToSQL(d, true) to create UTC dates.
Sign In or Register to comment.