By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,086 Members | 1,875 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,086 IT Pros & Developers. It's quick & easy.

Looking for paid-time-off javascript function

P: n/a
Hi there,

I am looking for a javascript function that someone might have already
written to calculate the paid-time-off.

Given are the start and end date and time. I need to calculate the
paid-time-off. That means the formula needs to be smart enough to figure out
the Saturdays and Sundays within the period and subtract the time from the
time period.

Has anybody some code to share with me or can you point me into the right
direction to get this functionality written?

Thanks a bunch,
Daniela
Jul 20 '05 #1
Share this Question
Share on Google+
12 Replies


P: n/a
Daniela Nii wrote:
Hi there,

I am looking for a javascript function that someone might have already
written to calculate the paid-time-off.

Given are the start and end date and time. I need to calculate the
paid-time-off. That means the formula needs to be smart enough to figure out
the Saturdays and Sundays within the period and subtract the time from the
time period.

Has anybody some code to share with me or can you point me into the right
direction to get this functionality written?


Start by explaining how you would manually calculate it, and post it.
Someone might be willing to write it, maybe not. But to simply say "I
want a paid time off" calculator is stretching it a bit.
The first year, I get 5 days paid vacation (1 calendar week)
The second year, I get 10 days paid vacation (2 calendar weeks)
The third year, I get 15 days paid vacation (3 calendar weeks)

I have been there since I got hired so I will get 3 calendar weeks paid
time off this calendar year. I doubt that fits your situation though.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/

Jul 20 '05 #2

P: n/a
JRS: In article <Jg****************@newsread2.news.pas.earthlink.n et>,
seen in news:comp.lang.javascript, Daniela Nii
<da*********@earthlink.net> posted at Wed, 28 Jan 2004 23:07:21 :-
I am looking for a javascript function that someone might have already
written to calculate the paid-time-off.

Given are the start and end date and time. I need to calculate the
paid-time-off. That means the formula needs to be smart enough to figure out
the Saturdays and Sundays within the period and subtract the time from the
time period.


See FAQ and sig below.

<URL:http://www.merlyn.demon.co.uk/js-date7.htm#CWD>

--
John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4
<URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 20 '05 #3

P: n/a
Thanks, Dr. Stockton,

Those date functions are in the right direction. I will see if I can adjust
them for my purpose.

Daniela

"Dr John Stockton" <sp**@merlyn.demon.co.uk> wrote in message
news:YI**************@merlyn.demon.co.uk...
JRS: In article <Jg****************@newsread2.news.pas.earthlink.n et>,
seen in news:comp.lang.javascript, Daniela Nii
<da*********@earthlink.net> posted at Wed, 28 Jan 2004 23:07:21 :-
I am looking for a javascript function that someone might have already
written to calculate the paid-time-off.

Given are the start and end date and time. I need to calculate the
paid-time-off. That means the formula needs to be smart enough to figure outthe Saturdays and Sundays within the period and subtract the time from thetime period.
See FAQ and sig below.

<URL:http://www.merlyn.demon.co.uk/js-date7.htm#CWD>

--
John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE

4 <URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang.javascript <URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources. <URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items,

links.
Jul 20 '05 #4

P: n/a
Hi Randy,

I was hoping that somebody had to do some HR (Human Resources) web
programming where an employee would go on an intranet to request paid time
off (PTO) by entering a start date/time and end date/time. It then would
calculate the actual workdays and hours for his entered period.

As an example, he enters: Tue, Jan 20, 2004, 12:00 noon - Tue, Jan 27, 2004,
8:00 am. The PTO would be 4 days, 4 hours.

Daniela
Jul 20 '05 #5

P: n/a
: Those date functions are in the right direction. I will see if I can
adjust
: them for my purpose.

Have also a look on www.javascriptsource.com
They have day/date calculators I think.

Wouter
Jul 20 '05 #6

P: n/a
"DJ WIce" <contextmenu @ djwice.com> wrote in message
news:bv**********@news.tudelft.nl...
:Those date functions are in the right direction. I will
:see if I can adjust them for my purpose.

Have also a look on www.javascriptsource.com
They have day/date calculators I think.


javascriptsource.com may have literally thousands of scripts but when I
spent an hour looking through them I was unable to find one that was of
a suitable standard to be recommending to anyone. The bulk were
amateurish and out of date, really better avoided entirely.

Richard.
Jul 20 '05 #7

P: n/a
Daniela Nii wrote:
Hi Randy,

I was hoping that somebody had to do some HR (Human Resources) web
programming where an employee would go on an intranet to request paid time
off (PTO) by entering a start date/time and end date/time. It then would
calculate the actual workdays and hours for his entered period.

As an example, he enters: Tue, Jan 20, 2004, 12:00 noon - Tue, Jan 27, 2004,
8:00 am. The PTO would be 4 days, 4 hours.


Now it makes sense to me what you were trying to do. Might be something
I tinker with this weekend - no guarantees. Seems trivial at first
thought though. (Obviously is isn't)

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/

Jul 20 '05 #8

P: n/a
: Has anybody some code to share with me or can you point me into the right
: direction to get this functionality written?

Maybe you don't mind to use Excell instead?

Field1: StartDate, format: d-mm-jj u:mm;
Field2: EndDate, format: d-mm-jj u:mm;

Field4: Field2-Field1, format: d \d\ay\s u ho\ur\s mm \mi\n\ut\e\s;

Then you have the time between.
Now you have to count the # of saterdays and sundays dan substract them.

Determine the first saterday and devide the left period of days by 7 ceil
that value.
Determine the first sunday and devide the left period of days by 7 ceil that
value.
if the first day is a saterday ..
if the first day is a sunday ..
Works pretty fast and nice in Excell :-)

The export of that to HTML has problems when you use dates where the start
time is lower than the time on the end date.
The \ are to tell Excell not to interpret that but to print it.
Wouter
Jul 20 '05 #9

P: n/a
JRS: In article <ck*****************@newsread1.news.pas.earthlink. net>,
seen in news:comp.lang.javascript, Daniela Nii
<da*********@earthlink.net> posted at Thu, 29 Jan 2004 19:39:52 :-
Those date functions are in the right direction. I will see if I can adjust
them for my purpose. "Dr John ...


Responses should go after trimmed quotes, as per FAQ and established
usenet convention. Compliance earns consideration.

It appears that you are assuming a 5-day week of 8-hour days. On that
basis, the working-days-since-origin function can easily be adapted to
working-hours-since-origin.

Summer Time will not start/finish within working hours; nevertheless, it
could cause error. Test.

ISTM that you will need to add holiday information - see "Working Days
Ahead" on that page, and <URL:http://www.merlyn.demon.co.uk/holidays.htm>

--
John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME
Web <URL:http://www.uwasa.fi/~ts/http/tsfaq.html> -> Timo Salmi: Usenet Q&A.
Web <URL:http://www.merlyn.demon.co.uk/news-use.htm> : about usage of News.
No Encoding. Quotes before replies. Snip well. Write clearly. Don't Mail News.
Jul 20 '05 #10

P: n/a
JRS: In article <bv*******************@news.demon.co.uk>, seen in
news:comp.lang.javascript, Richard Cornford
<Ri*****@litotes.demon.co.uk> posted at Fri, 30 Jan 2004 00:56:06 :-
"DJ WIce" <contextmenu @ djwice.com> wrote in message
news:bv**********@news.tudelft.nl...
:Those date functions are in the right direction. I will
:see if I can adjust them for my purpose.

Have also a look on www.javascriptsource.com
They have day/date calculators I think.


javascriptsource.com may have literally thousands of scripts but when I
spent an hour looking through them I was unable to find one that was of
a suitable standard to be recommending to anyone. The bulk were
amateurish and out of date, really better avoided entirely.


I didn't take an hour; but I went straight to Calendars : Days left.

Obviously the author does not understand the uses of the Date Object; to
calculate the length of the current month, he has an array of month
lengths, correcting the second entry with a three-term leap expression.

There is little point in using anything better than Leap = Year % 4 = 0
or maybe Year & 3 = 0, for current dates.

function MonthLength(y, m) { // NS4 ?
return new Date(y, m+1, 1, -9).getDate() }

does all but the final subtraction of his code.

--
John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4
<URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 20 '05 #11

P: n/a
"Dr John Stockton" <sp**@merlyn.demon.co.uk> wrote in message
news:iH**************@merlyn.demon.co.uk...
<snip>
Have also a look on www.javascriptsource.com
They have day/date calculators I think.
javascriptsource.com may have literally thousands of scripts
but when I spent an hour looking through them I was unable
to find one that was of a suitable standard to be recommending
to anyone. ...

<snip>I didn't take an hour; but I went straight to Calendars :
Days left.


In context only the quality of the date/time scripts are significant.
When I was looking at the site I was trying to make an assessment of the
entire collection and given 2000+ scripts I thought a random sample of
more than 100 would be required. Admittedly, when I had dismissed the
first 20 as really very bad I was not optimistic about the prospect of
finding any good scripts on the site, but it did not seem fair to
dismiss the entire collection (publicly) without taking a reasonable
sample.

Richard.
Jul 20 '05 #12

P: n/a

: function MonthLength(y, m) { // NS4 ?
: return new Date(y, m+1, 1, -9).getDate() }

Code that I use to correct the date (in the time stamp on my pages):

// Y2K bugfix for Netscape
if (year<100) year += 2000; else if (year<200) year += 1900;

This should work for the next 95 years :-)
Wouter
Jul 20 '05 #13

This discussion thread is closed

Replies have been disabled for this discussion.