<repo_name>LukasGlader/Calendar<file_sep>/date/julian.cpp
#include "julian.h"
#define IGREG (15+31L*(10+12L*1582))


namespace lab2{

Julian::Julian():Gregorian()
{
}

Julian::Julian(const Date& d)
{
	julian_day_number = d.julian_day();
}

Julian::Julian(int jdn)
{
	julian_day_number = jdn;
}

Julian::Julian(int year, int month, int day)
{
	is_valid(day, month, year);
	julian_day_number = julian_date_to_JDN(year, month, day);
}

	Julian::~Julian()
{
}

double Julian::julian_date_to_JDN(int year, int month, int day) const
{
	//std::cout << "Julian->JDN date: " << year <<"-"<<month<<"-"<<day<<" ->";

	if(year < 1 ){
		year++;
	}
	if( month <= 2 ){
		year--;
		month += 12;
	}
	double jdn = ((floor(365.25*(year+4716)) +
			floor(30.6001*(month+1))+day)-1524.5);
	//std::cout << (int)jdn << "\n";
	return jdn;
}

	day_month_year Julian::JDN_to_julian(double julian) const
{
	//std::cout << "\tJDN->Julian JDN: " << (int)julian << " -> ";
	day_month_year result;
	int day, month, year;

	int b = JDN_to_mod_julian_day(julian) + 2401525;
	int c = (int)((b - 122.1) / 365.25);
	int da = (int)(365.25 * c);
	int e = (int)((b - da) / 30.6001);
	month =(int)( (e < 14) ? (e - 1) : (e - 13) );
	year = (int)( (month > 2 ) ? (c - 4716) : (c - 4715));
	day = (int)(b-da-floor(30.6001*e));

	//std::cout << year <<"-"<<month<<"-"<<day<<"\n";
	result.day = day;
	result.month = month;
	result.year = year;
	return result;
}

	const int Julian::year() const
{
	day_month_year date = JDN_to_julian(julian_day_number);
	return date.year;
}

	const int Julian::month() const
{
	day_month_year date = JDN_to_julian(julian_day_number);
	return date.month;
}

	const int Julian::day() const
{
	day_month_year date = JDN_to_julian(julian_day_number);
	return date.day;
}

	Date& Julian::add_year(int n)
{
	if(is_leap_day())
	{
		if(is_leap_year(year() + n))
		{
			julian_day_number = julian_date_to_JDN(
				year() + n, month(), day());
		}else //jumping from leap day to non leap day.
		{
			julian_day_number = julian_date_to_JDN(
				year() + n, 2, 28);
		}
	}else
	{
		julian_day_number = julian_date_to_JDN(
			year() + n, month(), day());
	}
	return (*this);
}

	Date& Julian::sub_month()
{

	int next_year = year();
	int next_month = month();
	if(month() == 1)
	{
		next_month = 12;
		next_year--;
	}else
	{
		next_month--;
	}

	if(days_in_month(next_year, next_month) >= day())
	{
		julian_day_number = julian_date_to_JDN(next_year, next_month, day());
	}else
	{
		julian_day_number -= 30;
	}
	return (*this);
}


	Date& Julian::add_month()
{
	int next_year = year();
	int next_month = month();
	if(month() == 12)
	{
		next_month = 1;
		next_year++;
	}else
	{
		next_month++;
	}

	if(days_in_month(next_year, next_month) >= day())
	{
		julian_day_number = julian_date_to_JDN(next_year, next_month, day());
	}else
	{
		julian_day_number += 30;
	}
	return (*this);
}

	bool Julian::is_leap_year(int year) const
{
	return (year % 4 == 0);
}

const int Julian::week_day()const{
	// Julian
	int m = month();
	int y = year();
	if (m < 3){
		m += 12;
		y -=1;
	}
	int k = y % 100;
	int j = y /100;
	int h = ((day() + (int)(((m+1)*26)/10) + k + (int)(k/4) + 5 + (6*j))) % 7;
	h -= 1;
	if(h == 0){
		h = 7;
	}
	if(h == -1){
		h = 6;
	}
	return h;
}

}

<file_sep>/cal/date.cpp
#include "date.h"
namespace lab2{

Date::Date(void)
{

}


Date::~Date(void)
{
}

std::ostream& operator<<(std::ostream & os, const Date& d){
	os << d.year() << "-";
	int month = d.month();
	if(month < 10)
		os << "0";

	os << month << "-";
	
	int day = d.day();
	if(day < 10)
		os << "0";
	os << day;

	return os;
}

const int  Date::operator-(const Date& d) const{
	return (mod_julian_day() - d.mod_julian_day());
}

const bool Date::operator==(const Date& d) const{
	return (mod_julian_day() == d.mod_julian_day());
}
const bool Date::operator!=(const Date& d) const{
	return (mod_julian_day() != d.mod_julian_day());
}
const bool Date::operator<(const Date& d) const{
	return (mod_julian_day() < d.mod_julian_day());
}
const bool Date::operator<=(const Date& d) const{
	return (mod_julian_day() <= d.mod_julian_day());
}
const bool Date::operator>(const Date& d) const{
	return (mod_julian_day() > d.mod_julian_day());
}
const bool Date::operator>=(const Date& d) const{
	return (mod_julian_day() >= d.mod_julian_day());
}

}
<file_sep>/old/julian.cpp
#include "julian.h"

namespace lab2 {

Julian::Julian(int year, int month, int day) {
	checkValid(year, month, day);
    julianDayNumber = julianDateToJDN(year, month, day);
	jdnToJulianDate(julianDayNumber);
}

Julian::Julian(Date*& other) {
	jdnToJulianDate(other->mod_julian_day() + 2400000);
}

Julian::Julian(Date* other) {
	jdnToJulianDate(other->mod_julian_day() + 2400000);
}

Julian::Julian(const Date& other) {
	jdnToJulianDate(other.mod_julian_day() + 2400000);
}

Julian::Julian(int jdn) {
	jdnToJulianDate(jdn);
}

Julian::Julian():Gregorian() {
    jdnToJulianDate(julianDayNumber);
}

Julian::~Julian(void) {
}

const int Julian::days_this_month() const {
	return days_this_month(currentYear, currentMonth);
 }

int Julian::days_this_month(int year, int month) const{
	if(month == 0) month = 12;
	int result = 0;
		if(month == 2 && isLeapYear(year)){
			result = 29;
		}else{
			result = daysInMonth[month];
		}
	return result;
}

    //prefix
    Julian& Julian::operator++() {
        julianDayNumber++;
        jdnToJulianDate(julianDayNumber);
        return *this;
    }

    Julian& Julian::operator--() {
        julianDayNumber--;
        jdnToJulianDate(julianDayNumber);
        return *this;
    }

	const int Julian::week_day()const{
	int m = month();
	int y = year();
	if (m < 3){
		m += 12;
		y -=1;
	}
	int k = y % 100;
	int j = y /100;
	int h = ((day() + (int)(((m+1)*26)/10) + k + (int)(k/4) + 5 + (6*j))) % 7;
	h -= 1;
	if(h == 0){
		h = 7;
	}
	if(h == -1){
		h = 6;
	}
	return h;
}


/**
* Converts a julian date to a Julian Day Number
**/
int Julian::julianDateToJDN(int year, int month, int day) {

	if(year < 1 ){
		year++;
	}
	if( month <= 2 ){
		year--;
		month += 12;
	}
	return ((floor((365.25)*(year+4716)) +
			floor(30.6001*(month+1))+day)-1524.5);
    }


bool Julian::isLeapYear(int year) const {
	if(year % 4 == 0){
		return true;
	}else{
		return false;
	}
}


/**
* Converts a Julian Day Number to a Julian Date
**/
void Julian::jdnToJulianDate(int jdn) {

	int b = mod_julian_day() + 2401525;
	int c = (int)((b - 122.1) / static_cast<double>(365.25));
	int da = (int)(static_cast<double>(365.25) * c);
	int e = (int)((b - da) / 30.6001);
	currentMonth = (int)( (e < 14) ? (e - 1) : (e - 13) );
	currentYear = (int)( (currentMonth > 2 ) ? (c - 4716) : (c - 4715));
	currentDay = (int)(b-da-floor(30.6001*e));
}

    void Julian::operator+=(int n) {
        julianDayNumber += n;
        jdnToJulianDate(julianDayNumber);
    }

    void Julian::operator-=(int n) {
        julianDayNumber -= n;
        jdnToJulianDate(julianDayNumber);
    }

	Julian& Julian::operator=(const Date& d)
	{
        julianDayNumber = d.julianDayNumber;
        updateDateWithJDN(julianDayNumber);
		return *this;
	}
	void Julian::updateDateWithJDN(int jdn) {
		jdnToJulianDate(jdn);
		return;
	}

    Date& Julian::add_year(int n) {

	if(currentDay > days_this_month(currentYear+n, currentMonth))
	{
		julianDayNumber = julianDateToJDN(currentYear + n, currentMonth, days_this_month(currentYear + n,currentMonth));
	}else
	{
		julianDayNumber = julianDateToJDN(currentYear + n, currentMonth, currentDay);
	}
	jdnToJulianDate(julianDayNumber);
	return *this;
    }

	Date& Julian::add_month(int n) {
		int tmpYear = currentYear;
		int tmpMonth = currentMonth + n;
		tmpYear += tmpMonth/12;
		tmpMonth = tmpMonth % 12;
		if(tmpMonth <= 0)
		{
			tmpMonth = 12 + tmpMonth;
			--tmpYear;
		}
		if(currentDay > days_this_month(tmpYear,tmpMonth))
		{
			julianDayNumber = julianDateToJDN(tmpYear, tmpMonth, days_this_month(tmpYear,tmpMonth));
		}else
		{
			julianDayNumber = julianDateToJDN(tmpYear, tmpMonth, currentDay);
		}
		jdnToJulianDate(julianDayNumber);
		return *this;
	}
}
<file_sep>/old/julian.h
#pragma once

#include <math.h>
#include "gregorian.h"
#include <math.h>

namespace lab2{

class Julian :
	public Gregorian
{
public:

	Julian(void);
	Julian(int); //JDN Constructor
	Julian(Date*);
	Julian(Date*&);
	Julian(const Date&);
	Julian(int year, int month, int day);
	~Julian(void);

	const virtual int week_day() const;

	const virtual int days_this_month() const;
	int days_this_month(int year, int month) const;

	void jdnToJulianDate(int jdn);
	int julianDateToJDN(int year, int month, int day);
	
	//prefix
	virtual Julian& operator++();
	virtual Julian& operator--();

	Julian& operator=(const Date& d);
	void updateDateWithJDN(int jdn);

	virtual void operator+=(int n);
	virtual void operator-=(int n);

	virtual Date& add_year(int n = 1);
	virtual Date& add_month(int n = 1);

private:

protected:

	virtual bool isLeapYear(int year) const;

};
}
<file_sep>/old/date.h
#pragma once
#include <string>
#include <iostream>
namespace lab2{

class Date
{
public:
	Date(void);
	~Date(void);

	const virtual int year() const = 0;
	const virtual int month() const = 0;
	const virtual int day() const = 0;

	const virtual int week_day() const = 0;


	const virtual int days_per_week() const = 0;
	const virtual int days_this_month() const = 0;

	const virtual int months_per_year() const = 0;
	const virtual std::string week_day_name() const = 0;
	const virtual std::string month_name() const = 0;

	//prefix
	virtual Date& operator++() = 0;
	virtual Date& operator--() = 0;

	virtual void operator+=(int n) = 0;
	virtual void operator-=(int n) = 0;


	int julianDayNumber;

	virtual Date& add_year(int n = 1) = 0;
	virtual Date& add_month(int n = 1) = 0;

	virtual int mod_julian_day() const = 0;

	const virtual bool operator==(const Date& d) const;
	const virtual bool operator!=(const Date& d) const;
	const virtual bool operator<(const Date& d) const;
	const virtual bool operator<=(const Date& d) const;
	const virtual bool operator>(const Date& d) const;
	const virtual bool operator>=(const Date& d) const;
	const virtual int operator-(const Date& d) const;

};
std::ostream& operator<<(std::ostream & os, const Date& d);


}
<file_sep>/cal/gregorian.cpp
#include "gregorian.h"

namespace lab2{

	//spot 0 empty to avoid having to do index arithmetic later
	const std::string Gregorian::day_names[8] =
		{"INVALID_DAY",
		"monday",
		"tuesday",
		"wednesday",
		"thursday",
		"friday",
		"saturday",
		"sunday"};

	const std::string Gregorian::month_names[13] =
		{"INVALID_MONTH",
		"january",
		"february",
		"march",
		"april",
		"may",
		"june",
		"july",
		"august",
		"september",
		"october",
		"november",
		"december"};

	const int Gregorian::days_in_month_array[13] =
	{0,31,28,31,30,31,30,31,31,30,31,30,31};

Gregorian::Gregorian()
{

	time_t t;
	k_time(&t);	//time(t);
	julian_day_number = (t/86400)+ 2440587.5;
}

Gregorian::Gregorian(const Date& d)
{
	julian_day_number = d.julian_day();
}

Gregorian::Gregorian(int jdn)
{
	julian_day_number = jdn;
}

Gregorian::Gregorian(int year, int month, int day)
{
	is_valid(day, month, year);
	julian_day_number = gregorian_date_to_JDN(year, month, day);
}

	Gregorian::~Gregorian()
{
}

	int Gregorian::mod_julian_day() const
{
	return (int)JDN_to_mod_julian_day(julian_day_number);
}

	double Gregorian::JDN_to_mod_julian_day(double jdn) const
{
	return (jdn - 2400000.5);
}

	double Gregorian::julian_day() const
{
	return julian_day_number;
}

double Gregorian::gregorian_date_to_JDN(int y, int m, int d) const
{
	return (1721425.5 - 1) +
	(365 * (y - 1)) +
	(int)((y - 1) / 4) +
	(-(int)((y - 1) / 100)) +
	(int)((y - 1) / 400) +
	(int)((((367 * m) - 362) / 12) +
			((m <= 2) ? 0 :
			(is_leap_year(y) ? -1 : -2)
			) +
			d);
}


	day_month_year Gregorian::JDN_to_gregorian(double jd) const
{

	day_month_year result;
	int y, m, d;
	double j;

	j = jd - 1721119 + 0.5 ;
	y = (int)((4 * j - 1) / 146097 );
	j = 4 * j - 1 - 146097 * y ;
	d = (int)(j / 4) ;
	j = (4 * d + 3) / 1461 ;
	d = 4 * d + 3 - 1461 * j ;
	d = (d + 4) / 4 ;
	m = (5 * d - 3) / 153 ;
	d = 5 * d - 3 - 153 * m ;
	d = (d + 5) / 5 ;
	y = 100 * y + j ;
	if(m < 10)
	{
		m = m + 3;
	}else
	{
		m = m - 9 ; y = y + 1;
	}

	result.day = d;
	result.month = m;
	result.year = y;
	return result;
}

	const int Gregorian::year() const
{
	day_month_year date = JDN_to_gregorian(julian_day_number);
	return date.year;
}

	const int Gregorian::month() const
{
	day_month_year date = JDN_to_gregorian(julian_day_number);
	return date.month;
}

	const int Gregorian::day() const
{
	day_month_year date = JDN_to_gregorian(julian_day_number);
	return date.day;
}

	const int Gregorian::week_day() const
{
	int m = month();
	int y = year();
	if (m < 3){
		m += 12;
		y -=1;
	}
	int k = y % 100;
	int j = y /100;
	int h = ((day() + (int)(((m+1)*26)/10) + k + (int)(k/4) + (int)(j/4) + (5*j))) % 7;
	h -= 1;
	if(h == 0){
		h = 7;
	}
	if(h == -1){
		h = 6;
	}
	return h;
}

	const int Gregorian::days_per_week() const
{
	return 7;
}

	const int Gregorian::days_this_month() const
{
	return days_in_month(year(), month());
}

	const int Gregorian::months_per_year() const
{
	return 12;
}

int Gregorian::days_in_month(int year, int month) const
{
	if(month == 0) month = 12;
	int result = 0;
	if(month == 2 && is_leap_year(year)){
		result = 29;
	}else{
		result = days_in_month_array[month];
	}
	return result;
}

	const std::string Gregorian::week_day_name() const
{
	return day_names[week_day()];
}

	const std::string Gregorian::month_name() const
{
	return month_names[month()];
}

//prefix
Date& Gregorian::operator++()
{
	julian_day_number++;
	return *this;
}

Date& Gregorian::operator--()
{
	julian_day_number--;
	return *this;
}

//postfix
Gregorian Gregorian::operator++(int n)
{
	Gregorian old(year(), month(), day());
	++(*this);

	return old;
}

Gregorian Gregorian::operator--(int n)
{
	Gregorian old(year(), month(), day());
	--(*this);

	return old;
}

void Gregorian::operator+=(int n)
{
	julian_day_number+= n;
}

void Gregorian::operator-=(int n)
{
	julian_day_number-= n;
}

Gregorian& Gregorian::operator=(const Date& d)
{
	int jdn = d.julian_day();
	julian_day_number = jdn;
	return *this;
}

	Date& Gregorian::add_year(int n)
{
	if(is_leap_day())
	{
		if(is_leap_year(year() + n))
		{
			julian_day_number = gregorian_date_to_JDN(
				year() + n, month(), day());
		}else //jumping from leap day to non leap day.
		{
			julian_day_number = gregorian_date_to_JDN(
				year() + n, 2, 28);
		}
	}else
	{
		julian_day_number = gregorian_date_to_JDN(
			year() + n, month(), day());
	}
	return (*this);
}

	Date& Gregorian::add_year()
{
	add_year(1);
	return (*this);
}

	bool Gregorian::is_leap_day() const
{
	return (month() == 2 && day() == 29);
}

	Date& Gregorian::sub_month()
{

	int next_year = year();
	int next_month = month();
	if(month() == 1)
	{
		next_month = 12;
		next_year--;
	}else
	{
		next_month--;
	}

	if(days_in_month(next_year, next_month) >= day())
	{
		julian_day_number = gregorian_date_to_JDN(next_year, next_month, day());
	}else
	{
		julian_day_number -= 30;
	}
	return (*this);
}

	Date& Gregorian::add_month(int n)
{
	if(n > 0)
	{
		for(int i = 0; n > i; i++)
			add_month();
	}else
	{
		for(int i = 0; std::abs(n) > i; i++)
			sub_month();
	}
	return (*this);
}

	Date& Gregorian::add_month()
{
	int next_year = year();
	int next_month = month();
	if(month() == 12)
	{
		next_month = 1;
		next_year++;
	}else
	{
		next_month++;
	}

	if(days_in_month(next_year, next_month) >= day())
	{
		julian_day_number = gregorian_date_to_JDN(next_year, next_month, day());
	}else
	{
		julian_day_number += 30;
	}
	return (*this);
}

	bool Gregorian::is_leap_year(int year) const
{
	if(year % 4 == 0)
		if(year % 100 == 0)
			if(year % 400 == 0)
				return true;
			else
				return false;
		else
			return true;
	else
		return false;
}

void Gregorian::is_valid(int d, int m, int y) const
{
	if(m < 1 || m > 12 || d < 1 || d > days_in_month(y,m)){
		throw std::out_of_range("illegal date");
	}
}
}

<file_sep>/old/gregorian.cpp
#include "gregorian.h"

namespace lab2{

	//spot 0 empty to avoid having to do index arithmetic later
	const std::string Gregorian::dayNames[8] = 	
		{"INVALID_DAY", 
		"monday", 
		"tuesday",
		"wednesday",
		"thursday",
		"friday",
		"saturday",
		"sunday"};

	const std::string Gregorian::monthNames[13] =
		{"INVALID_MONTH",
		"january",
		"february",
		"march",
		"april",
		"may",
		"june",
		"july",
		"august",
		"september",
		"october",
		"november",
		"december"};

	const int Gregorian::daysInMonth[13] =
	{0,31,28,31,30,31,30,31,31,30,31,30,31};


Gregorian::Gregorian(){
	
	// För att få nuvarande tid
    time_t mytime = time(NULL);
	//set_k_time(mytime);
    k_time(&mytime);

    // För att få ut datum lokalt 
    struct tm *t = gmtime(&mytime);
    currentYear  = t->tm_year + 1900;
    currentMonth = t->tm_mon + 1;      // månaderna och dagarna
    currentDay   = t->tm_mday;         // indexerade från ETT

	julianDayNumber = gregorianDateToJDN(currentYear, currentMonth, currentDay);

}

Gregorian::Gregorian(const Date& d) {
	if(d != *this) {
		julianDayNumber = d.julianDayNumber;
		jdnToGregorian(julianDayNumber);
	}
}

Gregorian::Gregorian(int jdn){

	julianDayNumber = jdn;
	jdnToGregorian(jdn);
}

Gregorian::Gregorian(int year, int month, int day)
{
	checkValid(year, month, day);
	currentYear  = year;
    currentMonth = month;      // månaderna och dagarna
    currentDay   = day;         // indexerade från ETT

	julianDayNumber = gregorianDateToJDN(year, month, day);
}

Gregorian::~Gregorian(void)
{
}

void Gregorian::checkValid(int year, int month, int day) {
	if(month < 1 || month > 12 || day < 1 || day > days_this_month(year,month)){
		throw std::out_of_range("illegal date given!");
	}
}


/**
 * Converts a conventional western Gregorian Date to a julian day number
 * Algorithm source: http://www.astro.uu.nl/~strous/AA/en/reken/juliaansedag.html
 **/
int Gregorian::gregorianDateToJDN(int y, int m, int d){
	return (1721425.5 - 1) + (365 * (y - 1)) +
	(int)((y - 1) / 4) + (-(int)((y - 1) / 100)) +
	(int)((y - 1) / 400) + (int)((((367 * m) - 362) / 12) +
	((m <= 2) ? 0 :	(isLeapYear(y) ? -1 : -2)) + d);
}

/**
 * Converts a Julian Day Number to a Gregorian date.
 **/
void Gregorian::jdnToGregorian(int jd){

	int dqc, dcent, dquad, leapadj;
	double wjd,depoch, quadricent, cent, quad,yindex, yearday;

	wjd = (int)(mod_julian_day() +2400000) + 0.5;
	depoch = wjd - 1721425.5;
	quadricent = floor(depoch / 146097);
	dqc = (((int)depoch) % 146097);
	cent = (int)(dqc / 36524);
	dcent = (dqc %36524);
	quad = (int)(dcent / 1461);
	dquad = (dcent % 1461);
	yindex = (int)(dquad / 365);
	currentYear = int((quadricent * 400) + (cent * 100) + (quad * 4) + yindex);
	if (!((cent == 4) || (yindex == 4))) {
		(currentYear)++;
	}
	yearday = wjd - gregorianDateToJDN(currentYear, 1, 1);
	leapadj = ((wjd < gregorianDateToJDN(currentYear, 3, 1)) ? 0
			:
	(isLeapYear(currentYear) ? 1 : 2));
	currentMonth = int(floor((((yearday + leapadj) * 12) + 373) / 367));
	currentDay = int((wjd - gregorianDateToJDN(currentYear, currentMonth, 1)) + 1);
}

const int Gregorian::week_day() const{ 
	int m = month();
	int y = year();
	if (m < 3){
		m += 12;
		y -=1;
	}
	int k = y % 100;
	int j = y /100;
	int h = ((day() + (int)(((m+1)*26)/10) + k + (int)(k/4) + (int)(j/4) + (5*j))) % 7;
	h -= 1;
	if(h == 0){
		h = 7;
	}
	if(h == -1){
		h = 6;
	}
	return h;
}

const int Gregorian::year() const{
	return currentYear;
}

const int Gregorian::month() const{
	return currentMonth;
}

const int Gregorian::day() const{
	return currentDay;
}

const int Gregorian::days_per_week() const{
	return daysInWeek;
}

const int Gregorian::days_this_month() const {
	return days_this_month(currentYear, currentMonth);
}	

int Gregorian::days_this_month(int year, int month) const {
	if(month == 0) month = 12;
	int result = 0;
		if(month == 2 && isLeapYear(year)){
			result = 29;
		}else{
			result = daysInMonth[month];
		}
	return result;
}

const int Gregorian::months_per_year() const{
	return monthsInYear;
}


/**
 * Method for determining whether or not the given year was a leap year.
 * Algorithm source: http://en.wikipedia.org/wiki/Leap_year
 **/
bool Gregorian::isLeapYear(int year) const {
	if(year % 400 == 0){
		return true;
	}else if(year % 100 == 0){
		return false;
	}else if(year % 4 == 0){
		return true;
	}else{
		return false;
	}
}

const std::string Gregorian::week_day_name() const{
	return dayNames[week_day()];
}

const std::string Gregorian::month_name() const{
	printf("\n$$$ month: %d $$$$\n", currentMonth);
	fflush(stdout);
	if(currentMonth > 12 || currentMonth < 1)
		throw std::out_of_range("illegal date given!");
	return monthNames[currentMonth];
}

//prefix
Date& Gregorian::operator++(){
	julianDayNumber++;
	jdnToGregorian(julianDayNumber);
	return *this;
}

Date& Gregorian::operator--(){
	julianDayNumber--;
	jdnToGregorian(julianDayNumber);
	return *this;
}

//postfix
Gregorian Gregorian::operator++(int n)
{
	Gregorian old(year(), month(), day());
	++(*this);

	return old;
}

Gregorian Gregorian::operator--(int n)
{
	Gregorian old(year(), month(), day());
	--(*this);

	return old;
}

int Gregorian::mod_julian_day() const{
	return int(julianDayNumber - 2400000);
}

void Gregorian::operator+=(int n){
	julianDayNumber+= n;
	jdnToGregorian(julianDayNumber);
}

void Gregorian::operator-=(int n){
	julianDayNumber-= n;
	jdnToGregorian(julianDayNumber);
}

Date& Gregorian::add_year(int n){
	if(currentDay > days_this_month(currentYear+n, currentMonth))
	{
		julianDayNumber = gregorianDateToJDN(currentYear + n, currentMonth, days_this_month(currentYear + n,currentMonth));
	}else
	{
		julianDayNumber = gregorianDateToJDN(currentYear + n, currentMonth, currentDay);
	}
	jdnToGregorian(julianDayNumber);
	return *this;
}

Date& Gregorian::add_month(int n) {
	int tmpYear = currentYear;
	int tmpMonth = currentMonth + n;
	tmpYear += tmpMonth/12;
	tmpMonth = tmpMonth % 12;
	if(tmpMonth <= 0)
	{
		tmpMonth = 12 + tmpMonth;
		--tmpYear;
	}
	if(currentDay > days_this_month(tmpYear,tmpMonth))
	{
		julianDayNumber = gregorianDateToJDN(tmpYear, tmpMonth, days_this_month(tmpYear,tmpMonth));
	}else
	{
		julianDayNumber = gregorianDateToJDN(tmpYear, tmpMonth, currentDay);
	}
	jdnToGregorian(julianDayNumber);
	return *this;
}

Gregorian& Gregorian::operator=(const Date& d) {
        julianDayNumber = d.julianDayNumber;
        updateDateWithJDN(julianDayNumber);
		return *this;
}

void Gregorian::updateDateWithJDN(int jdn) {
	jdnToGregorian(jdn);
	return;
}

int Gregorian::calculateDaysNextMonth() {
	
		int nextMonth = currentMonth+1;
		int nextYear = currentYear;

		if(nextMonth > 12){ //Rollover
			nextYear++;
			nextMonth = 1;
		}

		Gregorian nextDate = Gregorian(nextYear, nextMonth, 1);
		int daysNextMonth = nextDate.days_this_month();
		return daysNextMonth;
}
}
<file_sep>/date/makefile
ALL:
	#g++ -g -O2 -static -std=gnu++0x date.cpp gregorian.cpp kattistime.cpp cprog09lab22b.cpp
	g++ -g -Wall date.cpp julian.cpp gregorian.cpp kattistime.cpp test_codea.cpp

<file_sep>/cal/gregorian.h
#pragma once
#include "date.h"
#include "kattistime.h"
#include <time.h>
#include <stdlib.h>
#include <stdio.h>
#include <cstdlib>
#include <math.h>
#include <iterator>
#include <stdexcept>
#include <iostream>
namespace lab2
{

    struct day_month_year
    {
        int day;
        int month;
        int year;
    };
class Gregorian :
	public Date
{

public:
	Gregorian();
	Gregorian(const Date&);
	Gregorian(int jdn);
	Gregorian(int year, int month, int day);
	~Gregorian();

	virtual int mod_julian_day() const;
	virtual double julian_day() const;

	const virtual int year() const;
	const virtual int month() const;
	const virtual int day() const;
	const virtual int week_day() const;

	const virtual int days_per_week() const;
	const virtual int days_this_month() const;
	const virtual int months_per_year() const;

	const virtual std::string week_day_name() const;
	const virtual std::string month_name() const;

	//prefix
	virtual Date& operator++();
	virtual Date& operator--();

	//postfix
	virtual Gregorian operator++(int n);
	virtual Gregorian operator--(int n);

	virtual void operator+=(int n);
	virtual void operator-=(int n);
	virtual Gregorian& operator=(const Date& d);

	virtual Date& add_year(int n);
	Date& add_year();
	Date& add_month(int n);
	virtual Date& add_month();
	virtual Date& sub_month();
protected:

	virtual bool is_leap_year(int year) const;
	bool is_leap_day() const;

	virtual int days_in_month(int year, int month) const;
	//int calculateDaysNextMonth();

	//void jdnToG_Regorian(int jdn);
	double gregorian_date_to_JDN(int year, int month, int day) const;
	double JDN_to_mod_julian_day(double jdn) const;

	static const std::string day_names[8];
	static const std::string month_names[13];
	static const int days_in_month_array[13];

	static const int days_in_week = 7;
	static const int months_in_year = 12;

	void is_valid(int d, int m, int y) const;
	day_month_year JDN_to_gregorian(double jd) const;
};
}
<file_sep>/old/calendar.h
#pragma once
#include <string>
#include <vector>
#include <algorithm>
#include "date.h"
#include "gregorian.h"
#include "Event.h"

namespace lab2 {
	using namespace std;

template <class T> class Calendar
{

protected:

	template<class U> friend std::ostream& operator<<(std::ostream&,const Calendar<U>&);
	

public:

	T* currentDate;
	vector<Event*>* events;

Calendar(void) {
	currentDate = new T();
	events = new vector<Event*>();
}

template <class S>
Calendar(const Calendar<S> & other) {

	if(static_cast<void*>(this) == &other) {
		return;
	}

	currentDate = new T(); 
	*currentDate -= currentDate->mod_julian_day();
	*currentDate += other.currentDate->mod_julian_day();
	
	typename vector<Event* >::iterator it;
	it = other.events->begin();
	events->clear();
	for(;it!=other.events->end();it++) {
		T* tmpDate = new T((*it)->getDate());
		
		Event eventCopy((*it)->getEventName(), tmpDate);
		events->push_back(&eventCopy);
	}
}

~Calendar(void) {
}
bool set_date(int year, int month, int day) {
	Date* current = currentDate;

	try {
	currentDate = new T(year, month, day);
	delete(current);
		}catch (...) {
	return false;
	}
	return true;
}


bool add_event(string eventName) {
	return add_event(eventName, new T());
}
bool add_event(string eventName, int day) {
	return add_event(eventName, T().month(), day);
}
bool add_event(string eventName, int month, int day) {
	return add_event(eventName, T().year(), month, day);
}
bool add_event(string eventName, int year, int month, int day) {
		T* d;
try {
		d = new T(year, month, day);
	}catch(...) {
		return false;
	}
	return add_event(eventName, d);
}


bool remove_event(string name) {
	T* d = new T();
	return remove_event(name, d);
}
bool remove_event(string name, int day) {
	return remove_event(name, T().month(), day);
}
bool remove_event(string name, int month, int day) {
	return remove_event(name, T().year(), month, day);
}
bool remove_event(string name, int year, int month, int day) {
	T* d;
	try{
	d = new T(year, month, day);
	}catch (...) {
		return false;
	}
	return true;
}


//Assignment operator.
Calendar<T>& operator=(const Calendar& other) {

	delete(currentDate); //Clean
	this->currentDate = other.currentDate; //Assign

	delete[] events; //Clean
	this->events = other.events; //Assign

	//TODO: copy more values
	return *this;
}
	
//Private, does the heavy lifting once the public ones have checked for valid input and standardized
//their parameters (made a date).
bool add_event(string eventName, Date* d) {
	if(indexOf(eventName, *d) > 0) //Exists.
		return false;
	events->push_back(new Event(eventName, d));
	return true;
}

//Private, actually does the removing after doing an exists-check.
bool remove_event(string eventName, Date* d) {
	int i = indexOf(eventName, *d);
	if(i < 0) //Doesn't exist
		return false;
	events->erase(events->begin() + i);
	return true;
}


//Returns the index of the given event name+date combo, or negative number if not found.
int indexOf(string name, Date& d) {
	for(int i = 0; i < events->size(); ++i) {
		Event* e = (*events)[i];

		if(e->getEventName() == name && e->getDate() == d)
			return i;
	}
	return -1;
}

};


template <class U>
ostream& operator<<(ostream& o, const Calendar<U>& cal){

	sort(cal.events->begin(), cal.events->end());
	U* start = new U();

	vector<Event*>::iterator it;
	//First, skip ahead to today
	for(it = cal.events->begin(); it != cal.events->end(); ++it){
		Date* current = &(*it)->getDate();
		if(current->julianDayNumber == start->julianDayNumber) //Todays date, this is where we start.
			break; //++it will take care of getting us to start+1, so we're done here
	}
		
	for(; it != cal.events->end(); ++it) {
		o << *it;
	}
	delete(start);
	return o;
}

}<file_sep>/old/test_code.h
#pragma once

namespace lab2{

class test_code
{
public:
	test_code(void);
	~test_code(void);

	
};
}
/*
int main();
}
*/<file_sep>/cal/julian.h
#pragma once
#include "gregorian.h"
#include "kattistime.h"
#include <time.h>
#include <stdlib.h>
#include <stdio.h>
#include <cstdlib>
#include <math.h>
#include <iterator>
#include <stdexcept>
#include <iostream>
namespace lab2
{

class Julian :
	public lab2::Gregorian
{

public:
	Julian();
	Julian(const Date&);
	Julian(int jdn);
	Julian(int year, int month, int day);
	~Julian();

	const int day() const;
	const int month() const;
	const int year() const;

	virtual Date& add_year(int n);
	//virtual Date& add_month(int n);
	virtual Date& add_month();
	virtual Date& sub_month();
protected:

	virtual bool is_leap_year(int year) const;

	//int calculateDaysNextMonth();

	double julian_date_to_JDN(int year, int month, int day) const;
	day_month_year JDN_to_julian(double jd) const;
	const virtual int week_day() const;
};
}
<file_sep>/old/Event.cpp
#include "Event.h"
#include "date.h"


namespace lab2 {
Event::Event(string name, Date* date)
{
	this->name = name;
	this->date = date;
}


string Event::getEventName() {
	return name;
}

Date& Event::getDate() {
	return *date;
}

ostream& Event::operator<<(ostream& o) {
	o << date << " : " << name << std::endl;
	return o;
}

Event::~Event(void)
{
}

}
<file_sep>/old/gregorian.h
#pragma once
#include "date.h"
#include "kattistime.h"
#include <time.h>
#include <stdlib.h>
#include <stdio.h>
#include <cstdlib>
#include <math.h>
#include <iterator>
#include <stdexcept>
namespace lab2{

class Gregorian :
	public Date
{
public:

	int currentMonth;
	int currentYear;
	int currentDay;

	Gregorian();
	Gregorian(const Date&);
	Gregorian(int jdn);
	Gregorian(int year, int month, int day);

	~Gregorian();

	
	const virtual int year() const;
	const virtual int month() const;
	const virtual int day() const;
	
	const virtual int week_day() const;

	const virtual int days_per_week() const;
	const virtual int days_this_month() const;

	const virtual int months_per_year() const;
	const virtual std::string week_day_name() const;
	const virtual std::string month_name() const;

	//prefix
	virtual Date& operator++();
	virtual Date& operator--();

	//postfix
	virtual Gregorian operator++(int n);
	virtual Gregorian operator--(int n);

	virtual void operator+=(int n);
	virtual void operator-=(int n);
	virtual Gregorian& operator=(const Date& d);
	void updateDateWithJDN(int jdn);

	virtual Date& add_year(int n = 1);
	virtual Date& add_month(int n = 1);

	virtual int mod_julian_day() const;

protected:

	virtual bool isLeapYear(int year) const;

	int days_this_month(int year, int month) const;
	int calculateDaysNextMonth();

	void jdnToGregorian(int jdn);
	int gregorianDateToJDN(int year, int month, int day);

	static const int daysInWeek = 7;
	static const int monthsInYear = 12;

	
	static const std::string dayNames[8];
	static const std::string monthNames[13];
	static const int daysInMonth[13];

	void checkValid(int, int, int);
};
}
<file_sep>/old/Rebecca.cpp
#include "Rebecca.h"

namespace lab2{
Rebecca::Rebecca(void)
{
}

const int Rebecca::day() const{
	return 5;
}

Rebecca::~Rebecca(void)
{
}
}<file_sep>/old/test_code.cpp
#include "test_code.h"
#include "julian.h"

using namespace lab2;

test_code::test_code(void)
{
}


test_code::~test_code(void)
{
}

/*
int main(){

	Gregorian a = Gregorian(2009, 2, 24);
	std::cout << "Created Gregorian date 2009-02-24 (Tuesday). Our implementation reports \n";
	std::cout << "Greg: " << a.year() << "-" << a.month() << "-" << a.currentDay  << ": " << a.week_day_name() << "(" << a.julianDayNumber << ")" << std::endl;
	std::cout << "Mod_Julian: " << a.mod_julian_day() << std::endl;
	a.add_month(15);
	std::cout << "Adding 15 months gives us the date 2010-05-24 (Monday)\n";
	std::cout << "Greg: " << a.year() << "-" << a.month() << "-" << a.currentDay  << ": " << a.week_day_name() << "(" << a.julianDayNumber << ")" << std::endl;
	std::cout << "\n";

	std::cout << "Created Gregorian date 2037-07-12 (Sunday). Our implementation reports \n";
	Gregorian c = Gregorian(2037, 7, 12);
	std::cout << "Greg: " << c.year() << "-" << c.month() << "-" << c.currentDay  << ": " << c.week_day_name() << "(" << c.julianDayNumber << ")" << std::endl;
	std::cout << "Mod_Julian: " << c.mod_julian_day() << std::endl;
	c.add_month(15);
	std::cout << "Adding 15 months gives us the date 2038-10-12 (Tuesday)\n";
	std::cout << "Greg: " << c.year() << "-" << c.month() << "-" << c.currentDay  << ": " << c.week_day_name() << "(" << c.julianDayNumber << ")" << std::endl;
	std::cout << "\n";

	std::cout << "Created Julian date from Greg 1970-01-15 (Thursday). \n" <<
		"This should yield Julian 1970-01-02. Our implementation reports \n";
	Julian b = Julian(1970, 1, 15);
	std::cout << "Julian: " << b.year() << "-" << b.month() << "-" << b.day() << ": " << b.week_day_name() << "(" << b.julianDayNumber << ")" << std::endl;
	std::cout << "Mod_Julian: " << b.mod_julian_day() << std::endl;
	b.add_month(15);
	std::cout << "Adding 15 months should yield Julian 1971-04-02 (Thursday)\n";
	std::cout << "Julian: " << b.year() << "-" << b.month() << "-" << b.currentDay  << ": " << b.week_day_name() << "(" << b.julianDayNumber << ")" << std::endl;
	std::cout << "\n";

	std::cout << "Created Julian date from Greg 1997-04-22 (Tuesday). \n" <<
		"This should yield Julian 1997-04-09\n";
	Julian d = Julian(1997, 4, 22);
	std::cout << "Julian: " << d.year() << "-" << d.month() << "-" << d.day() << ": " << d.week_day_name() << "(" << d.julianDayNumber << ")" << std::endl;
	std::cout << "Mod_Julian: " << d.mod_julian_day() << std::endl;
	d.add_month(15);
	std::cout << "Adding 15 months should yield Julian 1998-07-09 (Wednesday)\n";
	std::cout << "Julian: " << d.year() << "-" << d.month() << "-" << d.currentDay  << ": " << d.week_day_name() << "(" << d.julianDayNumber << ")" << std::endl;
	std::cout << "\n";


	//Gregorian c = Gregorian(2010, 10, 1);
	//Gregorian d = Gregorian(2010, 9, 31);

	//std::cout << "Greg: " << c.year() << "-" << c.month() << "-" << c.currentDay  << ": " << c.week_day_name() << "(" << c.julianDayNumber << ")" << std::endl;
	//std::cout << "Greg: " << d.year() << "-" << d.month() << "-" << d.currentDay  << ": " << d.week_day_name() << "(" << d.julianDayNumber << ")" << std::endl;
	std::string asdf;
	std::cin >> asdf;

	return 0;
}
*/<file_sep>/old/makefile
cal.exe:
	g++ -Wall -g -o cal.exe date.cpp gregorian.cpp julian.cpp datetest.cpp kattistime.cpp
<file_sep>/old/Event.h
#pragma once

#include <string>
#include "date.h"

namespace lab2 {
	using namespace std;

class Event
{

public:
	Event(string, Date* date);

	~Event(void);

	ostream& operator<<(ostream&);

	string getEventName();
	Date& getDate();
private:
	string name;
	Date* date;
};

}
<file_sep>/date/test_codea.cpp
#include "test_code.h"
#include "julian.h"
//#include "Julian.h"

using namespace lab2;

test_code::test_code(void)
{
}


test_code::~test_code(void)
{
}

int main(){

	time_t time = 0;
	set_k_time(time);
	Julian j = Julian(1923, 1, 1);
	std::cout << "--------------------------------------------------------------------------------\n";
	std::cout << "Test 1 - Date: 1923-01-01: \n";
	std::cout << "\n";

	std::cout << "Gregor - Date: " << j.year() << "-" << j.month() << "-" << j.day()  << ": " << j.week_day_name() << std::endl;
	std::cout << "Actual    JDN: " << j.mod_julian_day() << std::endl;
	std::cout << "Expected  JDN: " << "23433" << std::endl;
	std::cout << "\n";

	j = Julian(2014, 5, 22);
	std::cout << "--------------------------------------------------------------------------------\n";
	std::cout << "Test 1 - Date: 2014-05-22: \n";
	std::cout << "\n";

	std::cout << "Gregor - Date: " << j.year() << "-" << j.month() << "-" << j.day()  << ": " << j.week_day_name() << std::endl;
	std::cout << "Actual    JDN: " << (int)j.julian_day() << std::endl;
	std::cout << "Expected  JDN: " << "56812" << std::endl;
	std::cout << "\n";
/*
	std::cout << "Julian - Date: " << j.year() << "-" << j.month() << "-" << j.day()  << ": " << j.week_day_name() << std::endl;
	std::cout << "Actual    JDN: " << j.mod_julian_day() << std::endl;
	std::cout << "Expected  JDN: " << "54899" << std::endl;
	std::cout << "\n\n";
	g = Julian(1970, 1, 17);
//	j = Julian(1970, 1, 17);
	std::cout << "--------------------------------------------------------------------------------\n";
	std::cout << "Test 2 - Date: 1970-1-17: Saturday\n";
	std::cout << "\n";

	std::cout << "Gregor - Date: " << g.year() << "-" << g.month() << "-" << g.day()  << ": " << g.week_day_name() << std::endl;
	std::cout << "Actual    JDN: " << g.mod_julian_day() << std::endl;
	std::cout << "Expected  JDN: " << "40603" << std::endl;
	std::cout << "\n";
	//std::cout << "Julian - Date: " << j.year() << "-" << j.month() << "-" << j.day()  << ": " << j.week_day_name() << std::endl;
	std::cout << "Actual    JDN: " << j.mod_julian_day() << std::endl;
	std::cout << "Expected  JDN: " << "40616" << std::endl;
	std::cout << "\n\n";
	g = Julian();
//	j = Julian();
	std::cout << "--------------------------------------------------------------------------------\n";
	std::cout << "Test 3 - Date: Today! all dates should be the same!\n";
	std::cout << "\n";

	std::cout << "Gregor - Date: " << g.year() << "-" << g.month() << "-" << g.day()  << ": " << g.week_day_name() << std::endl;
	std::cout << "          JDN: " << g.mod_julian_day() << std::endl;
	std::cout << "\n";
	std::cout << "Julian - Date: " << j.year() << "-" << j.month() << "-" << j.day()  << ": " << j.week_day_name() << std::endl;
	std::cout << "          JDN: " << j.mod_julian_day() << std::endl;
	std::cout << "\n\n";

	std::cout << "--------------------------------------------------------------------------------\n";
	std::cout << "--------------------------------------------------------------------------------\n";
	std::cout << "--------------------------------------------------------------------------------\n";
	std::cout << "--------------------------------------------------------------------------------\n";
	g = Julian(1923, 3, 1);
	//g.add_year(111);
	//g.add_month(-120);
	//g.add_month(-119);
	g.add_year(-10);
//	j = Julian(1900, , 29);
	std::cout << "--------------------------------------------------------------------------------\n";
	std::cout << "Test 4 - Date: 1923-3-1: Thursday\n";
	std::cout << "\n";

	std::cout << "Gregor - Date: " << g << ": " << g.week_day_name() << std::endl;
	std::cout << "Actual    JDN: " << g.mod_julian_day() << std::endl;
	std::cout << "Expected  JDN: " << "23479" << std::endl;
	std::cout << "\n";

	g = Julian(1858, 1, 1);
//	j = Julian(1900, 2, 29);
	std::cout << "--------------------------------------------------------------------------------\n";
	std::cout << "Test 5 - Date: 1858-01-01\n";
	std::cout << "\n";

	std::cout << "Gregor - Date: " << g << ": " << g.week_day_name() << std::endl;
	std::cout << "Actual    JDN: " << g.mod_julian_day() << std::endl;
	std::cout << "Expected  JDN: " << "-1" << std::endl;
	std::cout << "\n";

	g = Julian(2033, 8, 20);
//	j = Julian(1900, 2, 29);
	std::cout << "--------------------------------------------------------------------------------\n";
	std::cout << "Test 6 - Date: 2033-08-20\n";
	std::cout << "\n";

	std::cout << "Gregor - Date: " << g << ": " << g.week_day_name() << std::endl;
	std::cout << "Actual    JDN: " << g.mod_julian_day() << std::endl;
	std::cout << "Expected  JDN: " << "-1" << std::endl;
	std::cout << "\n";

	set_k_time(717119999);
	g = Julian();
//	j = Julian(1900, 2, 29);
	std::cout << "--------------------------------------------------------------------------------\n";
	std::cout << "Test 7 - Date: 1992-09-21\n";
	std::cout << "\n";

	std::cout << "Gregor - Date: " << g << ": " << g.week_day_name() << std::endl;
	std::cout << "Actual    JDN: " << g.mod_julian_day() << std::endl;
	std::cout << "Expected  JDN: " << "-1" << std::endl;
	std::cout << "\n";

	set_k_time(717120000);// + 86400/4);
	g = Julian();
//	j = Julian(1900, 2, 29);
	std::cout << "--------------------------------------------------------------------------------\n";
	std::cout << "Test 8 - Date: 1992-09-22\n";
	std::cout << "\n";

	std::cout << "Gregor - Date: " << g << ": " << g.week_day_name() << std::endl;
	std::cout << "Actual    JDN: " << g.mod_julian_day() << std::endl;
	std::cout << "\n";


	g = Julian(1992,9,22);
//	j = Julian(1900, 2, 29);
	std::cout << "--------------------------------------------------------------------------------\n";
	std::cout << "Test 9 - Date: 1992-09-22\n";
	std::cout << "\n";

	std::cout << "Gregor - Date: " << g << ": " << g.week_day_name() << std::endl;
	std::cout << "Actual    JDN: " << g.mod_julian_day() << std::endl;
	std::cout << "\n";

	set_k_time(212158799);// + 86400/4);
	g = Julian();
//	j = Julian(1900, 2, 29);
	std::cout << "--------------------------------------------------------------------------------\n";
	std::cout << "Test 10 - Date: 1976-09-21\n";
	std::cout << "\n";

	std::cout << "Gregor - Date: " << g << ": " << g.week_day_name() << std::endl;
	std::cout << "Actual    JDN: " << g.mod_julian_day() << std::endl;
	std::cout << "\n";

	set_k_time(0);// + 86400/4);
	g = Julian();
//	j = Julian(1900, 2, 29);
	std::cout << "--------------------------------------------------------------------------------\n";
	std::cout << "Test 11 - Date: 1970-01-01\n";
	std::cout << "\n";

	std::cout << "Gregor - Date: " << g << ": " << g.week_day_name() << std::endl;
	std::cout << "Actual    JDN: " << g.mod_julian_day() << std::endl;
	std::cout << "\n";

	set_k_time(2008152549);// + 86400/4);
	g = Julian();
	std::cout << "--------------------------------------------------------------------------------\n";
	std::cout << "Test 12 - Date: 2033-08-20\n";
	std::cout << "\n";

	std::cout << "Gregor - Date: " << g << ": " << g.week_day_name() << std::endl;
	std::cout << "Actual    JDN: " << g.mod_julian_day() << std::endl;
	std::cout << "\n";

	g = Julian(2093,1,1);
	std::cout << "--------------------------------------------------------------------------------\n";
	std::cout << "Test 13 - Date: 2093-01-01\n";
	std::cout << "\n";

	std::cout << "Gregor - Date: " << g << ": " << g.week_day_name() << std::endl;
	std::cout << "Actual    JDN: " << g.mod_julian_day() << std::endl;
	std::cout << "\n";
	*/
	return 0;
}
<file_sep>/cal/makefile
ALL:
	g++ -g -Wall calendar.cpp date.cpp event.cpp gregorian.cpp julian.cpp cprog09lab23.cpp 
<file_sep>/old/test_code_new.cpp
#include "test_code_new.h"
#include "julian.h"

using namespace lab2;

test_code::test_code(void)
{
}


test_code::~test_code(void)
{
}

int main(){

	Gregorian g = Gregorian(2009, 2, 24);
	Julian j = Julian(2009, 2, 24);
	std::cout << "--------------------------------------------------------------------------------\n";
	std::cout << "Test 1 - Date: 2009-2-24: Tuesday\n";
	std::cout << "\n";

	std::cout << "Gregor - Date: " << g.year() << "-" << g.month() << "-" << g.currentDay  << ": " << g.week_day_name() << std::endl;
	std::cout << "Actual    JDN: " << g.mod_julian_day() << std::endl;
	std::cout << "Expected  JDN: " << "54886" << std::endl;
	std::cout << "\n";

	std::cout << "Julian - Date: " << j.year() << "-" << j.month() << "-" << j.currentDay  << ": " << j.week_day_name() << std::endl;
	std::cout << "Actual    JDN: " << j.mod_julian_day() << std::endl;
	std::cout << "Expected  JDN: " << "54899" << std::endl;
	std::cout << "\n\n";

	g = Gregorian(1970, 1, 17);
	j = Julian(1970, 1, 17);
	std::cout << "--------------------------------------------------------------------------------\n";
	std::cout << "Test 2 - Date: 1970-1-17: Saturday\n";
	std::cout << "\n";

	std::cout << "Gregor - Date: " << g.year() << "-" << g.month() << "-" << g.currentDay  << ": " << g.week_day_name() << std::endl;
	std::cout << "Actual    JDN: " << g.mod_julian_day() << std::endl;
	std::cout << "Expected  JDN: " << "40603" << std::endl;
	std::cout << "\n";

	std::cout << "Julian - Date: " << j.year() << "-" << j.month() << "-" << j.currentDay  << ": " << j.week_day_name() << std::endl;
	std::cout << "Actual    JDN: " << j.mod_julian_day() << std::endl;
	std::cout << "Expected  JDN: " << "40616" << std::endl;
	std::cout << "\n\n";

	g = Gregorian();
	j = Julian();
	std::cout << "--------------------------------------------------------------------------------\n";
	std::cout << "Test 3 - Date: Today! all dates should be the same!\n";
	std::cout << "\n";

	std::cout << "Gregor - Date: " << g.year() << "-" << g.month() << "-" << g.currentDay  << ": " << g.week_day_name() << std::endl;
	std::cout << "          JDN: " << g.mod_julian_day() << std::endl;
	std::cout << "\n";

	std::cout << "Julian - Date: " << j.year() << "-" << j.month() << "-" << j.currentDay  << ": " << j.week_day_name() << std::endl;
	std::cout << "          JDN: " << j.mod_julian_day() << std::endl;
	std::cout << "\n\n";
	
	g = Gregorian(1900, 2, 29);
	j = Julian(1900, 2, 29);
	std::cout << "--------------------------------------------------------------------------------\n";
	std::cout << "Test 4 - Date: 1900-2-29: Thursday\n";
	std::cout << "\n";

	std::cout << "Gregor - Date: " << g.year() << "-" << g.month() << "-" << g.currentDay  << ": " << g.week_day_name() << std::endl;
	std::cout << "Actual    JDN: " << g.mod_julian_day() << std::endl;
	std::cout << "Expected  JDN: " << "15079" << std::endl;
	std::cout << "\n";


	std::string asdf;
	std::cin >> asdf;
	return 0;
}
<file_sep>/old/Rebecca.h
#pragma once
#include "gregorian.h"

namespace lab2 {

class Rebecca :
	public Gregorian
{
public:
	Rebecca(void);
	~Rebecca(void);

	const virtual int day() const;
};

}

