#include "Age.h"
// #include <stdio.h>
// #include <iostream>
// using namespace std;

/**
*constructs a new BodyAutoMeasurement
*/
Age::Age(int index, QWidget *parent): Measurable(index, parent)
 {
	this->bDate = StringDate(QDate::currentDate());
 }

/**
*Set the Birth date to date
*/
void Age::setBDate(StringDate date){
this->bDate = date;
}

/**
*Returns the BirthDate
*/
StringDate Age::getBDate(){
return this->bDate;
}

/**
*Returns the age of this person on 'date' with the Birthdate set by setBDate(StringDate)
*/
int Age::getValue(StringDate date){
int age = date.getQDate().year()-bDate.getQDate().year();
if(bDate.getQDate().month()-date.getQDate().month() == 0 ){
	///we are in the month of the birthday
	if(bDate.getQDate().day()-date.getQDate().day() > 0 ){
		age--;
		}
	}
if(bDate.getQDate().month()-date.getQDate().month() > 0 ){
	///we are before the month of the birthday
	age--;
	}
return age;
}

QString Age::getName(){
return tr("Age");
}

QString Age::getExplanation(){
return tr("Age");
}

/**
*toString
*/
QString Age::toString(){
QString ret = getBDate().getQString();
ret.append("!");
return ret;
}