• 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: Week of year - odd/even week
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Week of year - odd/even week


  • Subject: Re: Week of year - odd/even week
  • From: Nigel Garvey <email@hidden>
  • Date: Fri, 1 Feb 2002 13:11:30 +0000

Emmanuel wrote on Fri, 1 Feb 2002 00:05:52 +0100:

>Below I give the script to compute the first day of the first week of the
>year which contains theDate.
>
>------------------------------ tested (was included in Smile's distribution)
>copy theDate to theFirst
>set day of theFirst to 1
>set month of theFirst to January
>set time of theFirst to 0
>repeat until (weekday of theFirst) is Thursday
> set day of theFirst to 1 + (get day of theFirst)
>end repeat
>repeat until (weekday of theFirst) is Monday
> set day of theFirst to 1 + (get day of theFirst)
>end repeat
>set theFirst to theFirst - 7 * 86400
>------------------------------

... which can be simplified to:

copy theDate to theFourth
set day of theFourth to 4
set month of theFourth to January
set theFourth to theFourth - (theFourth - (date "Monday, 6 January 1000
00:00:00")) mod weeks

(If, like me, you think a week starts on a Sunday, change the date in the
fourth line to 5th January 1000.)

Telescoping in the formula for calculating the week number gives:

copy theDate to theFourth
set day of theFourth to 4
set month of theFourth to January
1 + (theDate - theFourth + (theFourth - (date "Monday, 6 January 1000
00:00:00")) mod weeks) div weeks

NG


  • Follow-Ups:
    • Re: Week of year - odd/even week
      • From: Emmanuel <email@hidden>
  • Prev by Date: Re: Applescript Studio: How do I get started?
  • Next by Date: Re: How to coerce a real to an integer in X?
  • Previous by thread: Re: Week of year - odd/even week
  • Next by thread: Re: Week of year - odd/even week
  • Index(es):
    • Date
    • Thread