• 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: Date question with weeknumber
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Date question with weeknumber


  • Subject: Re: Date question with weeknumber
  • From: "Mark J. Reed" <email@hidden>
  • Date: Sun, 2 May 2010 16:55:21 -0400

Yeesh, what am I, chopped liver? :)  

On Sun, May 2, 2010 at 3:56 PM, Bert Groeneveld <email@hidden> wrote:
Hello Nigel,

Thank you for your answer. This script works really great!
I spent some time examining it but unfortunately I had to give up. I guess I don't have enough brains to exactly understand how it works. Or even better: I completely don't understand it!
I just implemented it as a handler in my main script (of course I put your name and today's date in a commented line, just in case I (or my script) gets famous ;).

Nigel, this is not the first time you helped me through with a date question. In my eyes you are really super as it comes to date-issues! Thanks a lot!

Bert.



On 24 apr 2010 (16), at 18:25, Nigel Garvey wrote:

In my message of Sat, 24 Apr 2010 17:14:12 +0100, I wrote:

Bert Groeneveld wrote on Fri, 23 Apr 2010 10:38:01 +0200:

Hello,

At some point in my script I know a weeknumber, for example set
myWeeknumber to "03", or set myWeeknumber to "52" (can be any
weeknumber in the future).
I want to find ou the date of the wednesday that falls in the week
with weeknumber myWeeknumber (this will be my startDate).
And I want to find out the date of the tuesday that falls in the week
after the week with weeknumber myWeeknumber (this will be my endDate).

The format of the startDate end endDate should be "23-04-2010" (23th
of april of 2010).

myWeeknumber is always a weeknumber in the future so when today falls
in week 52 of a given (this) year and myWeeknumber is set to "2" or
"02" then the startDate end the endDate fall in the next year of course.

This would be my take on it:

I wait all day for my Internet connection to be restored and then
discover a bad edit the instant after I finally post! Here's the
corrected script:

 -- ISO convention with Monday week starts.
 on getDateRange(startWeekNumber)
  set startWeekOffset to startWeekNumber - 1
  set baseMonday to date "Monday 3 January 1583 00:00:00"

  set now to (current date)
  set Jan4 to date "Tuesday 4 January 1583 00:00:00"
  set Jan4's year to now's year
  set yearStart to Jan4 - (Jan4 - baseMonday) mod weeks

  if ((now - yearStart) div weeks >= startWeekOffset) then
    set Jan4's year to (Jan4's year) + 1
    set yearStart to Jan4 - (Jan4 - baseMonday) mod weeks
  end if

  set startWeekStart to yearStart + startWeekOffset * weeks
  set startWednesday to formatDate(startWeekStart + 2 * days)
  set endTuesday to formatDate(startWeekStart + 8 * days)

  return {startWednesday, endTuesday}
 end getDateRange

 on formatDate(theDate)
  tell ((theDate's year) * 10000 + (theDate's month as integer) * 100
+ (theDate's day)) as text
    return text 7 thru 8 & "-" & text 5 thru 6 & "-" & text 1 thru 4
  end tell
 end formatDate

 getDateRange("03")
 --> {"19-01-2011", "25-01-2011"}


NG

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

Archives: http://lists.apple.com/archives/applescript-users

This email sent to 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:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden



--
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:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Follow-Ups:
    • Re: Date question with weeknumber
      • From: Bert Groeneveld <email@hidden>
References: 
 >Re: Date question with weeknumber (From: Bert Groeneveld <email@hidden>)

  • Prev by Date: Re: Date question with weeknumber
  • Next by Date: Re: Date question with weeknumber
  • Previous by thread: Re: Date question with weeknumber
  • Next by thread: Re: Date question with weeknumber
  • Index(es):
    • Date
    • Thread