8 Replies - 1303 Views - Last Post: 27 June 2013 - 10:35 AM

#1 condmach  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 24-June 13

Calculate UK Bank Holidays

Posted 24 June 2013 - 04:05 AM

Could use a little assistance adding a lookup (or hardcode if easier) to find UK bank holidays then excluding them from the following calculation...

Function NewTimeOut(Counter)
{
Var CalculatedDays=0;
Var day=today().getDay();
While (Counter > 0) {
       CalculatedDays++;
       day= (day%7)+1;
if (day!=6 && day!=7){
       Counter--;
}
}
Return CalculatedDays;
};



Thanks.

Is This A Good Question/Topic? 0
  • +

Replies To: Calculate UK Bank Holidays

#2 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3719
  • View blog
  • Posts: 5,991
  • Joined: 08-June 10

Re: Calculate UK Bank Holidays

Posted 24 June 2013 - 04:36 AM

What language is that supposed to be? Definitely doesn't look like Java. Kind of looks like Javascript (which is a completely different thing!) except that Javascript syntax doesn't allow mixed casing for keywords like function and var; which means this snippet would never run if it's supposed to be Javascript.
Was This Post Helpful? 0
  • +
  • -

#3 Dogstopper  Icon User is offline

  • The Ninjaducky
  • member icon



Reputation: 2874
  • View blog
  • Posts: 11,047
  • Joined: 15-July 08

Re: Calculate UK Bank Holidays

Posted 24 June 2013 - 05:38 AM

Moving to Javascript. You might consider fixing all your capitalization. Function != function != funCtion.
Was This Post Helpful? 0
  • +
  • -

#4 condmach  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 24-June 13

Re: Calculate UK Bank Holidays

Posted 25 June 2013 - 01:15 AM

My apologies, seems Word was capitalising the code.

Here it is again:

 
function NewTimeOut(Counter){
var CalculatedDays=0;
var day=today().getDay();
while (Counter > 0) {
               CalculatedDays++;
               day= (day %7) +1;
if (day !=6 && day !=7){
               Counter--;
}
}
return CalculatedDays;
};

vWTimeOut=NewTimeOut(TimeOut1);



This is currently working, but need to add bank holidays into the equation.

Thanks.
Was This Post Helpful? 0
  • +
  • -

#5 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3554
  • View blog
  • Posts: 10,335
  • Joined: 08-June 10

Re: Calculate UK Bank Holidays

Posted 25 June 2013 - 01:43 AM

my first question is, what is this function supposed to calculate? if its the number of work days between two dates, Id rather calculate the amount of weekends (via week count) and holidays in the given time span. for holidays Id use an array of the holidays and filter off any dates that are outside the date range.
Was This Post Helpful? 0
  • +
  • -

#6 JMRKER  Icon User is offline

  • D.I.C Addict

Reputation: 129
  • View blog
  • Posts: 832
  • Joined: 25-October 08

Re: Calculate UK Bank Holidays

Posted 25 June 2013 - 07:01 AM

View Postcondmach, on 25 June 2013 - 02:15 AM, said:

My apologies, seems Word was capitalising the code.

Here it is again:

 
function NewTimeOut(Counter){
var CalculatedDays=0;
var day=today().getDay();
while (Counter > 0) {
               CalculatedDays++;
               day= (day %7) +1;
if (day !=6 && day !=7){
               Counter--;
}
}
return CalculatedDays;
};

vWTimeOut=NewTimeOut(TimeOut1);



This is currently working, but need to add bank holidays into the equation.

Thanks.

Difficult to see how you are going to get UK bank holidays from that code.
For example:
1. What are the actions of the function today()?
2. What will the values of 'TimeOut' be passed to the function NewTimeOut()?
What do you expect to happen if the value is accidently negative?
3. Looks to me that CalculatedDays will be number of M,T,W,T,F days (ignores Sat-Sun).
How does the number of weekdays relate to UK holidays?

What does the rest of your code look like (including HTML and CSS)?
Was This Post Helpful? 0
  • +
  • -

#7 condmach  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 24-June 13

Re: Calculate UK Bank Holidays

Posted 27 June 2013 - 12:29 AM

There is no more code.

This simply takes a timeout number eg 3 days and depending on the current day of the week adds on days to cater for week ends... and returns NewTimeOut

Eg If Friday Today + 3 Days Timeout value would be Monday, but this is only 1 working day, this code adds 2 days (1 weekend) to make it Wednesday. i.e. NewTimeout 5 Days

Eg If Friday Today + 7 Days Timeout value would be next Friday, this code adds 4 days (2 weekends) to make it following Tuesday. i.e. NewTimeout 11 Days

With a Bank Holiday on the Monday
Eg If Friday Today + 3 Days Timeout value would be Monday, we need code which adds 2 days (1 weekend) plus an extra day for the Holiday. i.e. NewTimeout 6 Days

Thanks.
Was This Post Helpful? 0
  • +
  • -

#8 JMRKER  Icon User is offline

  • D.I.C Addict

Reputation: 129
  • View blog
  • Posts: 832
  • Joined: 25-October 08

Re: Calculate UK Bank Holidays

Posted 27 June 2013 - 07:51 AM

So how is the script to know if 'Today' (BTW: an unknown and not specified value)
is a normal Monday or a UK bank holiday Monday?

And is the 'Today' always positive?
Is 'Friday' always a future day (not last Friday) and it is always represented as a value of '5'?

It may be all the code you have, but you need to specify more information to solve it.
Sort of like solving a polynomial formula with only one known.
:whistling:/>/>

Just a guess as to what you want to do with some HTML code to change input for calculations.
<!DOCTYPE HTML>
<html>
<head>
<title> Untitled </title>
<meta charset="utf-8">

</head>
<body>
<input type="text" id="futureDays" value="" size="3">

 <!-- following is a poorly named function BTW -->
<button onclick="alert(NewTimeOut(document.getElementById('futureDays').value))">
 Weekday count </button>

<script type="text/javascript">
// From: http://www.dreamincode.net/forums/topic/323511-calculate-uk-bank-holidays/page__gopid__1867754&#entry1867754

function NewTimeOut(Counter) {
  var CalculatedDays=0;
  var today = new Date().getDay();  // possible values 0-6 (Sun-Sat)
  while (Counter > 0) {

// following logic STILL DOES NOT KNOW if Monday is a UK holiday!!!
    if ((today > 0) && (today < 6)) { CalculatedDays++; }

    today = ((today+1) % 7); 
    Counter--;
  }
  return CalculatedDays;
};

</script>

</body>
</html>


This post has been edited by JMRKER: 27 June 2013 - 08:11 AM

Was This Post Helpful? 0
  • +
  • -

#9 laytonsdad  Icon User is online

  • Cheese and Sprinkles
  • member icon

Reputation: 442
  • View blog
  • Posts: 1,892
  • Joined: 30-April 10

Re: Calculate UK Bank Holidays

Posted 27 June 2013 - 10:35 AM

View Postcondmach, on 25 June 2013 - 08:15 AM, said:

My apologies, seems Word was capitalising the code.

Why are you using Word? Using Word for editing is bad practice. It will make more issues than help. Just throwing that out there. :whistling:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1