Go Back   MarcomCentral (PTI) and FusionPro User Communities > Software-Related Talk > The JavaScript Library > Dates

Notices

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old June 24th, 2011, 02:44 PM
WestPress WestPress is offline
Junior Community Member
 
Join Date: Sep 2008
Location: Tucson, AZ
Posts: 28
Default A JavaScript Date Library ... just throwing it out there ...

I found an awesome library for playing with, and formatting, dates.

I present "Datejs"

This library is awesome. I just stuck the code in the "JavaScript Globals ..." area in the rules editor, and now I have some really cool latitude over how I accept user input in my MarcomCentral PrintOnes/Stores or even on the Desktop (via some data source) for templates that require it. I think this can benefit every FusionPro user, Designer or Desktop alike.

My goal is that I can present an input field in the PrintOne/Store without any guidance and irregardless of how the user inputs the date, I can format it with very little effort.
__________________
Mac OS X v10.6.7
FusionPro (Designer/Desktop v7.1P1c)
Adobe Acrobat Pro v9.4.5
Adobe InDesign CS5 v7
Reply With Quote
  #2  
Old June 24th, 2011, 03:22 PM
WestPress WestPress is offline
Junior Community Member
 
Join Date: Sep 2008
Location: Tucson, AZ
Posts: 28
Default Re: A JavaScript Date Library ... just throwing it out there ...

So a simple example (again, making sure that you have already pasted the contents of date.js into your globals):

Code:
var d1 = Date.parse(Field("Expiration"));
return (d1.toString('MM/dd/yy'));
This takes a string of input like, "5 days from today" and formats it to read, "06/29/11" like your template might require.... It could be "5 days from now," or "June 29 2011," or "jun 29, 2011," or "06292011," or "next april," or "next friday," etc.

You can format it many different ways....
__________________
Mac OS X v10.6.7
FusionPro (Designer/Desktop v7.1P1c)
Adobe Acrobat Pro v9.4.5
Adobe InDesign CS5 v7

Last edited by WestPress; June 24th, 2011 at 03:34 PM..
Reply With Quote
  #3  
Old June 24th, 2011, 04:00 PM
Dan Korn's Avatar
Dan Korn Dan Korn is offline
FusionPro Senior Engineer / Forum Moderator
 
Join Date: Aug 2008
Location: Chicago, IL
Posts: 4,320
Default Re: A JavaScript Date Library ... just throwing it out there ...

Thanks, that's awesome stuff!

Our decision many moons ago to choose JavaScript as the language for FusionPro rule scripting has turned out to be a huge win, since JavaScript has pretty much taken over the world in the last few years, and there are now tons of great libraries like this around. Of course, many of them are web-specific, as JavaScript's primary use continues to be for client-side web page scripting; however, this is a nice generic library that works right out of the box in just about any JS context, including FusionPro. I dare say that some of this library's date formatting capabilities, and certainly its parsing capabilities, exceed those of FusionPro's built-in functions. Of course, we're not quite Google.

By the way, instead of copy-and-pasting all the code from the Date.js file into your JavaScript Globals, you could add it as a Plain Text Resource to your job and put this line in the Globals instead:
Code:
Load(Resource("Date.JS").value);
__________________
Dan Korn
FusionPro Developer / JavaScript Guru / Forum Moderator
PTI Marketing Technologies | Printable | MarcomCentral
LinkedIn

I am a not a Support engineer, and this forum is not a substitute for Support. My participation on this forum is primarily as a fellow user (and a forum moderator). I am happy to provide help and answers to questions when I can; however, there is no guarantee that I, or anyone else on this forum, will be able to answer all questions or fix any problems. If I ask for files to clarify an issue, I might not be able to look at them personally. I am not able to answer private messages, emails, or phone calls unless they go through proper Support channels. Please direct any sales or pricing questions to your salesperson or inquiries@marcom.com.

Complex template-building questions, as well as all installation and font questions or problems, should be directed to FusionProSupport@marcom.com. Paid consulting work may be required to fulfill your template-building needs.

This is a publicly viewable forum. Please DO NOT post fonts, or other proprietary content, to this forum. Also, please DO NOT post any "live" data with real names, addresses, or any other personal, private, or confidential data.

Please include the specific versions of FusionPro, Acrobat, and your operating system in any problem reports or help requests. I recommend putting this information in your forum signature. Please also check your composition log (.msg) file for relevant error or warning messages.

Please post questions specific to the MarcomCentral Enterprise and Web-to-Print applications in the MarcomCentral forum. Click here to request access. Or contact your Business Relationship Manager (BRM/CPM) for assistance.

Please direct any questions specific to EFI's Digital StoreFront (DSF) to EFI support.

How To Ask Questions The Smart Way

The correct spellings are JavaScript, FusionPro, and MarcomCentral (each with two capital letters and no spaces). Acceptable abbreviations are JS, FP, and MC (or MCC). There is no "S" at the end of "Expression" or "Printable"! The name of the product is FusionPro, not "Fusion". "Java" is not is not the same as JavaScript.

Check out the JavaScript Guide and JavaScript Reference! FusionPro 8.0 and newer use JavaScript 1.7. Older versions use JavaScript 1.5.

return "KbwbTdsjqu!spdlt\"".replace(/./g,function(w){return String.fromCharCode(w.charCodeAt()-1)});
Reply With Quote
  #4  
Old June 24th, 2011, 04:44 PM
WestPress WestPress is offline
Junior Community Member
 
Join Date: Sep 2008
Location: Tucson, AZ
Posts: 28
Default Re: A JavaScript Date Library ... just throwing it out there ...

Heh, that's why you're the JavaScript Guru! That certainly makes for a much cleaner "Globals" area It would have taken me working on several templates before that even would have occurred to me.

I do like Java/JavaScript and appreciate that you chose JavaScript for the foundation of the rules feature of FusionPro.
__________________
Mac OS X v10.6.7
FusionPro (Designer/Desktop v7.1P1c)
Adobe Acrobat Pro v9.4.5
Adobe InDesign CS5 v7

Last edited by WestPress; June 27th, 2011 at 07:30 AM..
Reply With Quote
  #5  
Old June 27th, 2011, 07:53 AM
WestPress WestPress is offline
Junior Community Member
 
Join Date: Sep 2008
Location: Tucson, AZ
Posts: 28
Default Re: A JavaScript Date Library ... just throwing it out there ...

Well Dan,

I tried to load the JavaScript library into "Globals" the way you suggested in a new template I am working with. I loaded the "date.js" file as a plain text file resource. In my JavaScript Globals I have included the resource using the code you suggested:

Code:
Load(Resource("date.js").value);
My text rule, "{rule_FormatDate}" validates okay when I am editing it, showing the correctly formatted date, even the "Results" field of the building blocks menu shows the correct formatted date. But, the preview and subsequent composition returns "{rule_FormatDate}" (the name of my rule) instead of the formatted date.
__________________
Mac OS X v10.6.7
FusionPro (Designer/Desktop v7.1P1c)
Adobe Acrobat Pro v9.4.5
Adobe InDesign CS5 v7
Reply With Quote
  #6  
Old June 27th, 2011, 09:21 AM
Dan Korn's Avatar
Dan Korn Dan Korn is offline
FusionPro Senior Engineer / Forum Moderator
 
Join Date: Aug 2008
Location: Chicago, IL
Posts: 4,320
Default Re: A JavaScript Date Library ... just throwing it out there ...

Quote:
Originally Posted by cdaters View Post
My text rule, "{rule_FormatDate}" validates okay when I am editing it, showing the correctly formatted date, even the "Results" field of the building blocks menu shows the correct formatted date. But, the preview and subsequent composition returns "{rule_FormatDate}" (the name of my rule) instead of the formatted date.
What does the log (.msg) file say?
__________________
Dan Korn
FusionPro Developer / JavaScript Guru / Forum Moderator
PTI Marketing Technologies | Printable | MarcomCentral
LinkedIn

I am a not a Support engineer, and this forum is not a substitute for Support. My participation on this forum is primarily as a fellow user (and a forum moderator). I am happy to provide help and answers to questions when I can; however, there is no guarantee that I, or anyone else on this forum, will be able to answer all questions or fix any problems. If I ask for files to clarify an issue, I might not be able to look at them personally. I am not able to answer private messages, emails, or phone calls unless they go through proper Support channels. Please direct any sales or pricing questions to your salesperson or inquiries@marcom.com.

Complex template-building questions, as well as all installation and font questions or problems, should be directed to FusionProSupport@marcom.com. Paid consulting work may be required to fulfill your template-building needs.

This is a publicly viewable forum. Please DO NOT post fonts, or other proprietary content, to this forum. Also, please DO NOT post any "live" data with real names, addresses, or any other personal, private, or confidential data.

Please include the specific versions of FusionPro, Acrobat, and your operating system in any problem reports or help requests. I recommend putting this information in your forum signature. Please also check your composition log (.msg) file for relevant error or warning messages.

Please post questions specific to the MarcomCentral Enterprise and Web-to-Print applications in the MarcomCentral forum. Click here to request access. Or contact your Business Relationship Manager (BRM/CPM) for assistance.

Please direct any questions specific to EFI's Digital StoreFront (DSF) to EFI support.

How To Ask Questions The Smart Way

The correct spellings are JavaScript, FusionPro, and MarcomCentral (each with two capital letters and no spaces). Acceptable abbreviations are JS, FP, and MC (or MCC). There is no "S" at the end of "Expression" or "Printable"! The name of the product is FusionPro, not "Fusion". "Java" is not is not the same as JavaScript.

Check out the JavaScript Guide and JavaScript Reference! FusionPro 8.0 and newer use JavaScript 1.7. Older versions use JavaScript 1.5.

return "KbwbTdsjqu!spdlt\"".replace(/./g,function(w){return String.fromCharCode(w.charCodeAt()-1)});
Reply With Quote
  #7  
Old June 27th, 2011, 03:29 PM
WestPress WestPress is offline
Junior Community Member
 
Join Date: Sep 2008
Location: Tucson, AZ
Posts: 28
Default Re: A JavaScript Date Library ... just throwing it out there ...

This is what is contained in the .msg log:
Code:
internal, line 1: Error: can't open /test_deleteme/date.js: No such file or directory
Failed to process JavaScript globals
Job started 15:18:51 - 1309187931.
Creator: FusionPro(TM) Designer 7.1P1c
Computer Name: sysad-m01
Current working folder: /
Template File: /test_deleteme/ScratcherBC_Spring_fp.dif
Input File: /test_deleteme/ScratcherBC_Spring.txt
Job Config File: /test_deleteme/ScratcherBC_Spring-Output.cfg
rule_formatDate, line 3: Error: illegal radix 0
Yes, the date.js file does exist at that location...

Initially, I was wondering if it might have something to do with OS X thinking the .js was not necessarily a text file. So, I changed the extension to .txt but that had no effect either. I even moved it to a top level directory thinking the path might have contained too many characters for the parser. What is weird is that the rule validates okay, but the composition fails.
__________________
Mac OS X v10.6.7
FusionPro (Designer/Desktop v7.1P1c)
Adobe Acrobat Pro v9.4.5
Adobe InDesign CS5 v7
Reply With Quote
  #8  
Old June 29th, 2011, 09:23 AM
Dan Korn's Avatar
Dan Korn Dan Korn is offline
FusionPro Senior Engineer / Forum Moderator
 
Join Date: Aug 2008
Location: Chicago, IL
Posts: 4,320
Default Re: A JavaScript Date Library ... just throwing it out there ...

Quote:
Originally Posted by cdaters View Post
This is what is contained in the .msg log:
Code:
internal, line 1: Error: can't open /test_deleteme/date.js: No such file or directory
...
What is weird is that the rule validates okay, but the composition fails.
Oh, you're on Mac. The Load function is broken there. Sorry about that.

It's an issue of HFS vs. POSIX file paths. HFS is the older Mac OS 9-style file reference with colons, while POSIX is the "new" Unix-y OS X-type syntax with forward slashes. Over the years of dealing with the OS 9 to OS X transition, along with all the other myriad changes Apple has made to their APIs, we've patched just about every part of FusionPro to be able to handle both HFS and POSIX path specifications (as well as Windows DOS-type path specifications) interchangeably. However, the Load function in JavaScript is one that we missed. The thing is that, when you're validating the rule, JavaScript is running in a native Intel OS X app, which expects POSIX paths, which is what FusionPro is giving it, and that works fine. But at composition time, you're in the CFM/PowerPC FusionPro app, which expects HFS paths at a low level, so it doesn't work.

This will be fixed in the next 7.2 release.

Also, we're planning to port FusionPro to a modern, Intel-native, BSD-based OS X app in the second half of this year, which should finally get rid of any remaining HFS path dependencies (and actually deprecate support for HFS).
__________________
Dan Korn
FusionPro Developer / JavaScript Guru / Forum Moderator
PTI Marketing Technologies | Printable | MarcomCentral
LinkedIn

I am a not a Support engineer, and this forum is not a substitute for Support. My participation on this forum is primarily as a fellow user (and a forum moderator). I am happy to provide help and answers to questions when I can; however, there is no guarantee that I, or anyone else on this forum, will be able to answer all questions or fix any problems. If I ask for files to clarify an issue, I might not be able to look at them personally. I am not able to answer private messages, emails, or phone calls unless they go through proper Support channels. Please direct any sales or pricing questions to your salesperson or inquiries@marcom.com.

Complex template-building questions, as well as all installation and font questions or problems, should be directed to FusionProSupport@marcom.com. Paid consulting work may be required to fulfill your template-building needs.

This is a publicly viewable forum. Please DO NOT post fonts, or other proprietary content, to this forum. Also, please DO NOT post any "live" data with real names, addresses, or any other personal, private, or confidential data.

Please include the specific versions of FusionPro, Acrobat, and your operating system in any problem reports or help requests. I recommend putting this information in your forum signature. Please also check your composition log (.msg) file for relevant error or warning messages.

Please post questions specific to the MarcomCentral Enterprise and Web-to-Print applications in the MarcomCentral forum. Click here to request access. Or contact your Business Relationship Manager (BRM/CPM) for assistance.

Please direct any questions specific to EFI's Digital StoreFront (DSF) to EFI support.

How To Ask Questions The Smart Way

The correct spellings are JavaScript, FusionPro, and MarcomCentral (each with two capital letters and no spaces). Acceptable abbreviations are JS, FP, and MC (or MCC). There is no "S" at the end of "Expression" or "Printable"! The name of the product is FusionPro, not "Fusion". "Java" is not is not the same as JavaScript.

Check out the JavaScript Guide and JavaScript Reference! FusionPro 8.0 and newer use JavaScript 1.7. Older versions use JavaScript 1.5.

return "KbwbTdsjqu!spdlt\"".replace(/./g,function(w){return String.fromCharCode(w.charCodeAt()-1)});
Reply With Quote
  #9  
Old June 29th, 2011, 03:11 PM
WestPress WestPress is offline
Junior Community Member
 
Join Date: Sep 2008
Location: Tucson, AZ
Posts: 28
Default Re: A JavaScript Date Library ... just throwing it out there ...

You know, this actually validates a discussion I had with Alex some time back about Universal builds vs. Intel builds for OS X.

I had asked him when/if there would ever be an Intel build of FusionPro, that I had noticed it was still a Universal build, and that I would love to see an Intel build thinking of situations just like this.

He had mentioned that there was no reason for an Intel build that the Universal build was working just fine...
__________________
Mac OS X v10.6.7
FusionPro (Designer/Desktop v7.1P1c)
Adobe Acrobat Pro v9.4.5
Adobe InDesign CS5 v7
Reply With Quote
  #10  
Old June 29th, 2011, 04:27 PM
Dan Korn's Avatar
Dan Korn Dan Korn is offline
FusionPro Senior Engineer / Forum Moderator
 
Join Date: Aug 2008
Location: Chicago, IL
Posts: 4,320
Default Re: A JavaScript Date Library ... just throwing it out there ...

Quote:
Originally Posted by cdaters View Post
You know, this actually validates a discussion I had with Alex some time back about Universal builds vs. Intel builds for OS X.

I had asked him when/if there would ever be an Intel build of FusionPro, that I had noticed it was still a Universal build, and that I would love to see an Intel build thinking of situations just like this.

He had mentioned that there was no reason for an Intel build that the Universal build was working just fine...
Okay, well, we're getting quite far afield from the original subject of this thread, but I can tell you that this isn't really an Intel vs. PowerPC vs. universal binary issue. I'll try to explain.

First, since we're being technical, the FusionPro app (the composition engine) is not a universal binary, it's a CFM/PEF PowerPC app, which runs under the Rosetta VM (the PowerPC emulation layer) on Intel Macs. The FusionPro Acrobat plug-in, on the other hand, is a bundle containing a Mach-O universal binary with both PowerPC and 32-bit Intel (i386) architectures, to match the host application, Acrobat. (Of course, Acrobat, and therefore our plug-in, do run natively as Intel executables on most modern Macs, but we still support PowerPC Macs, as does Adobe, thus the need for a universal binary instead of an Intel-only executable.)

The reason that the FusionPro app uses HFS paths natively doesn't really have anything to do with the fact that it's a PowerPC app instead of a native Intel app or a unversal binary. It's a consequence of the tools and APIs used to build it. Specifically, it's because it's built in CodeWarrior instead of Xcode, which not only limits it to PowerPC and the CFM architecture, but it also makes it use HFS paths by default because it relies on CodeWarrior's Metrowerks Standard Library (MSL) runtime.

Now, we have actually patched the CodeWarrior MSL runtime to accept POSIX file paths as well as HFS paths, to facilitate interoperability between the FusionPro app and other modern OS X components, most especially our Acrobat plug-in. However, the JavaScript runtime is a third-party component from Mozilla, and the version of the JS runtime used by the FusionPro app is still an older-style CFM library which expects HFS paths. We've patched most of the interface points into the JS library to convert POSIX paths to HFS, but the Load function is one that we missed. (I'm sorry to say that it's not a widely used feature.) The JavaScript runtime used by the Acrobat plug-in, however, is a native Mach-O binary, just like the rest of the plug-in, so it uses POSIX paths by default (and in fact, doesn't work with HFS directly).

Anyway, other than a few fairly minor issues, such as this one with the Load function, the old-school CFM FusionPro app has indeed been working fine for quite some time, as Alex noted. So we haven't had any major impetus to change it. To paraphrase a wise man: "Prudence, indeed, will dictate that Applications long established should not be changed for light and transient causes; and accordingly all experience hath shewn that mankind are more disposed to suffer, while evils are sufferable than to right themselves by abolishing the forms to which they are accustomed."

However, the time eventually comes, "when a long train of abuses and usurpations, pursuing invariably the same Object evinces a design to reduce them under absolute Despotism." Or in this case, Apple decides to change things on us for the umpteenth time. (PowerPC to Intel, HFS to POSIX, 68K to Carbon to Cocoa, QuickDraw to Quartz, GrafPorts to HIViews to NIBs to xibs, dylibs to frameworks, little-endian to big-endian back to little-endian, Leopard to Tiger to Lion, to bears, oh my!)

Specifically, the upcoming Mac OS 10.7 "Lion" removes the Rosetta subsystem, which will render our current architecture unusable. Therefore, we do need to finally bite the bullet and port the FusionPro app to a modern Mach-O app which can run natively under Intel. We're targeting this for FusionPro 8. We will likely drop support for PowerPC Macs and HFS paths in that version as well.

Then we can rest, at least until Acrobat goes to 64-bit.
__________________
Dan Korn
FusionPro Developer / JavaScript Guru / Forum Moderator
PTI Marketing Technologies | Printable | MarcomCentral
LinkedIn

I am a not a Support engineer, and this forum is not a substitute for Support. My participation on this forum is primarily as a fellow user (and a forum moderator). I am happy to provide help and answers to questions when I can; however, there is no guarantee that I, or anyone else on this forum, will be able to answer all questions or fix any problems. If I ask for files to clarify an issue, I might not be able to look at them personally. I am not able to answer private messages, emails, or phone calls unless they go through proper Support channels. Please direct any sales or pricing questions to your salesperson or inquiries@marcom.com.

Complex template-building questions, as well as all installation and font questions or problems, should be directed to FusionProSupport@marcom.com. Paid consulting work may be required to fulfill your template-building needs.

This is a publicly viewable forum. Please DO NOT post fonts, or other proprietary content, to this forum. Also, please DO NOT post any "live" data with real names, addresses, or any other personal, private, or confidential data.

Please include the specific versions of FusionPro, Acrobat, and your operating system in any problem reports or help requests. I recommend putting this information in your forum signature. Please also check your composition log (.msg) file for relevant error or warning messages.

Please post questions specific to the MarcomCentral Enterprise and Web-to-Print applications in the MarcomCentral forum. Click here to request access. Or contact your Business Relationship Manager (BRM/CPM) for assistance.

Please direct any questions specific to EFI's Digital StoreFront (DSF) to EFI support.

How To Ask Questions The Smart Way

The correct spellings are JavaScript, FusionPro, and MarcomCentral (each with two capital letters and no spaces). Acceptable abbreviations are JS, FP, and MC (or MCC). There is no "S" at the end of "Expression" or "Printable"! The name of the product is FusionPro, not "Fusion". "Java" is not is not the same as JavaScript.

Check out the JavaScript Guide and JavaScript Reference! FusionPro 8.0 and newer use JavaScript 1.7. Older versions use JavaScript 1.5.

return "KbwbTdsjqu!spdlt\"".replace(/./g,function(w){return String.fromCharCode(w.charCodeAt()-1)});
Reply With Quote
Reply

Tags
date, datejs, formatting, library

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 05:42 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
(c) 2011, PTI Marketing Technologies™, Inc.