Derivative script. This one finds intervals and translates them to regular dates. This has dependencies though, and I'm not certain it will always work. (e.g. in other years)
set date_code to "41-T"
set {x, y, week_code} to {items 1 thru -3 of date_code as text as number, item -1 of date_code, "MTWRFAU"}
repeat with i from 1 to length of week_code if y is item i of week_code then exit repeat end repeat
set full_date to (date ("1/1/" & year of (current date))) + (x * weeks) + ((i + 1) * days)
set {z, interval} to {return, {1, 4, 12, 24, 52}}
repeat with i in interval if (x - i) > 0 then set z to z & x - i & "-" & y & tab & (full_date - (i * weeks)) & return end repeat
" 40-T Tuesday, October 11, 2011 12:00:00 AM 37-T Tuesday, September 20, 2011 12:00:00 AM 29-T Tuesday, July 26, 2011 12:00:00 AM 17-T Tuesday, May 3, 2011 12:00:00 AM "
Correction, correction, correction. Disregard all above. I clearly didn't understand my math. This version should have the offset correctly adjusted. Remember, though, this is a static adjustment that will break from year to year and in special circumstances. I need to put in some code that gets the correct definition of the ISO standard involved.
set date_code to "42-T"
set {x, y, week_code} to {items 1 thru -3 of date_code as text as number, item -1 of date_code, "MTWRFAU"}
repeat with i from 1 to length of week_code if y is item i of week_code then exit repeat end repeat
set full_date to (date ("1/1/" & year of (current date))) + (x * weeks) + ((i - 6) * days)
set {z, interval} to {return, {1, 4, 12, 24, 52}}
repeat with i in interval if (x - i) > 0 then set z to z & x - i & "-" & y & tab & (full_date - (i * weeks)) & return end repeat
Comments 4
set date_code to "41-T"
set {x, y, week_code} to {items 1 thru -3 of date_code as text as number, item -1 of date_code, "MTWRFAU"}
repeat with i from 1 to length of week_code
if y is item i of week_code then exit repeat
end repeat
set z to (date ("1/1/" & year of (current date))) + (x * weeks) + ((i + 1) * days)
-- sample result: date "Tuesday, October 18, 2011 12:00:00 AM"
Needs more work, though.
Reply
set date_code to "41-T"
set {x, y, week_code} to {items 1 thru -3 of date_code as text as number, item -1 of date_code, "MTWRFAU"}
repeat with i from 1 to length of week_code
if y is item i of week_code then exit repeat
end repeat
set full_date to (date ("1/1/" & year of (current date))) + (x * weeks) + ((i + 1) * days)
set {z, interval} to {return, {1, 4, 12, 24, 52}}
repeat with i in interval
if (x - i) > 0 then set z to z & x - i & "-" & y & tab & (full_date - (i * weeks)) & return
end repeat
get z
Reply
40-T Tuesday, October 11, 2011 12:00:00 AM
37-T Tuesday, September 20, 2011 12:00:00 AM
29-T Tuesday, July 26, 2011 12:00:00 AM
17-T Tuesday, May 3, 2011 12:00:00 AM
"
Reply
set date_code to "42-T"
set {x, y, week_code} to {items 1 thru -3 of date_code as text as number, item -1 of date_code, "MTWRFAU"}
repeat with i from 1 to length of week_code
if y is item i of week_code then exit repeat
end repeat
set full_date to (date ("1/1/" & year of (current date))) + (x * weeks) + ((i - 6) * days)
set {z, interval} to {return, {1, 4, 12, 24, 52}}
repeat with i in interval
if (x - i) > 0 then set z to z & x - i & "-" & y & tab & (full_date - (i * weeks)) & return
end repeat
get z
Reply
Leave a comment