On 2011-07-12 [+0900 JST], at 1:24 AM, Žorvaršur Davķšsson wrote:
> I would like to have a macro that tells me what date there will be in 145 days from now, for example. The latest version of TypeIt4Me (v. 5.2) has a similar, nice feature which allows adding or subtracting days and/or months for future or past events. Can this be done in NWP with a macro?
Unfortunately NWP macro's Date object is read-only. So you have to call Perl in a macro like the one below (not tested enough).
Kino
--
$namesOfDay = Array.new
$namesOfDay[0] = Date.nameOfWeekday 7
$i = 1
while $i < 7
$namesOfDay[$i] = Date.nameOfWeekday $i
$i += 1
end
$now = Date.now
$day = $now.day
$month = $now.month - 1
$year = $now.year
$dayOfWeek = undefined
$detail = $now & ' (give a negative value to substract days)'
$add = Prompt Input 'How many days do you want to add?', $detail, '', '15'
Set Exported Perl Variables 'add', 'day', 'month', 'year', 'dayOfWeek'
begin Perl
use Time::Local;
$i = timelocal(0, 0, 12, $day, $month, $year);
$i += $add*86400;
@lt = localtime($i);
$day = $lt[3];
$month = $lt[4] + 1;
$year = $lt[5] + 1900;
$dayOfWeek = $lt[6];
end
$futureDate = $day & '-'
$futureDate &= $month & '-'
$futureDate &= $year & ' '
$futureDate &= $namesOfDay[$dayOfWeek]
exit $futureDate
|