Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10 beta 3/9/83; site frog.UUCP Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!cybvax0!frog!john From: john@frog.UUCP (John Woods, Software) Newsgroups: net.sources Subject: Shopping Reminder for /bin/login Message-ID: <279@frog.UUCP> Date: Mon, 25-Nov-85 14:55:33 EST Article-I.D.: frog.279 Posted: Mon Nov 25 14:55:33 1985 Date-Received: Thu, 28-Nov-85 04:13:06 EST Distribution: net Organization: Charles River Data Systems, Framingham MA Lines: 96 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 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