Welcome to the nuBuilder Forums!

Register and log in to access exclusive forums and content available only to registered users.

Format Builder 12 Hour Time

Questions related to using nuBuilder Forte.
Post Reply
BoydG
Posts: 35
Joined: Mon Dec 31, 2018 10:31 am

Format Builder 12 Hour Time

Unread post 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
nac
Posts: 115
Joined: Tue Dec 12, 2017 11:28 pm
Location: Aberdeen, UK
Has thanked: 9 times
Been thanked: 12 times

Re: Format Builder 12 Hour Time

Unread post 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
Post Reply