Reply to topic  [ 3 posts ] 
Class Calendar 
Author Message
User avatar

Joined: 2004-09-09 18:07:11
Posts: 333
Location: Utah
Every semester, I create a syllabus for my classes that includes a table with a list of dates and assignments for those dates. I have always done this by hand. Would it be possible to have a macro spit out a list of days/dates within a certain range (for MWF and T/Th) so I don't have to do this by hand? Something like

Monday 8/24
Wednesday 8/26

or

Tuesday 8/25
Thursday 8/27

Thanks in advance!


2009-08-23 20:36:07
Profile ICQ WWW

Joined: 2008-05-17 04:02:32
Posts: 400
Does this work as you expected? It will ask you to specify the first date, the last date and days of week and insert a table at the current insertion point (in a new document if there is no open document).

This macro does not check the validity of date format and that of a date itself. So you may get an unexpected result or an error if you give a wrong one. E.g. "2009-4-31" (wrong date in the valid format).

Code:
 Require Pro Version 1.3

$namesOfDay = Array.new
$namesOfDay[0] = Date.nameOfWeekday 7
$i = 1
while $i < 7
   $namesOfDay[$i] = Date.nameOfWeekday $i
   $i += 1
end

$indexToName = Hash.new
foreach $i, $n in $namesOfDay
   $indexToName{$i} = $n
end

$now = Date.now
$today = $now.year & '-'
$today &= $now.month & '-'
$today &= $now.day

$date1 = Prompt Input 'From...', '', '', $today
$date2 = Prompt Input 'To...', '', '', $date1
$date1 = $date1.split '-'
$date2 = $date2.split '-'

$checked = Prompt Checkboxes 'Check names of day', '', '', $namesOfDay
if ! $checked.count
   exit 'No item checked, exit...'
end

$checkedNames = Hash.new
foreach $name in $checked
   $i = $namesOfDay.indexOfValue $name
   $checkedNames{$i} = 1
end

$output = ''

Set Exported Perl Variables 'date1', 'date2', 'checkedNames', 'indexToName', '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);
      if (defined $checkedNames{$lt[6]}) {
         $output .= sprintf ("%s\t%01d/%01d\t\n", $indexToName{$lt[6]}, $lt[4]+1, $lt[3]);
      }
      $i += 86400;
   }
end

$doc = Document.active
if $doc == undefined  # if no document is open...
   Document.new
end

Insert Text $output
Menu ':Table:Convert to Table'

This macro uses Perl because Nisus Macro language does not have a command for generating an arbitrary date object and properties such as year, month, day are Read-only. I hope these limitations will be removed in a future version. Also I'd like to have a command such as
Code:
$dateObject = Prompt Date 'Message', 'Detail', 'Button', $defaultDateObject
which will prompt a dialog box having input fields with stepper for date and time, something like those in Date & Time system preferences pane.


2009-08-24 23:10:54
Profile
User avatar

Joined: 2004-09-09 18:07:11
Posts: 333
Location: Utah
I neglected to respond, but yes yes yes! This is perfect!


2009-09-27 13:19:55
Profile ICQ WWW
Display posts from previous:  Sort by  
Reply to topic   [ 3 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group
Designed by ST Software