• 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: "Mark J. Reed" <email@hidden>
  • Date: Mon, 17 Oct 2005 10:36:00 -0400

On 10/17/05, Mark J. Reed <email@hidden> wrote:
The formula for "number of occurrences of weekday Foo in month Bar" is really straightforward. 

Except I can't seem to type it successfully. :)


Given a month with  a total of D days (presumably between 28 and 31 inclusive, but the formula works for hypothetical calendars where that's not true) whose first day of the week starts on F (F=0 for Sunday, 1 for Monday,...,6 for Saturday), the number of occurrences of weekday W (again, 0=Sunday through 6=Saturday) is given by this formula:


floor(D/7) + floor( (D mod 7 + 1) / ((W - F) mod 7 + 2) )   (WRONG!)

That should be + 2 and + 3, not + 1 and + 2:

floor(D/7) + floor( (D mod 7 + 2) / ((W - F) mod 7 + 3) )


Here's the corrected AS version:


on countWeekdays(D, F, W)
    return floor(D/7) + floor( modulo(D,7) + 2 ) / ( modulo(W - F, 7) + 3 ) )
end countWeekdays

--
Mark J. Reed <email@hidden>
 _______________________________________________
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>
References: 
 >Re: Days and hours (From: "Nigel Garvey" <email@hidden>)
 >Re: Days and hours (From: "Mark J. Reed" <email@hidden>)

  • Prev by Date: Re: Days and hours
  • Next by Date: Re: Days and hours
  • Previous by thread: Re: Days and hours
  • Next by thread: Re: Days and hours
  • Index(es):
    • Date
    • Thread