NISUS Archives

July 2011

NISUS@LISTSERV.DARTMOUTH.EDU

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
Þorvarður Davíðsson <[log in to unmask]>
Reply To:
Date:
Tue, 12 Jul 2011 02:50:26 +0200
Content-Type:
text/plain
Parts/Attachments:
text/plain (118 lines)
On 11.07.2011, at 20:01, Kino wrote:

> 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. (…)
> 
> 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).


Thank you, Kino. Your macro seems perfect.

I modified it a little bit in order to paste the result automatically into an open document, get the result on the clipboard and change names of weekdays from English to German (Danish, Italian or whatever).

I notice that if Sunday comes up I can’t chance the English weekday name to "Sonntag" which is the German equivalent. An example: If I enter 5, 12, 19 … days from now I ALWAYS receive "Sunday" instead of "Sonntag". By ALL other weekdays the macro works as expected, that means I get all the days correctly written in German.

What is wrong here? Is this a bug?



Žorvaršur 


---- BEGINNING OF MACRO -------------

$namesOfDay = Array.new
$namesOfDay[0] = Date.nameOfWeekday 7

	$namesOfDay[1] = "Montag"
	$namesOfDay[2] = "Dienstag"
	$namesOfDay[3] = "Mittwoch"
	$namesOfDay[4] = "Donnerstag"
	$namesOfDay[5] = "Freitag"
	$namesOfDay[6] = "Samstag"
	$namesOfDay[7] = "Sonntag"

$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 = $namesOfDay[$dayOfWeek] & ", den "
# This just adds the German article

$futureDate &= $day & '.'
$futureDate &= $month & '.'
$futureDate &= $year & ' '
#$futureDate &= $namesOfDay[$dayOfWeek]

Write Clipboard $futureDate
# This puts the result on the active clipboard
Insert Text $futureDate
# "Insert" instead of "Type" in order to keep the text selected after it has been pasted into the open document

#exit $futureDate
#This blocks a message saying that this macro has been completed


Exit

---- END OF MACRO -------------


Kino’s original macro:


> 
> $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
> 

ATOM RSS1 RSS2