Guest
2010-09-02, 02:10 PM
You should be able to translate your column of 2d 3w 5m strings into an adjacent column of real dates (exportable to OF) by selecting your oo3 source column (click its header to make the whole column blue), and then running an applescript like this, which will create a new column next to it, containing dates calculated as today+3w (three weeks) etc.
Code:
set dteToday to date (short date string of (current date))
tell application id "com.omnigroup.OmniOutlinerPro3"
tell front document
try
set oSrcCol to first selected column
on error
display dialog "No column selected ..." & return & return & ¬
"Select column containing 1d 2w 3m etc, and run the script again"
return
end try
set idSrc to id of oSrcCol
set oTgtCol to make new column at after oSrcCol with properties {name:"Resulting Dates", type:date}
set idTgt to id of oTgtCol
repeat with oRow in rows
copy dteToday to dteBase
set strDelta to value of cell id idSrc of oRow
set dteResult to my DatePlus(dteBase, strDelta)
if dteResult is not missing value then set value of cell id idTgt of oRow to dteResult
end repeat
end tell
end tell
on DatePlus(dte, strNUnits)
copy dte to dteNew
if length of strNUnits < 2 then return missing value
set strUnit to last character of strNUnits
try
set lngDelta to (text 1 thru ((length of strNUnits) - 1) of strNUnits) as integer
on error
return missing value
end try
ignoring case
if strUnit = "d" then
return dteNew + lngDelta * days
else if strUnit = "w" then
return dteNew + lngDelta * weeks
else if strUnit = "y" then
set (year of dteNew) to (year of dteNew) + lngDelta
return dteNew
else if strUnit = "m" then
-- Get current month and year
set lngMonth to (month of dteNew) * 1
set lngYear to (year of dteNew)
-- and simply add the increment to the month,
-- negative possibly getting something negative, and/or too large
set lngNewMonth to lngMonth + lngDelta
-- get the YEAR
set lngDateMonth to lngNewMonth mod 12
set lngYearDelta to lngNewMonth div 12
-- if we have gone down to a negative month, we are already in the previous year,
-- regardless of any multiples of 12
if lngDateMonth ≤ 0 then set lngYearDelta to (lngYearDelta - 1)
if lngYearDelta is not 0 then
set lngDateYear to lngYear + lngYearDelta
else
set lngDateYear to lngYear
end if
-- and the MONTH
if lngDateMonth is 0 then
set lngDateMonth to 12
else if lngDateMonth < 0 then
set lngDateMonth to (12 + lngDateMonth)
end if
-- and update the date variable
if lngYear is not lngDateYear then set (year of dteNew) to lngDateYear
if lngMonth is not lngDateMonth then set (month of dteNew) to lngDateMonth
else
return missing value
end if
end ignoring
dteNew
end DatePlus
Last edited by RobTrew; 2010-09-07 at 02:33 AM..
Reason: DatePlus() tested against Mathematica for all values -1000m to +1000m. Now passes test :-)