/    Sign up×
Community /Pin to ProfileBookmark

Javascript indesign folio/date HELP!

Hello, Thanks for Helping!

Below is code used to get the next days date. I would like to fix a few cliches I can’t seem to solve. I would like to add one day to the date on the right. I would also like to eliminate 0 from dates early in the month (01,02,03,04,05,06,07,08,09)

(Example of what the code produces now in red)
[COLOR=”Red”][B]Weekend Edition, January 06-06, 2007[/B][/COLOR]

(What I would like the code to produce in red below)
[COLOR=”Red”][B]Weekend Edition, January 6-7, 2007[/B][/COLOR]

[CODE]

if (app.documents.length == 0) { exit() }
insertDTs(app.documents[0]);

function insertDTs(aDoc) {
var curPrefs = aDoc.characterStyles[0].extractLabel(“dtprefs”);
if (curPrefs == “”) {
// Doc has no prefs; use saved prefs
curPrefs = getCurPrefs(File(getScriptPath().absoluteURI.replace(/Insert.jsx/, “Prefs.txt”)));
} // end if curPrefs
var prefParts = curPrefs.split(“n”);
if (prefParts[2] != “[None]”) {
insertIt(aDoc, prefParts[0], prefParts[2]);
}
if (prefParts[3] != “[None]”) {
insertIt(aDoc, prefParts[1], prefParts[3]);
}

function insertIt(aDoc, formString, cStyleName) {
var formStrings= [“Day, Month, Year”]
var theFuncs = [dayMonthYear]
var charStyleStrings = aDoc.characterStyles.everyItem().name
if (indexOf(charStyleStrings, cStyleName) < 1) { return } // style not found or is No Style
var func = indexOf(formStrings, formString);
if (func < 0) { return } // requested form not recognized
var dateString = theFuncs[func](new Date());
app.findPreferences = app.changePreferences = null;
aDoc.search(“”, false, false, dateString, {appliedCharacterStyle:cStyleName});
} // end insertIt

function dayMonthYear(date) {
date.setDate(date.getDate()+1);
// returns monthName , year
var myDateString = date.toLocaleDateString();
myParts = myDateString.split(” “);
return “Weekend Edition, “+myParts[1] + ” ” + myParts[2] +”-“+ myParts[2] + “, ” + myParts[3];
}

function indexOf(array, find,offs) {
for( var i = offs == undefined ? 0 : offs; array.length > i; i++ ) {
if( array[i]==find ) {return i}
}
return -1;
}

function getScriptPath() {
// This function returns the path to the active script, even when running ESTK
try {
return app.activeScript;
} catch(e) {
return File(e.fileName);
} // end try
} // end getScriptPath

} // end insertDTs

[/CODE]

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@Wisest_GuyJan 15.2007 — Your dayMonthYear function returns this:
[CODE]return "Weekend Edition, "+myParts[1] + " " + myParts[2] +"-"+ myParts[2] + ", " + myParts[3];[/CODE]
Returning this should work:
[CODE]return "Weekend Edition, "+myParts[1]+" "+(myParts[2]++)+"-"+myParts[2]+", "+myParts[3];[/CODE]
Copy linkTweet thisAlerts:
@MontaraauthorJan 15.2007 — That work perfect! Thanks you really are the Wisest Guy!!!!!— now I just need to figure out how to delete the 0 in front of the numbers 01,02,03,04,05,06,07,08,09 so the dates read 2-3 instead of 02-03
Copy linkTweet thisAlerts:
@Wisest_GuyJan 18.2007 — Try this:
[CODE]return "Weekend Edition, "+myParts[1]+" "+Number(myParts[2]++)+"-"+Number(myParts[2])+", "+myParts[3];[/CODE]
×

Success!

Help @Montara spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...