Calender outline maker

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Calender outline maker

Steve Litt
Hi all,

I needed a calendar in outline form in order to keep track of my day to day
accomplishments. I implemented it as a Perl program that takes the year on
the command line, and spits out the calendar via stdout, which can be
redirected to a file.

I then incorporated it into my menu system (UMENU) with a script, so now all I
do is choose "Make calendar outline for this year", and if no outline exists,
it creates one, otherwise it issues an error message rather than write over
an existing calendar outline.

I think the VimOutliner crew already has stuff way beyond this simple script,
so I'm copying them also.

Below my sig is the script.

SteveT



#!/usr/bin/perl -w
#Copyright (C) 2005 by Steve Litt, all rights reserved.
#Licensed under version 2 of the GNU General Public License.

use strict;
use Time::Local;

# GLOBAL DATA
my $secondsPerDay = 60*60*24;
my @monthnames = ('Zero', 'January', 'February', 'March', 'April',
        'May', 'June', 'July', 'August', 'September', 'October',
        'November', 'December');
my @daynames = ('Sunday', 'Monday', 'Tuesday', 'Wednesday',
        'Thursday', 'Friday', 'Saturday');

# PROGRAM LOGIC
sub main()
        {
        # HANDLE YEAR ARGUMENT, CONVERT TO SECONDS SINCE EPOCH
        my $calYear = shift(@ARGV);
        if(!defined($calYear))
                {
                print STDERR "makecal must have one argument, the year\n";
                exit(1);
                }
        elsif(!($calYear =~m/^\d\d\d\d$/))
                {
                print STDERR "usage makecal year\n";
                exit(1);
                }
        my $time = timelocal(0,0,0,1,0,$calYear);


        # INITIALIZE struct_tm
        my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
                        localtime($time);

        # ADJUST
        $mon++;        # Make it 1 based instead of zero based
        $year += 1900;  # Make 4 digit y2k compliant

        # INITIALIZE BREAK LOGIC
        my $hold_mday = 9999;
        my $hold_mon = 0;
        my $hold_year = $year;

        # LOOP THROUGH DAYS OF YEAR
        while($year == $hold_year)
                {
                # BREAK LOGIC
                if($mon  > $hold_mon) # new month
                        {
                        printf("%s %4d\n", $monthnames[$mon], $year);
                        }
                elsif($wday == 1)
                        {
                        print "\t-\n";
                        }

                # PRINT THE DAY'S LINE
                printf("\t%02d/%02d/%04d (%s)\n",
                        $mon, $mday, $year, $daynames[$wday]);

                # HOLD VALUES FOR NEXT ITERATION'S BREAK LOGIC
                $hold_year = $year;
                $hold_mday = $mday;
                $hold_mon = $mon;

                # INCREMENT
                $time += $secondsPerDay;
                ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
                        localtime($time);

                # ADJUST
                $mon++;        # Make it 1 based instead of zero based
                $year += 1900;  # Make 4 digit y2k compliant
                }
        print "# vim600: set foldlevel=0:\n";
        }

main();
_______________________________________________
VimOutliner mailing list
[hidden email]
http://www.lists.vimoutliner.org/mailman/listinfo/vimoutliner