Build a Date

509 views
Skip to first unread message

Davidson, Jerry

unread,
Feb 10, 2012, 12:08:06 PM2/10/12
to live...@googlegroups.com

This is an offshoot of the thread on the date bug.  Since it is a different topic, I thought it deserved its own thread.

 I want to build a date, but I don't see any constructor in FormCalc to do that.  Is this just my missing it or doesn't it exist.

 Using Date2Num I can extract the pieces of a date (month, day, year).  Because of the date bug I can't do the simple of adding one to a date without tons of scripting behind it.  Each of the date delimiters has multiple options (mm,dd,yy or m,dd,yy or mm,d,yy or m,d,yy or mm,dd,yyyy or m,dd,yyyy or mm,d,yyyy or dd,mm,yy or m,dd,yyyy etc.  And each of these apply to period, comma, dash, slash or space delimiters.  A script could run to hundreds of lines to accommodate all this.

 I was hoping to have a work-a-round by extracting the pieces and ignoring the delimiters and permutations.  The problem is building the date from the pieces.

 One format in the docs is Num2Date("12/31/12", "MM/DD/YY") so I was hoping to create a variable with that and use it.  But it didn't work.

 Any ideas on:

1) other utilities that will convert numbers into a date?

2) a correct format for this utility?

 Here is the code I have so far:

 var day = Num2Date(monAsNum, "D");

var month = Num2Date(monAsNum, "M");

var year = Num2Date(monAsNum, "Y");

var redone = Concat(month,"/",day+1,"/",year);

var rebuild = Num2Date(redone,"MM/DD/YYYY");   

$host.messageBox(Concat("Testing **Day: ", day, " Month: ", month, " Year: ", year, " Rebuilt: ", rebuild));

I also concatenated in a double quote to the string start and end, but it still didn't work.

tarekahf

unread,
Feb 11, 2012, 12:50:08 AM2/11/12
to Adobe LiveCycle Developers
Hi Jerry,

As per my experience, I avoid using FormCalc, except for the
following:

1. Calculating Summaries,

2. Any function less than 5 lines of code.

Any other processing, I use JavaScript.

I faced similar problem you are describing, and I found the solution
in using:

util.printd(...)

and

util.scand(...)

For more information, check this detailed guide:

http://acrobatusers.com/tutorials/date_time_part1

Since then, I am not using FormCalc for complex date processing and
formating.

Tarek.

On Feb 10, 8:08 pm, "Davidson, Jerry" <Jerry.David...@Illinois.gov>
wrote:

fred.pantalone

unread,
Feb 13, 2012, 10:18:44 AM2/13/12
to Adobe LiveCycle Developers
Try this (I'm not exactly sure what you've got in "monAsNum"):

var rebuild = Num2Date( Date2Num( monAsNum ) + 1 )

Date2Num() returns the number of days since the epoch so there is no
need to split up the date, just add one (i.e. a day) to this "raw"
date. Simply incrementing the day of the month is problematic for a
number of reasons. Also, your approach is flawed. You're putting a
string into "redone" and then calling Num2Date() which expects a
number (hence the name of the function) as the first argument.

Fred




On Feb 10, 12:08 pm, "Davidson, Jerry" <Jerry.David...@Illinois.gov>
wrote:

Davidson, Jerry

unread,
Feb 14, 2012, 10:55:35 AM2/14/12
to live...@googlegroups.com
Thanks for the reply.

I'm using LiveCycle Designer and most of the java script isn't working. For example,
var rightNow = Date(this.rawValue);
xfa.host.messageBox(rightNow);

var year = rightNow.getYear().value;
xfa.host.messageBox(year);
var month = rightNow.getMonth().value;
xfa.host.messageBox(mouth);
var day = rightNow.getDate().value;
xfa.host.messageBox(day);

will display "rightNow" and nothing else. There is no javascript console either (thus all the message boxes).

Hi Jerry,

1. Calculating Summaries,

util.printd(...)

and

util.scand(...)

http://acrobatusers.com/tutorials/date_time_part1

Tarek.

--
You received this message because you are subscribed to the Google Groups "Adobe LiveCycle Developers" group.
To post to this group, send email to live...@googlegroups.com.
To unsubscribe from this group, send email to livecycle+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/livecycle?hl=en.

tarekahf

unread,
Feb 14, 2012, 11:26:00 AM2/14/12
to Adobe LiveCycle Developers
That is because there is a bug in your code (Error).

After the code you wrote is executed, press Ctrl-J and the Console
will display, or, at the end of your code, execute "console.show()"

You will see the following errors:
------
rightNow.getYear is not a function
4:XFA:form1[0]:#subform[0]:Button4[0]:clickException in line 4 of
function top_level, script XFA:form1[0]:#subform[0]:Button4[0]:click

rightNow.getYear is not a function
4:XFA:form1[0]:#subform[0]:Butt
-----

Please note that what you are trying to do is not correct.

If you are trying to convert a Form Date Field into a Javascript Date
Field, then first you need to understand that almost any Form Filed
Value (someField.rawValue) is a String Type in Javascript. So, to
convert the Field Value from the Form into JavaScript, you need first
to convert from "String" to "Date".

So, if you have DateTime Field, first display the "rawValue" to learn
how the value is formatted, and then use "util.scand()" to convert
from "String" to proper Date in JavaScript, something like this:

xfa.host.messageBox(myDateField.rawValue);
//I suppose the Date String Value is formatted by default as yyyy-mm-
dd
var myDate = util.scand("yyyy-mm-dd", myDateField.rawValue);
xfa.host.messageBox(myDate.toString());

I hope now you can work it out.

Tarek.

On Feb 14, 6:55 pm, "Davidson, Jerry" <Jerry.David...@Illinois.gov>
> For more options, visit this group athttp://groups.google.com/group/livecycle?hl=en.- Hide quoted text -
>
> - Show quoted text -

Davidson, Jerry

unread,
Feb 14, 2012, 2:55:39 PM2/14/12
to live...@googlegroups.com
Unfortunately, "Ctrl-j" didn't do anything. "console.show()" didn't display any windows.

The date/time field returns completely different results depending on the input format which is the initial problem. I changed the deprecated "getYear" to "getFullYear" with no difference.

Since I'm using Adobe LiveCycle Designer ES2 9.0.0 I may not have access to the things you see.

Jono Moore

unread,
Feb 14, 2012, 5:59:01 PM2/14/12
to live...@googlegroups.com
On Tuesday, February 14, 2012 11:55:39 AM UTC-8, Jerry62712 wrote:
> Unfortunately, "Ctrl-j" didn't do anything. "console.show()" didn't display any windows.

The console window is in Acrobat, not Designer.

Once you have the console open then you can use console.println() instead of xfa.host.messageBox() for debugging...much easier!

tarekahf

unread,
Feb 15, 2012, 2:12:07 PM2/15/12
to Adobe LiveCycle Developers

Please follow these steps:

1. Make sure to install Acrobat (remove Adobe Reader to be on the safe
side)

2. Open any PDF, press Ctrl-K, and enable JavaScript debugging ...etc.
from Javascript Option. Click OK.

3. Press Ctrl-J, now the console should open. You can try Javascript
here. Try:

1 + 1 (Press Ctrl-Enter)

4. Try again your date processing

If still console does not open, then I am afraind I ran out of
options.

Tarek.


On Feb 14, 10:55 pm, "Davidson, Jerry" <Jerry.David...@Illinois.gov>
> > For more options, visit this group athttp://groups.google.com/group/livecycle?hl=en.-Hide quoted text -

fred.pantalone

unread,
Feb 16, 2012, 10:54:04 AM2/16/12
to Adobe LiveCycle Developers
Some suggestions:

// use the "new" operator, try using "formattedValue" - the Date
constructor might be able to use it as is:
var rightNow = new Date(this.formattedValue);

// cast "rightNow" to a string by using a string and the "+" operator:
xfa.host.messageBox( "date: " + rightNow );

// get rid of ".value" at the end of the call to getYear(), it's
wrong:
var year = rightNow.getYear();

// cast these ints to a strings by using a string and the "+"
operator:
xfa.host.messageBox("y: " + year);

All of this works for me:

var rightNow = new Date(DateTimeField1.formattedValue);
xfa.host.messageBox("date: " + rightNow);

var year = rightNow.getYear();
xfa.host.messageBox( "y: " + year);

var month = rightNow.getMonth();
xfa.host.messageBox("m: " + month);

var day = rightNow.getDate();
xfa.host.messageBox("d: " + day);


Fred




On Feb 14, 10:55 am, "Davidson, Jerry" <Jerry.David...@Illinois.gov>
wrote:

fred.pantalone

unread,
Feb 16, 2012, 10:55:18 AM2/16/12
to Adobe LiveCycle Developers
One more thing:

console.show(); // makes the console appear in Reader.

Fred



On Feb 16, 10:54 am, "fred.pantalone" <fred.pantal...@gmail.com>
wrote:

tarekahf

unread,
Feb 18, 2012, 2:02:32 AM2/18/12
to Adobe LiveCycle Developers
I have updated my Google Workspace which I have started using to
document my experience using Adobe LiveCycle in General:

http://bit.ly/w00nNc

Click on the above link, and you will see a recent image I uplaoded
which is a screen shot of the Javascript option settings and the
console.

Tarek.

On Feb 14, 10:55 pm, "Davidson, Jerry" <Jerry.David...@Illinois.gov>
> > For more options, visit this group athttp://groups.google.com/group/livecycle?hl=en.-Hide quoted text -
Reply all
Reply to author
Forward
0 new messages