• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Days and hours
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Days and hours


  • Subject: Re: Days and hours
  • From: "Nigel Garvey" <email@hidden>
  • Date: Mon, 17 Oct 2005 12:10:37 +0100

Bernard AZANCOT wrote on Sun, 16 Oct 2005 21:54:21 +0200:

>I would like to know how to calculate the number of work hours to pay
>to a person working for me, in a given month, knowing that each
>
>Monday                     -> 2,5 h.
>Tuesday                     -> 2,5 h.
>Wednesday                -> 2 h.
>Friday                         -> 2 h.
>
>My problem is that the number of mondays, etc. is not the same each
>month, and the 1st/last day of the month can be anyone.

The question assumes that the hours and weekdays will never ever vary,
which is unlikely. But here's a handler that allows the input of the
normally expected hours-per-weekday for the month in question. It's thus
only rigid for that month. In Tiger, the 'set w' line can be simplified
to 'set w to dx's weekday as integer'.

  on hoursWorkInMonth(theDate, hoursPerWeekday)
    -- Each month has at least 28 days, thus 4 of each weekday.
    tell hoursPerWeekday to set h to ((item 1) + (item 2) + (item 3) +
(item 4) + (item 5) + (item 6) + (item 7)) * 4

    --  Get the weekday number of the last day of the month.
    tell theDate + (32 - (theDate's day)) * days to set dx to it - (its
day) * days
    set w to (dx - (date "Sunday 3 January 1904 00:00:00")) mod weeks div
days + 1

    -- Add the hours for the last (month length - 28) weekdays to h.
    repeat with w from w - ((dx's day) - 29) to w
      set h to h + (item ((w + 6) mod 7 + 1) of hoursPerWeekday)
    end repeat

    return h
  end hoursWorkInMonth

  -- A list of hours per weekday, Sunday to Saturday.
  set hoursPerWeekday to {0, 2.5, 2.5, 2, 0, 2, 0}
  -- Any date in the target month.
  set payDay to date "Friday 28 October 2005 00:00:00"
  hoursWorkInMonth(payDay, hoursPerWeekday)


NG

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Days and hours
      • From: "Mark J. Reed" <email@hidden>
    • Re: Days and hours
      • From: "Mark J. Reed" <email@hidden>
  • Prev by Date: Re: Days and hours
  • Next by Date: mount volume
  • Previous by thread: Re: Days and hours
  • Next by thread: Re: Days and hours
  • Index(es):
    • Date
    • Thread