Jump to content

Bolding by time or weekend


dreimer

Recommended Posts

I am trying to figure out how to write a rule to change the font to bold if the time is after 5PM or a weekend date as well. I will have 21 text boxes that this will need and it could apply to any combination of them. At this point I do not have data but I assume the date will be its on field and the time will be another. The time part of the rule would seem static but I am guessing the weekend portion would vary based on the month. Could this rule even be accomplished? I know it would help if I had a file but I am trying to figure out if I can even do this before I get the job. TIA
Link to comment
Share on other sites

So I got a little more information on this. The time will be in it's own text box and is formatted in 12 hour format. So data will come in say as 10:00:00 AM or 5:30:00 PM. So I would need to write a rule for these text boxes to bold if 5:00PM or later

 

Then I would need a text box for the Date and Day of the week. I would be supplied the date. For example: 7/7/2014. So I would need to convert that to say July 7, 2014 and also have the rule return the day of the week it is. So for these text boxes I would need a rule to Bold if the time is 5:00PM or later as well as if it falls on a weekend.

 

Very complicated for my brain to wrap around. Hope this will help in understanding what I am up against and be able to get some guidance. TIA

Link to comment
Share on other sites

Don, here's a function I came up with that you can put in your JavaScript Globals of your template and call from your text boxes to determine whether or not you should be bolding the text:

function useBold(date,time) {
   var d = new Date();
   date = FormatDate(date,"m/d/yyyy");

   // Set Date variables
   thisMonth = date.split("/")[0];
   thisDay = date.split("/")[1];
   thisYear = date.split("/")[2];

   // Set Time variables
   thisHour = Int(time.split(":")[0]);
   thisHour += (time.search(/P/gi) > -1) ? 12 : 0; //add 12 hours if "PM"
   thisMinute = Int(time.split(":")[1]);

   // Set the date and time
   d.setMonth(thisMonth-1);
   d.setDate(thisDay);
   d.setFullYear(thisYear);
   d.setUTCHours(thisHour);
   d.setMinutes(thisMinute);

   var before5 = false;
   var weekend = (d.getDay() == 6 || d.getDay() == 0) ? true : false;

   // If it's the weekend go ahead and return true regardless of the time
   if (weekend) {
       return true;
       }

   // Determine if it's after 5 (17:00)
   if (d.getUTCHours() >= 17) {
       before5 = true;
   }

   return before5;

}

 

It requires that you pass the function (useBold()) two parameters: the date and the time. I wrote it with the data formatting structure that you quoted in your most recent post so as long as that's correct you should be all right. The function basically determines whether or not it's a weekend (Saturday or Sunday) or if it's after 5PM. If either of those conditions are met, it will return true. So I'm thinking you'd set your rules up as such:

 


var s = "2/2/2014"; // Date Field
var p = "4:00:00 PM" // Time Field
var myFont = (useBold(s,p)) ? "Helvetica Bold" : "Helvetica";
return '<span font="' + myFont + '">' + FormatDate(s,"lm d, yyyy") + '</span>';

Edited by step
spelling error
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...