/* * Copyright (c) 2003 Scott M Harrison. All rights reserved. * * Redistribution and use in source and binary forms, with or * without modification, are permitted provided that the * following conditions are met: * * 1. Redistributions of source code must retain the * above copyright notice, this list of conditions * and the following disclaimer. * * 2. Redistributions in binary form must reproduce the * above copyright notice, this list of conditions * and the following disclaimer in the documentation * and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the * redistribution, if any, must include the following * acknowledgment: * * "This product includes software developed by * Scott M Harrison (mailto://scott@mithrandir.com)." * * Alternately, this acknowledgment may appear in the * software itself, if and wherever such third-party * acknowledgments normally appear. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ #include #include /* * This routine prints the Tranquility date for the structure * passed to it. */ void printTranquilityDateForDate(struct tm *aTime) { char *daysOfWeek[] = { "Thursday", "Friday", "Saturday", "Sunday", "Monday", "Tuesday", "Wednesday" }; char *months[] = { "Archimedes", "Brahe", "Copernicus", "Darwin", "Einstein", "Faraday", "Galileo", "Hippocrates", "Imhotep", "Jung", "Kepler", "Lavoisier", "Mendel" }; int daysInNonLeapYear = 365; int daysInTranquilityMonth = 28; int aldrinDay = 60; int armstrongDay = 201; int yearOfTranquility = 1969; int dayOfYear = aTime->tm_yday + 1; int yearOfCommonEra = aTime->tm_year + 1900; int isLeapYear = (((yearOfCommonEra % 4) == 0) && ((yearOfCommonEra % 400) != 100) && ((yearOfCommonEra % 400) != 200) && ((yearOfCommonEra % 400) != 300)); int tranquilityDayOfYear = 0; int specialDay = 0; int day; int month; int year; int afterArmstrongDay = dayOfYear > armstrongDay; if (isLeapYear) { if (dayOfYear > aldrinDay) { dayOfYear--; } else if (dayOfYear == aldrinDay) { specialDay = 1; } } if (dayOfYear == armstrongDay) { specialDay = 2; } tranquilityDayOfYear = dayOfYear - armstrongDay + (afterArmstrongDay ? 0 : daysInNonLeapYear); if (0 == specialDay) { month = (tranquilityDayOfYear - 1) / daysInTranquilityMonth; day = tranquilityDayOfYear - month * daysInTranquilityMonth; } else if (yearOfCommonEra == yearOfTranquility && 2 == specialDay) { specialDay = 3; } year = yearOfCommonEra - yearOfTranquility + (afterArmstrongDay ? 1 : 0); if (year <= 0) { year--; } switch (specialDay) { case 0: printf("%s, %s %d,", daysOfWeek[day % 7], months[month], day); break; case 1: printf("Aldrin Day"); break; case 2: printf("Armstrong Day"); break; case 3: printf("Moon Landing Day"); break; default: printf("Error with special day of %d", specialDay); break; } if (3 != specialDay) { printf(" %d", abs(year)); if (year < 0) { printf(" BT"); } } printf("\n"); return; } int main(int argc, char *argv[]) { time_t currentTime = time(NULL); struct tm *timeHere = localtime(¤tTime); printTranquilityDateForDate(timeHere); exit(0); return 0; }