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 April 15th, 2019, 06:51 AM
Susan Susan is offline
Regular Contributor
 
Join Date: Oct 2008
Location: Maitland, FL
Posts: 57
Default European Date Compose Error

I am using a rule from this site to convert 13-Oct-15 dates to October 13, 2015. It is working correctly, but when there is no data in the "GIFT_DATE" field I get this error "uncaught exception: Error in function "DateFromString": Could not convert "" to a valid date."

Is there something I can add to the rule so that I don't get the error for the empty "GIFT_DATE" fields. It makes it harder to catch real errors. The rule is below:

var str = Field("GIFT_DATE");

var MonthNameAbbrs = [ "jan", "feb", "mar", "apr", "may", "jun",
"jul", "aug", "sep", "oct", "nov", "dec" ];

var month_name_part = 0;
var parts = str.replace(/-/g,'/').split('/');
for (var i = 0; !month_name_part && i < parts.length; i++)
{
if (isNaN(parseInt(parts[i])))
{
for (var m = 0; m < MonthNameAbbrs.length; m++)
{
if (ToLower(parts[i]).substr(0,3) == MonthNameAbbrs[m])
{
parts[i] = m + 1;
month_name_part = i + i;
break;
}
}
}
}

if (month_name_part)
{
var mpart = month_name_part - 1;
var mval = parts[mpart];
parts.splice(mpart, 1);
parts.splice(0, 0, mval);
}

var date = DateFromString(parts.join('/'));
return FormatDate(date, "lm d, yyyy");
__________________
FusionPro Creator v10.1.11 / FusionPro Producer / FusionPro Expression 3.2.2 / Mac OSX 10.13.6 / Acrobat Pro DC
Reply With Quote
  #2  
Old April 15th, 2019, 12:23 PM
ScottHillock ScottHillock is offline
Regular Contributor
 
Join Date: Mar 2010
Posts: 93
Default Re: European Date Compose Error

Add this as your first line:

Code:
if (!Field("GIFT_DATE")){return "";}
__________________
FusionPro 9.3.36 - Acrobat 11 - macOS 10.14
Reply With Quote
  #3  
Old April 15th, 2019, 12:33 PM
Susan Susan is offline
Regular Contributor
 
Join Date: Oct 2008
Location: Maitland, FL
Posts: 57
Default Re: European Date Compose Error

Thanks Scott. Just what I needed!
__________________
FusionPro Creator v10.1.11 / FusionPro Producer / FusionPro Expression 3.2.2 / Mac OSX 10.13.6 / Acrobat Pro DC
Reply With Quote
Reply

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:41 AM.


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