• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

How do i change this?

New Here ,
Feb 05, 2018 Feb 05, 2018

Copy link to clipboard

Copied

/*** Get the ISO week date week number */

Date.prototype.getWeek = function () {
    // Create a copy of this date object;
    var target  = new Date(this.valueOf());
    //var target  = new Date(this.getField("WeekBegin").value);

    // ISO week date weeks start on Monday;
    // so correct the day number;
    var dayNr   = (this.getDay() + 6) % 7;

    // ISO 8601 states that week 1 is the week;
    // with the first Thursday of that year.;
    // Set the target date to the Thursday in the target week;
    target.setDate(target.getDate() - dayNr + 3);

    // Store the millisecond value of the target date;
    var firstThursday = target.valueOf();

    // Set the target to the first Thursday of the year;
    // First set the target to January first
    target.setMonth(0, 1);
    // Not a Thursday? Correct the date to the next Thursday
    if (target.getDay() != 4) {
        target.setMonth(0, 1 + ((4 - target.getDay()) + 7) % 7);
    }

    // The weeknumber is the number of weeks between the
    // first Thursday of the year and the Thursday in the target week
    return 1 + Math.ceil((firstThursday - target) / 604800000); // 604800000 = 7 * 24 * 3600 * 1000
}

var oDate = new Date(); // create date object;
var nWeekNumber = oDate.getWeek(); // get the week number for the date object;
//app.alert("For " + util.printd("ddmmyy", oDate) + " it is week " + nWeekNumber, 3, 0);

this.getField("WeekNumber").value = nWeekNumber;

Now I Want to be able to use the "weekbegin" field text box (ddmmyy) to work out the week number, but instead its using the current date.

What do I change to get it to use the "weekbegin" as the date instead of the current date it uses?

TOPICS
Acrobat SDK and JavaScript , Windows

Views

512

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 05, 2018 Feb 05, 2018

Copy link to clipboard

Copied

Change this line:

var oDate = new Date();

To:

var oDate = util.scand("mm/dd/yyyy", this.getField("weekbegin").valueAsString);

Adjust the date format if necessary.

However, this will return the results for the current date if the field is empty, so you might want to add a condition that checks for that.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 05, 2018 Feb 05, 2018

Copy link to clipboard

Copied

Ok I tried that, but doesn't show any results.

var oDate = util.scand("mmddyy", this.getField("WeekBegin").valueastring);

is what I have, However if the "WeekBegin" field is filled or not it doesn't show any value?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 05, 2018 Feb 05, 2018

Copy link to clipboard

Copied

That's not the code I posted.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 05, 2018 Feb 05, 2018

Copy link to clipboard

Copied

You needed to change one line of code and not delete all of the code.

So the only code for the field would be:

// var oDate = new Date(); // create date object;

var oDate = util.scand("mm/dd/yyyy", this.getField("weekbegin").valueAsString); // create date object for the value of "weekbegin" field;

var nWeekNumber = oDate.getWeek(); // get the week number for the date object;

//app.alert("For " + util.printd("ddmmyy", oDate) + " it is week " + nWeekNumber, 3, 0);

this.getField("WeekNumber").value = nWeekNumber;

All the code above that piece of code should be placed in the Document level JavaScript.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 05, 2018 Feb 05, 2018

Copy link to clipboard

Copied

ok.

so I have this on the field "WeekNumber":

//var oDate = new Date(); // create date object;
var oDate = util.scand("ddmmyy", this.getField("WeekBegin").valueastring); // create date object using WeekNumber input
var nWeekNumber = oDate.getWeek(); // get the week number for the date object;
//app.alert("For " + util.printd("ddmmyy", oDate) + " it is week " + nWeekNumber, 3, 0);

this.getField("WeekNumber").value = nWeekNumber;

And I have this code at document level:

/*** Get the ISO week date week number */

Date.prototype.getWeek = function () {
    // Create a copy of this date object;
    var target  = new Date(this.valueOf());
    //var target  = new Date(this.getField("WeekBegin").value);

    // ISO week date weeks start on Monday;
    // so correct the day number;
    var dayNr   = (this.getDay() + 6) % 7;

    // ISO 8601 states that week 1 is the week;
    // with the first Thursday of that year.;
    // Set the target date to the Thursday in the target week;
    target.setDate(target.getDate() - dayNr + 3);

    // Store the millisecond value of the target date;
    var firstThursday = target.valueOf();

    // Set the target to the first Thursday of the year;
    // First set the target to January first
    target.setMonth(0, 1);
    // Not a Thursday? Correct the date to the next Thursday
    if (target.getDay() != 4) {
        target.setMonth(0, 1 + ((4 - target.getDay()) + 7) % 7);
    }

    // The weeknumber is the number of weeks between the
    // first Thursday of the year and the Thursday in the target week
    return 1 + Math.ceil((firstThursday - target) / 604800000); // 604800000 = 7 * 24 * 3600 * 1000
}

Is this correct? as I'm still not getting anything?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 05, 2018 Feb 05, 2018

Copy link to clipboard

Copied

Yes. Why do you keep insisting on changing valueAsString to valueastring? The first exists, the second doesn't. JS is case-sensitive, plus you're missing an "s"...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 05, 2018 Feb 05, 2018

Copy link to clipboard

Copied

opps, sorry fixed that.

so its now:

//var oDate = new Date(); // create date object;
var oDate = util.scand("ddmmyy", this.getField("WeekBegin").valueAsString); // create date object using WeekNumber input
var nWeekNumber = oDate.getWeek(); // get the week number for the date object;
//app.alert("For " + util.printd("ddmmyy", oDate) + " it is week " + nWeekNumber, 3, 0);

this.getField("WeekNumber").value = nWeekNumber;

But still no luck?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 05, 2018 Feb 05, 2018

Copy link to clipboard

Copied

Where did you put the code?

What does "still no luck" mean? What exactly happens? Is there an error message in the JS Console? If so, what does it say?

Details, please.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 05, 2018 Feb 05, 2018

Copy link to clipboard

Copied

nothing happens.

in JS Console I get this:

TypeError: oDate.getWeek is not a function

3:Field:Mouse Up

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 05, 2018 Feb 05, 2018

Copy link to clipboard

Copied

You have to include the getWeek function definition with it...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 05, 2018 Feb 05, 2018

Copy link to clipboard

Copied

I put the code in the field. (as a "Refresh" button to be precise that way if I change the dates I can refresh)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 05, 2018 Feb 05, 2018

Copy link to clipboard

Copied

isn't that the code in the Document JavaScript?

This one:

/*** Get the ISO week date week number */

Date.prototype.getWeek = function () {
    // Create a copy of this date object;
    var target  = new Date(this.valueOf());
    //var target  = new Date(this.getField("WeekBegin").value);

    // ISO week date weeks start on Monday;
    // so correct the day number;
    var dayNr   = (this.getDay() + 6) % 7;

    // ISO 8601 states that week 1 is the week;
    // with the first Thursday of that year.;
    // Set the target date to the Thursday in the target week;
    target.setDate(target.getDate() - dayNr + 3);

    // Store the millisecond value of the target date;
    var firstThursday = target.valueOf();

    // Set the target to the first Thursday of the year;
    // First set the target to January first
    target.setMonth(0, 1);
    // Not a Thursday? Correct the date to the next Thursday
    if (target.getDay() != 4) {
        target.setMonth(0, 1 + ((4 - target.getDay()) + 7) % 7);
    }

    // The weeknumber is the number of weeks between the
    // first Thursday of the year and the Thursday in the target week
    return 1 + Math.ceil((firstThursday - target) / 604800000); // 604800000 = 7 * 24 * 3600 * 1000
}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 05, 2018 Feb 05, 2018

Copy link to clipboard

Copied

Yes. Did you put it there?
I just tried it myself and it's working fine... I don't know what you're doing to get it not to work.

See: WeekNumberTest.pdf - Google Drive

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 05, 2018 Feb 05, 2018

Copy link to clipboard

Copied

ok when I open your pdf, if I change the date it still shows 6 even after pressing button?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 05, 2018 Feb 05, 2018

Copy link to clipboard

Copied

Depends. What did you change it to?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 05, 2018 Feb 05, 2018

Copy link to clipboard

Copied

I just put 010118. hoping for 1 for week 1

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 05, 2018 Feb 05, 2018

Copy link to clipboard

Copied

Works fine for me:

So after you click the button it still shows 6? What application did you open it in?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 05, 2018 Feb 05, 2018

Copy link to clipboard

Copied

I'm using Adobe Acrobat DC.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 05, 2018 Feb 05, 2018

Copy link to clipboard

Copied

Just tried it on Acrobat Reader and still doesn't work..

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 05, 2018 Feb 05, 2018

Copy link to clipboard

Copied

Don't know what to tell you. It's working just fine on my end.

Did you press the button after changing the value of the first field?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 05, 2018 Feb 05, 2018

Copy link to clipboard

Copied

Tried opening on phone and tried there, and still not working.

Gonna try on another pc now

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 05, 2018 Feb 05, 2018

Copy link to clipboard

Copied

ok funny thing is, it works on my other pc using Adobe Acrobat DC?

WTH?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 05, 2018 Feb 05, 2018

Copy link to clipboard

Copied

Maybe you have JS disabled on the other computer, or something like that.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 05, 2018 Feb 05, 2018

Copy link to clipboard

Copied

But it works for some other js functions.. really weird

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines