[net.sources] Shopping Reminder for /bin/login

john@frog.UUCP (John Woods, Software) (11/25/85)

The following is a code fragment which I installed into the login program
at mitccc, which is also suitable for independant use.  The day after
Thanksgiving, it starts announcing how many shopping days are left until
Christmas :-).  (Note that it assumes that ALL days are shopping days, which
in Massachussetts only recently became true...)

I wanted to also include days til Hannukah, but (1) it is much harder to
track a moving target :-), and (2) no one I asked could think of an
appropriate adjective, since it isn't such a shopping frenzy...

Well, here it is:

#include <time.h>

christmas()
{
	struct tm *Today;
	long t;
	int ndays;
		
	time (& t);

	Today = localtime (& t);
		
	switch (Today->tm_mon)
	{
	case 10:	/* November */
		if (Today->tm_mday <= thanksgiving
					 (Today->tm_mday, Today->tm_wday))
			return;

		ndays = 55 - Today->tm_mday;

		break;
	case 11:	/* December */
		if (Today->tm_mday > 25)
			return;

		ndays = 25 - Today->tm_mday;

		break;
	default:
		return;
	}

	switch (ndays)
	{
	case 0:
		printf("It's Christmas!  What are you doing here?\n");
		break;
	case 1:
		printf("Last shopping day before Christmas!\n");
		break;
	default:
		printf("Only %d more shopping days before Christmas\n", ndays);
		break;
	}
}

/*
 *	The 1 based day of November Thanksgiving falls indexed by the 0 based
 *	day of the week the 1st of November falls on.
 *	23 Nov 1985 -- how did such a mistake pass?  Thanksgiving is the fourth
 *	Thursday in November. -jfw
 */
int TDay[7] =
{
	26,25,24,23,22,28,27
};

/* Return day of november thanxgiving falls on */

thanksgiving (mday, wday)
	int mday, wday;
{
	int d = (mday - 1) % 7;

	if (d > wday)
		wday += 7;

	wday -= d;

	/* wday is now day that 1 Nov was */

	return TDay[wday];
}




--
John Woods, Charles River Data Systems, Framingham MA, (617) 626-1101
...!decvax!frog!john, ...!mit-eddie!jfw, jfw%mit-ccc@MIT-XX.ARPA

Out of my way, I'm a scientist!
	War of the Worlds

ron@brl-sem.ARPA (Ron Natalie <ron>) (11/28/85)

> The following is a code fragment which I installed into the login program
> at mitccc, which is also suitable for independant use.  The day after
> Thanksgiving, it starts announcing how many shopping days are left until
> Christmas :-).  (Note that it assumes that ALL days are shopping days, which
> in Massachussetts only recently became true...)
> 
If you have the PWB or SYSTEM III/V date program you can just stick
this in your profile and not bother with modifying login.

	echo Only `expr 359 - \`date +%j\`` days until Christmas!

Not quite as fancy, but adequate.

-Ron