Page 1 of 1
Format Builder 12 Hour Time
Posted: Wed Jan 30, 2019 11:49 pm
by BoydG
Is there a way to get the hour in 12 hour format in Format Builder?
Right now when you try to format a time using hh:nn pp you will still get military time.
So for 5:00 pm it will say 17:00 pm
Re: Format Builder 12 Hour Time
Posted: Thu Jan 31, 2019 1:29 pm
by nac
BoydG,
I have not used the format builder but thought I would have a look at it. The solution below is untested but I think it should work. It is based on the assumption that if you include 'pp' in the format then you want a 12 hour clock. If there is no 'pp' then it's a 24 hour clock.
It looks like the formatting is done by the addFormatting() function in nuformclass.js. Adding four new lines to this function should do the trick. I inserted these lines in at line 722 but have included part of the existing code before and after so you can see exactly where it goes (between the two // comment rows).
Code: Select all
s = s.replaceAll('pp', 'am');
s = s.replaceAll('PP', 'AM');
}
// change to 12 hour clock if 'pp' is in the format string - 4 new lines below.
var sa = String(f);
if (sa.toLowerCase().indexOf('pp') > -1) {
hou = Number(hou) % 12 || 12;
}
// end of new code
s = s.replaceAll('yyyy', yea);
s = s.replaceAll('yy', String(yea).substr(2));
Try it and see - no guarantees! It will probably need some tweaking. Once you get it working you will need add these lines whenever you update nuBuilder and so keep a copy.
Neil