unittest start
This commit is contained in:
parent
bc87732585
commit
fa8bd24551
8 changed files with 105 additions and 99 deletions
|
|
@ -1,95 +1,19 @@
|
|||
//Tóth Dániel Mátyás | IFPQYY | V1
|
||||
#include <exception>
|
||||
#include <iostream>
|
||||
#include "cmydateexception.h"
|
||||
#include "cmydate.h"
|
||||
using namespace std;
|
||||
/*#define TIMESTAMP_YEAR 1970
|
||||
static bool IsLeapYear(int year) {
|
||||
if (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
static int GetMonthDayCount(int month, int year) {
|
||||
switch (month)
|
||||
{
|
||||
case 1:
|
||||
case 3:
|
||||
case 5:
|
||||
case 7:
|
||||
case 8:
|
||||
case 10:
|
||||
case 12:
|
||||
return 31;
|
||||
break;
|
||||
case 4:
|
||||
case 6:
|
||||
case 9:
|
||||
case 11:
|
||||
return 30;
|
||||
break;
|
||||
case 2:
|
||||
if (IsLeapYear(year))
|
||||
{
|
||||
return 29;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 28;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw new CMyDateException(CMyDateException::ErrUnexpected);
|
||||
break;
|
||||
}
|
||||
}
|
||||
static int DayOfTheYearArgs(int year, int month, int day) {
|
||||
for (int i = 1; i < month; i++)
|
||||
{
|
||||
day += GetMonthDayCount(i, year);
|
||||
}
|
||||
return day;
|
||||
}
|
||||
static int DateToTimeStamp(int year, int month, int day) { //counting from 1970-01-01
|
||||
int y = year - 1;
|
||||
int e = TIMESTAMP_YEAR - 1;
|
||||
|
||||
int days = 365 * (year - TIMESTAMP_YEAR)
|
||||
+ (y / 4 - e / 4)
|
||||
- (y / 100 - e / 100)
|
||||
+ (y / 400 - e / 400);
|
||||
|
||||
return days + DayOfTheYearArgs(year, month, day - 1);
|
||||
}
|
||||
static void TimeStampToDate(int timestamp, int* year, int* month, int* day) {
|
||||
*year = TIMESTAMP_YEAR;
|
||||
while (timestamp < 0)
|
||||
{
|
||||
(*year)--;
|
||||
timestamp += IsLeapYear(*year) ? 366 : 365;
|
||||
}
|
||||
while (timestamp >= (IsLeapYear(*year) ? 366 : 365))
|
||||
{
|
||||
timestamp -= IsLeapYear(*year) ? 366 : 365;
|
||||
(*year)++;
|
||||
}
|
||||
|
||||
*month = 1;
|
||||
int monthDay = GetMonthDayCount(*month, *year);
|
||||
while (timestamp >= monthDay)
|
||||
{
|
||||
timestamp -= monthDay;
|
||||
(*month)++;
|
||||
monthDay = GetMonthDayCount(*month, *year);
|
||||
}
|
||||
|
||||
*day = timestamp + 1;
|
||||
}*/
|
||||
|
||||
int main() {
|
||||
/*int t = DateToTimeStamp(1976, 10, 23);
|
||||
cout << t << "\n";
|
||||
int y = 0, m = 0, d = 0;
|
||||
TimeStampToDate(t, &y, &m, &d);
|
||||
cout << y << ". " << m << ". " << d << ".";*/
|
||||
CMyDate date;
|
||||
try
|
||||
{
|
||||
date.IsValid(1969, 0, 0);
|
||||
}
|
||||
catch (const CMyDateException& e)
|
||||
{
|
||||
cout << e.what();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue