• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Round up to nearest quarter hour

New Here ,
May 27, 2018 May 27, 2018

Copy link to clipboard

Copied

I have a form with several drop-down fields, representing rooms.

The dropdown values are from 1-10.

They are multiplied by a certain amount to reflect cleaning time per room.

In a text field I add up the value of the dropdown fields.

The value in the text field represents total minutes.

None of the fields has a format applied.

I want to convert the text field value to hours and minutes, then round UP to the nearest 15 minutes.

So, if the total minutes is 85, it should display as 01:25 and be rounded up to 01:30

Or, if the total minutes is 80, it should display as 01:20 and be rounded up to 01:30

Currently, I am using the following Javascript to get the value to display as hours and minutes (though I don't really understand it from var nHours onwards):

var st = this.getField("Storeys").value * 10;

var ki = this.getField("Kitchen").value * 30;

var kd = this.getField("K/D").value * 30;

var sw = this.getField("S/W").value * 10;

var be = this.getField("Bed").value * 10;

var di = this.getField("Dining").value * 20;

var lf = this.getField("Living").value * 20;

var co = this.getField("Cons").value * 20;

var fb = this.getField("FullBath").value * 30;

var sh = this.getField("Shower").value * 20;

var ba = this.getField("BathOnly").value * 20;

var wc = this.getField("W/C").value * 10;

var prep = 5;

var TotalMin = st + ki + kd + sw + be + di + lf + co + fb + sh + ba + wc + prep;

var nHours = TotalMin / 60;

var nMin = TotalMin % 60;

var sFormat = "%,002d";

sFormat += ":";

sFormat += "%,002d";

if (st == "" && ki == "" && kd == "" && sw == "" && be == "" && di == "" && lf == "" && co == "" && fb == "" && sh == "" && ba == "" && wc == "") {event.value = "";}

else event.value = util.printf(sFormat, nHours, nMin);

TOPICS
Acrobat SDK and JavaScript

Views

413

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 28, 2018 May 28, 2018

Copy link to clipboard

Copied

LATEST

I have tried simplifying this as I just want to produce a vlaue that says x hours and x minutes - such as "2hr 15min"

So, I tried removing the formating and using Math.round and Modulo to produce hour and minute values, then massaging those.

This is what I have so far, but it isn't working out - if I fill in any value into one of the room fields, the RecommendedHours becomes "2hr".

//Room fields are dropdowns with values from 1-10

var st = this.getField("Storeys").value * 10; //clean time fo rstairs and hallways

var ki = this.getField("Kitchen").value * 30; //clean time for kitchen

var kd = this.getField("K/D").value * 30; //clean time for kitchen/diner

var sw = this.getField("S/W").value * 10; //clean time for study/workroom

var be = this.getField("Bed").value * 10; //clean time fo rbedrooms

var di = this.getField("Dining").value * 20; //clean time for dining rooms

var lf = this.getField("Living").value * 20; //clean time for living/family room

var co = this.getField("Cons").value * 20; //clean time for conservatory

var fb = this.getField("FullBath").value * 30;  //clean time for full bathrooms

var sh = this.getField("Shower").value * 20; //clean time for shower rooms/en-suites

var ba = this.getField("BathOnly").value * 20; //clean time for bathrooms without shower

var wc = this.getField("W/C").value * 10; //clean time fo rutility rooms and w/c

var prep = 5; //add 5 minutes for prep time

//get total minutes for clean times

var TotalMin = st + ki + kd + sw + be + di + lf + co + fb + sh + ba + wc + prep;

//get hours from total minutes

var hr = Math.floor(TotalMin / 60);

//get remaining minutes after separating hours

var min = TotalMin % 60;

//if all room fields are blank, RecommendedHours value should be ""

if (st == "" && ki == "" && kd == "" && sw == "" && be == "" && di == "" && lf == "" && co == "" && fb == "" && sh == "" && ba == "" && wc == "") {event.value = "";}

//Minimum value of RecommendedHours must be 2 hours

else if (hr = 1) {event.value = "2hr";}

//If Hours are 2 or more

//If minutes is greater than 0 and equal to or less than 15, round up minutes to 15

else if (hr >= 2 && min > 0 && min <= 15) {event.value = hr + "hr" + " " + "15min";}

//If minutes is greater than 15 and equal to or less than 30, round up minutes to 30

else if (hr >= 2 && min > 15 && min <= 30) {event.value = hr + "hr" + " " + "30min";}

//If minutes is greater than 30 and equal to or less than 45, round up minutes to 15

else if (hr >= 2 && min > 30 && min <= 45) {event.value = hr + "hr" + " " + "45min";}

//If minutes is greater than 45, round up to next hour

else if (hr >= 2 && min > 45) {event.value = (hr + 1) + "hr";}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines