Should this code work in Javascript

Post any Bulk Rename Utility support requirements here. Open to all registered users.

Should this code work in Javascript

Postby sbennet1 » Mon Nov 24, 2025 4:13 pm

Should the following code work in Javascript BRU just goes away
Code: Select all
// Append a formatted date (using toLocaleDateString) to the existing name and alert the date.
// Example:
//   Before: name = "report"
//   After:  newName = "report Monday, January 10, 2000"

var dateObj = new Date(2000, 0, 10); // January is month 0
alert ("dateObj="+dateObj)
var options = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' };

alert ("options="+options)

var formatted = dateObj.toLocaleDateString("eng-US", options);

alert("Date: " + formatted);

newName = name + " " + formatted;
sbennet1
 
Posts: 16
Joined: Mon Oct 27, 2025 1:55 pm

Re: Should this code work in Javascript

Postby Admin » Tue Nov 25, 2025 12:16 am

Bulk Rename Utility’s embedded JavaScript environment does not reliably support the browser Intl/toLocaleDateString features you’re calling (and you also used the wrong locale code "eng-US" instead of "en-US"). Calling toLocaleDateString with locale + options can throw or crash the V8 runtime inside BRU. Use BRU’s built-in formatDateTime function instead.

Why it crashes
- The V8 build inside BRU may not include the Intl APIs or full toLocaleDateString implementation. Passing a locale/options that the engine doesn’t support can throw an unhandled exception and crash the script.
- Also your locale string is incorrect: "eng-US" should be "en-US". That alone may throw in some environments.

Fixed examples

1) Preferred (use BRU API formatDateTime — safe and supported)
var dateObj = new Date(2000,0,10); // Jan = 0
// format tokens: WD = weekday full, MMMM = month name full, D = day, YYYY = year
var formatted = formatDateTime(dateObj, "WD, MMMM D, YYYY", "en-US");
newName = name + " " + formatted;

2) If you still want to try toLocaleDateString (may fail in BRU)
var dateObj = new Date(2000,0,10);
var options = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' };
// correct locale tag
try {
var formatted = dateObj.toLocaleDateString("en-US", options);
newName = name + " " + formatted;
} catch (e) {
// fallback to BRU formatter when Intl isn't available
newName = name + " " + formatDateTime(dateObj, "WD, MMMM D, YYYY", "en-US");
}

Notes
- Avoid many alert() popups in batch runs (they block and are annoying). Use alert only for debugging a single run.
- Prefer BRU's formatDateTime for consistent, supported date formatting inside Bulk Rename Utility.
Admin
Site Admin
 
Posts: 3118
Joined: Tue Mar 08, 2005 8:39 pm

Re: Should this code work in Javascript

Postby sbennet1 » Fri Dec 05, 2025 10:15 pm

2) If you still want to try toLocaleDateString (may fail in BRU)
var dateObj = new Date(2000,0,10);
var options = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' };
// correct locale tag
try {
var formatted = dateObj.toLocaleDateString("en-US", options);
newName = name + " " + formatted;
} catch (e) {
// fallback to BRU formatter when Intl isn't available
newName = name + " " + formatDateTime(dateObj, "WD, MMMM D, YYYY", "en-US");
}

Notes
- Avoid many alert() popups in batch runs (they block and are annoying). Use alert only for debugging a single run.
- Prefer BRU's formatDateTime for consistent, supported date formatting inside Bulk Rename Utility.


I tried your code for option 2 it seems to return a null but does not crash BRU.

I will stick to number 1

thanks
sbennet1
 
Posts: 16
Joined: Mon Oct 27, 2025 1:55 pm


Return to BRU Support