/*
 * dni-do-konca.c
 *
 * Copyleft: (c) 2012 by Szymon Urbaƛ <urbas@hush.ai>
 *
 * License: the MIT license
 *
 * About:
 *
 *   The program prints how many days there are to the end of school year.
 *
 * Compile:
 *
 *   make
 *
 */

#include <stdio.h>
#include <time.h>

int main(void){
  time_t current_year, raw_time;
  int day, month, year;
  struct tm t, *ct;

  time(&current_year);
  localtime_r(&current_year, &t);

  if (t.tm_mon == 5 || t.tm_mon == 6){
    printf("As Billy Joe would say.. HOLIDAY!\n");
    return 0;
  }

  printf("End of school year: (dd/mm/yyyy) ");
  scanf("%d/%d/%d", &day, &month, &year);

  time(&raw_time);
  ct = localtime(&raw_time);
  ct->tm_mday = day;
  ct->tm_mon  = month - 1;
  ct->tm_year = year - 1900;

  mktime(ct);

  if (ct->tm_yday - t.tm_yday > 0){
    printf("There are %d days left to the end of school!\n", (ct->tm_yday + 1) - (t.tm_yday + 1));
  } else if (ct->tm_yday - t.tm_yday == 0){
    printf("Yay, it's today!\n");
  } else {
    printf("Hey, you missed the end of school..\n");
  }

  return 0;
}