Page 1 of 1
Dates in Sequence
Posted: 2012-07-31 07:52:51
by jb
I’m sure this would be simple for those who know something about coding macros, but it’s beyond my abilities.
I need to make a document each page of which (50-100 pages, say) has a date at the top, whether as header or simply as the first line of text, including day of the week in this form: Mon 30 July. Dates must be in sequence.
So how can I get a macro that generates a list like the following?
Mon 30 July
Tues 31 July
Wed 1 Aug
Thur 2 Aug
The exact form of the date is not so important; whether it’s ‘Jul’ or ‘July’ for example, or 'Monday' rather than 'Mon' I don’t care.
Thanks
For my purposes it would be best to insert page break after month, but I *do* know how to do that

Re: Dates in Sequence
Posted: 2012-07-31 15:34:16
by martin
This will be possible, though we might have to use some perl code for date calculations.
But first, let's get specific: how do you want to determine the date range? Do you always want the macro to start with the current date? And how many pages do you want exactly? Do you just want to enter in a number of page, or would it be more convenient to specify a final date?
Re: Dates in Sequence
Posted: 2012-07-31 17:01:07
by jb
Thanks, Martin.
I did have a look at the macro reference and wasn't able to see how this might be done. So I'm not too surprised to hear that pearl is required.
This macro will be useful for me in the future as well, and I don't know how many dates/pages I might want at another time. So some ability to choose a range would be helpful.
Ideally there would be a dialog asking for start and end dates, I suppose. But # of pages is also fine.
I'd be happy with either.
Thanks again
Re: Dates in Sequence
Posted: 2012-08-02 10:08:12
by Kino
A few years ago, I posted a macro for a similar purpose at
http://www.nisus.com/forum/viewtopic.php?p=16135#p16135 that I modified now so that, hopefully, it meets your needs.
Code: Select all
Require Pro Version 1.3
$indexToDayName = $indexToMonthName = Hash.new
$i = $j = 1
while $i < 8
$indexToDayName{$i%7} = Date.nameOfWeekday $i
$i += 1
end
while $j < 13
$indexToMonthName{$j} = Date.nameOfMonth $j
$j += 1
end
$now = Date.now
$today = $now.year & '-'
$today &= $now.month & '-'
$today &= $now.day
$date1 = Prompt Input 'From (year-month-day):', '', '', $today
$date2 = Prompt Input 'To (year-month-day):', '', '', $date1
$date1 = $date1.split '-'
$date2 = $date2.split '-'
$output = ''
Set Exported Perl Variables 'date1', 'date2', 'indexToDayName', 'indexToMonthName', 'output'
begin Perl
use Time::Local;
$i = timelocal (0, 0, 12, $date1[2], $date1[1]-1, $date1[0]);
$j = timelocal (0, 0, 12, $date2[2], $date2[1]-1, $date2[0]);
while ($i <= $j) {
@lt = localtime($i);
$output .= sprintf ("%s %01d %s\f", $indexToDayName{$lt[6]}, $lt[3], $indexToMonthName{$lt[4]+1});
$i += 86400;
}
end
$doc = Document.active
if $doc == undefined # if no document is open...
Document.new
end
Insert Text $output
jb wrote:For my purposes it would be best to insert page break after month, but I *do* know how to do that

I'm not very sure but am I right in supposing that page break should be inserted at the end of each date generated? In the macro above, page break is represended by
\f in
Code: Select all
$output .= sprintf ("%s %01d %s\f", $indexToDayName{$lt[6]}, $lt[3], $indexToMonthName{$lt[4]+1});
(if you prefer return, replace
\f with
\n.) But if you want page break to be inserted only after the last day of months, something a bit more complicated would be necessary.
Re: Dates in Sequence
Posted: 2012-08-03 01:56:21
by jb
Kino,
This is perfect. (Once again

)
Thank you.
Re: Dates in Sequence
Posted: 2012-08-10 15:51:34
by martin
Thank you very much for providing that macro Kino!