Looking for paid-time-off javascript function

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Daniela  Nii

    Looking for paid-time-off javascript function

    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


  • Randy Webb

    #2
    Re: Looking for paid-time-off javascript function

    Daniela Nii wrote:
    [color=blue]
    > 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?[/color]

    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.javas cript FAQ - http://jibbering.com/faq/

    Comment

    • Dr John Stockton

      #3
      Re: Looking for paid-time-off javascript function

      JRS: In article <JgXRb.1085$F23 .931@newsread2. news.pas.earthl ink.net>,
      seen in news:comp.lang. javascript, Daniela Nii
      <daniela.nii@ea rthlink.net> posted at Wed, 28 Jan 2004 23:07:21 :-
      [color=blue]
      >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.[/color]

      See FAQ and sig below.

      <URL:http://www.merlyn.demo n.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.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
      <URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.

      Comment

      • Daniela  Nii

        #4
        Re: Looking for paid-time-off javascript function

        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" <spam@merlyn.de mon.co.uk> wrote in message
        news:YIB6OKH2aQ GAFwJp@merlyn.d emon.co.uk...[color=blue]
        > JRS: In article <JgXRb.1085$F23 .931@newsread2. news.pas.earthl ink.net>,
        > seen in news:comp.lang. javascript, Daniela Nii
        > <daniela.nii@ea rthlink.net> posted at Wed, 28 Jan 2004 23:07:21 :-
        >[color=green]
        > >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[/color][/color]
        out[color=blue][color=green]
        > >the Saturdays and Sundays within the period and subtract the time from[/color][/color]
        the[color=blue][color=green]
        > >time period.[/color]
        >
        > See FAQ and sig below.
        >
        > <URL:http://www.merlyn.demo n.co.uk/js-date7.htm#CWD>
        >
        > --
        > © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE[/color]
        4 ©[color=blue]
        > <URL:http://jibbering.com/faq/> Jim Ley's FAQ for[/color]
        news:comp.lang. javascript[color=blue]
        > <URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates,[/color]
        sources.[color=blue]
        > <URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items,[/color]
        links.


        Comment

        • Daniela  Nii

          #5
          Re: Looking for paid-time-off javascript function

          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


          Comment

          • DJ WIce

            #6
            Re: Looking for paid-time-off javascript function

            : 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


            Comment

            • Richard Cornford

              #7
              Re: Looking for paid-time-off javascript function

              "DJ WIce" <contextmenu @ djwice.com> wrote in message
              news:bvc6ag$lvd $1@news.tudelft .nl...[color=blue]
              >: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.[/color]

              javascriptsourc e.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.


              Comment

              • Randy Webb

                #8
                Re: Looking for paid-time-off javascript function

                Daniela Nii wrote:[color=blue]
                > 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.[/color]

                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.javas cript FAQ - http://jibbering.com/faq/

                Comment

                • DJ WIce

                  #9
                  Re: Looking for paid-time-off javascript function

                  : 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


                  Comment

                  • Dr John Stockton

                    #10
                    Re: Looking for paid-time-off javascript function

                    JRS: In article <ckdSb.1757$uM2 .1198@newsread1 .news.pas.earth link.net>,
                    seen in news:comp.lang. javascript, Daniela Nii
                    <daniela.nii@ea rthlink.net> posted at Thu, 29 Jan 2004 19:39:52 :-
                    [color=blue]
                    >Those date functions are in the right direction. I will see if I can adjust
                    >them for my purpose.[/color]
                    [color=blue]
                    >"Dr John ...[/color]

                    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.demo n.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.demo n.co.uk/news-use.htm> : about usage of News.
                    No Encoding. Quotes before replies. Snip well. Write clearly. Don't Mail News.

                    Comment

                    • Dr John Stockton

                      #11
                      Re: Looking for paid-time-off javascript function

                      JRS: In article <bvca37$ban$1$8 30fa7b3@news.de mon.co.uk>, seen in
                      news:comp.lang. javascript, Richard Cornford
                      <Richard@litote s.demon.co.uk> posted at Fri, 30 Jan 2004 00:56:06 :-[color=blue]
                      >"DJ WIce" <contextmenu @ djwice.com> wrote in message
                      >news:bvc6ag$lv d$1@news.tudelf t.nl...[color=green]
                      >>: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.[/color]
                      >
                      >javascriptsour ce.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.[/color]

                      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.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
                      <URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.

                      Comment

                      • Richard Cornford

                        #12
                        Re: Looking for paid-time-off javascript function

                        "Dr John Stockton" <spam@merlyn.de mon.co.uk> wrote in message
                        news:iHjEtqJ9Is GAFwPA@merlyn.d emon.co.uk...
                        <snip>[color=blue][color=green][color=darkred]
                        >>> Have also a look on www.javascriptsource.com
                        >>> They have day/date calculators I think.[/color]
                        >>
                        >>javascriptsou rce.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. ...[/color][/color]
                        <snip>[color=blue]
                        >I didn't take an hour; but I went straight to Calendars :
                        >Days left.[/color]

                        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.


                        Comment

                        • DJ WIce

                          #13
                          Re: Looking for paid-time-off javascript function


                          : 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


                          Comment

                          Working...