Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

cal 5875707

Name: Anonymous 2008-12-17 19:59

$ cal 5875707
cal: year 5875707 not in range 1..5875706


What is the significance of the year 5875706? Why stop there? This seems like some kind of RMS Michael Shuttleworth ploy to fuck us over in the calendar department.

Name: Anonymous 2008-12-18 5:58

http://opengroup.org/susv3xcu/cal.html
The cal utility shall write a calendar to standard output using the Julian calendar for dates from January 1, 1 through September 2, 1752 and the Gregorian calendar for dates from September 14, 1752 through December 31, 9999 as though the Gregorian calendar had been adopted on September 14, 1752.
9999 is the STANDARD!!!

/* Copyright (c) 2008 Anonymous
 *
 * Permission to use, copy, modify, and/or distribute this software for any
 * purpose with or without fee is hereby granted, provided that you grant this
 * same permission to anyone you distribute it to without any additional
 * restrictions.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#include <inttypes.h>
#include <limits.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main(int argc, char **argv){
 uintmax_t year = 0;
 uintmax_t month = 0;
 int_fast8_t month_days = 0, day_of_week = 0;
 const char *month_names[12] = { "January", "February", "March", "April", "May",
  "June", "July", "August", "September", "October", "November", "December" };
 const int_fast8_t months_days[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31,
  30, 31 };
 time_t t = time(NULL);
 struct tm *time_struct = localtime(&t);
 switch(argc){
  case 1:
   year = time_struct->tm_year + 1900;
   month = time_struct->tm_mon + 1;
   break;
  case 2:
   year = strtoumax(argv[1], NULL, 10);
   month = time_struct->tm_mon + 1;
   break;
  default:
   month = strtoumax(argv[1], NULL, 10);
   year = strtoumax(argv[2], NULL, 10);
 }
 if(!year || !month || month > 12){
  fputs("learn to use cal, you idiot: http://opengroup.org/susv3xcu/cal.html",
   stderr);
  abort();
 }
 if(year > 9999){
  fputs("learn to use cal, you idiot: http://opengroup.org/susv3xcu/cal.html",
   stderr);
  abort();
 }
 if(year == 1752 && month == 9){
  puts("September 1752");
  puts("Su Mo Tu We Th Fr Sa");
  puts("       1  2 14 15 16");
  puts("17 18 19 20 21 22 23");
  puts("24 25 26 27 28 29 30");
  return 0;
 }else{
  printf("%s %d\n", month_names[month - 1], year);
  puts("Su Mo Tu We Th Fr Sa");
  month_days = months_days[month - 1];
  if(year > 1752 || (year == 1752 && month > 9)){
   /* Gregorian */
   if(month == 2 && !(year % 4) && year % 100 || !(year % 400))
    month_days = 29;
   time_struct->tm_mon = month - 1;
   time_struct->tm_year = year - 1900;
   time_struct->tm_mday = 1;
   t = mktime(time_struct);
   time_struct = localtime(&t);
   day_of_week = time_struct->tm_wday;
   day_of_week = ((153 * (month + 12 * ((14 - month) / 12) - 3) + 2) / 5 +
    365 * (year + 4800 - ((14 - month) / 12)) + (year + 4800 - ((14 - month) /
    12)) / 4 - (year + 4800 - ((14 - month) / 12)) / 100 + (year + 4800 - ((14 -
    month) / 12)) - 32044) % 7;
  }else{
   /* Julian */
   if(month == 2 && !(year % 4))
    month_days = 29;
   day_of_week = ((153 * (month + 12 * ((14 - month) / 12) - 3) + 2) / 5 +
    365 * (year + 4800 - ((14 - month) / 12)) + (year + 4800 - ((14 - month) /
    12)) / 4 - 32081) % 7;
  }
  for(int i = 0; i < day_of_week; ++i) fputs("   ", stdout);
  for(int i = 1; i <= month_days; ++i){
   printf("% 2u", i);
   ++day_of_week;
   putchar((day_of_week %= 7) ? ' ' : '\n');
  }
 }
 putchar('\n');
 return 0;
}

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List