Brett Terpstra created some date scripts back in 2010 to create a @start tag (if none is present) and if one is, the script would increment or decrement the date by a day.
Can anyone help me move these to JavaScript?
This one increments the date:
tell application "TaskPaper"
repeat with _task in «class TPse» as list
if exists «class TPtg» named "start" of _task then
set _datestring to («class TGvl» of («class TPtg» named "start" of _task))
set _fmt to (text items 6 thru 7 of _datestring) & "-" & (text items 9 thru 10 of _datestring) & "-" & (text items 1 thru 4 of _datestring) as string
set _val to (my getDate(_fmt)) + (1 * days) as string
set «class TGvl» of («class TPtg» named "start" of _task) to my formatDate(_val)
else
tell _task to make «class TPtg» with properties {name:"start", «class TGvl»:my formatDate(date string of (current date))}
end if
end repeat
end tell
on formatDate(_date)
set theDate to date _date
set _year to theDate's year
copy theDate to b
set the month of b to January
set _month to (1 + (theDate - b + 1314864) div 2629728)
if (count of text items of (_month as string)) < 2 then set _month to "0" & (_month as string)
set _day to theDate's day
if (count of text items of (_day as string)) < 2 then set _day to "0" & (_day as string)
set _fmt to _year & "-" & _month & "-" & _day as string
return _fmt
end formatDate
on getDate(_fmt)
return date _fmt
end getDate`
And this one decrements the date:
tell application "TaskPaper"
repeat with _task in «class TPse» as list
if exists «class TPtg» named "start" of _task then
set _datestring to («class TGvl» of («class TPtg» named "start" of _task))
set _fmt to (text items 6 thru 7 of _datestring) & "-" & (text items 9 thru 10 of _datestring) & "-" & (text items 1 thru 4 of _datestring) as string
set _val to (my getDate(_fmt)) - (1 * days) as string
set «class TGvl» of («class TPtg» named "start" of _task) to my formatDate(_val)
else
tell _task to make «class TPtg» with properties {name:"start", «class TGvl»:my formatDate(date string of (current date))}
end if
end repeat
end tell
on formatDate(_date)
set theDate to date _date
set _year to theDate's year
copy theDate to b
set the month of b to January
set _month to (1 + (theDate - b + 1314864) div 2629728)
if (count of text items of (_month as string)) < 2 then set _month to "0" & (_month as string)
set _day to theDate's day
if (count of text items of (_day as string)) < 2 then set _day to "0" & (_day as string)
set _fmt to _year & "-" & _month & "-" & _day as string
return _fmt
end formatDate
on getDate(_fmt)
return date _fmt
end getDate