changing the date format

svs's Avatar

svs

29 Aug, 2018 03:42 PM

I'm using the following code from Voodoopad Page Events:

function pageWasCreated(document, item) {
    var attString = item.dataAsAttributedString();
    attString.mutableString().appendString("\nThis page was created on " + (new Date()));
    item.setDataWithAttributedString(attString);
}

However, this produces:

This page was created on Wed Aug 29 2018 16:33:02 GMT+0100 (BST)

I want to change the date format to:

This page was created on Wed Aug 29 2018 16:33:02

How do I change this?

  1. Support Staff 1 Posted by Sarah on 29 Aug, 2018 10:11 PM

    Sarah's Avatar

    Try this:

    function pageWasCreated(document, item) {
        var attString = item.dataAsAttributedString();
        attString.mutableString().appendString("\nThis page was created on " + (new Date().toString()).replace(/ \w+-\d+ \(.*\)$/,"")));
        item.setDataWithAttributedString(attString);
    }
    

    This should give you the second date format. Let me know if you run into any issues.

  2. 2 Posted by svs on 31 Aug, 2018 08:05 AM

    svs's Avatar

    Many thanks, but this still returns:

    This page was created on Fri Aug 31 2018 09:03:16 GMT+0100 (BST)
    
  3. Support Staff 3 Posted by Sarah on 31 Aug, 2018 03:14 PM

    Sarah's Avatar

    Did you remove the previous script completely from the VPPageEventScript? If so, have you tried closing and reopening VoodooPad, and then attempting to create a new page?

  4. 4 Posted by svs on 31 Aug, 2018 04:02 PM

    svs's Avatar

    Yes tried that and still no joy. My VPPageEventScript contains the
    following:

    function makeOrphanedPage(document) {

    var linkedPages = {}; // using a hash table here because it's
    convenient.
    var orphanedPages = [];
    var summaryPageName = "Orphaned Pages";

    /* Collect all linked pages. */
    var keys = document.keys();
    for (i = 0; i < keys.length; i++) {
    var page = document.pageForKey(keys[i]);

    if (!page.isText() || (page.key() == "orphaned pages")) {
    continue;
    }

    var pageContent = page.dataAsAttributedString();
    var linkedPageNames =
    document.linkedPageNamesInAttributedString(pageContent);

    for (j = 0; j < linkedPageNames.length; j++) {

    linkedKey = linkedPageNames[j].vpkey();

    // ignore self links.
    if (!linkedKey.isEqualToString(page.key())) {
    linkedPages[linkedKey] = "";
    }
    }
    }

    /* Now compare the linked pages with all pages to find the orphaned
    ones. */
    for (i = 0; i < keys.length; i++) {
    var key = keys[i];
    if (linkedPages[key] == null) {
    orphanedPages.push(key);
    }
    }

    /* Create a summary page and open it. */
    var summaryPage = document.createNewPageWithName(summaryPageName);
    summaryPage.setDataAsString(summaryPageName + "\n\n" +
    orphanedPages.join("\n"));
    }

    function pageWasOpened(document, page) {
    if (page.key() == "orphaned pages") {
    makeOrphanedPage(document);
    }
    }

    function pageWasCreated(document, item) {
    var attString = item.dataAsAttributedString();
    attString.mutableString().appendString("\nThis page was created on
    " + (new Date().toString()).replace(/ \w+-\d+ \(.*\)$/,"")));
    item.setDataWithAttributedString(attString);
    }

    and a new page returns:

    This page was created on Fri Aug 31 2018 17:02:17 GMT+0100 (BST)

  5. Support Staff 5 Posted by Sarah on 31 Aug, 2018 08:20 PM

    Sarah's Avatar

    Do you have any other event script pages within that document?

  6. 6 Posted by svs on 01 Sep, 2018 09:41 AM

    svs's Avatar

    No, just the one: https://d.pr/i/G6kIkH

  7. Support Staff 7 Posted by Sarah on 04 Sep, 2018 01:11 PM

    Sarah's Avatar

    I see. What version of VoodooPad are you currently using? And which device and macOS version?

    Does anything change if you delete the current VPPageEventScript and create a new one with the above script?

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:

»

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac