Last active
January 31, 2020 23:41
-
-
Save Sarverott/f13c32757df55cdbc7f0b1f8393e7382 to your computer and use it in GitHub Desktop.
simple date class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef DATE_H | |
#define DATE_H | |
/* Sarverott 2020 */ | |
//#include <iostream> | |
//using namespace std; | |
class date{ | |
public: | |
int year=0; | |
int month=0; | |
int day=0; | |
date(){ | |
//cout<<"###DATE created!###\n"; | |
} | |
~date(){ | |
//cout<<"###DATE destroyed!###\n"; | |
} | |
//date(int y, int m, int d){ | |
// insertData(y, m, d); | |
//} | |
date(char* line){ | |
//cout<<"###DATE created!###\n"; | |
insertData(line); | |
} | |
void insertData(char* line){ | |
int i=0; | |
int multiplier=10; | |
this->year=0; | |
while(*line!='-'){ | |
this->year*=multiplier; | |
this->year+=*line-'0'; | |
line++; | |
} | |
this->month=0; | |
while(*line!='-'){ | |
this->month*=multiplier; | |
this->month+=*line-'0'; | |
line++; | |
} | |
this->day=0; | |
while(*line!='\0'){ | |
this->day*=multiplier; | |
this->day+=*line-'0'; | |
line++; | |
} | |
} | |
char* toString(){ | |
char* output=new char(); | |
char* flag=output; | |
*flag='0'+year/1000; | |
flag++; | |
*flag='0'+year/100%10; | |
flag++; | |
*flag='0'+year/10%10; | |
flag++; | |
*flag='0'+year%10; | |
flag++; | |
*flag='-'; | |
flag++; | |
*flag='0'+month/10; | |
flag++; | |
*flag='0'+month%10; | |
flag++; | |
*flag='-'; | |
flag++; | |
*flag='0'+day/10; | |
flag++; | |
*flag='0'+day%10; | |
flag++; | |
*flag='\0'; | |
return output; | |
} | |
int toInt(){ | |
return day+month*31+year*31*12;//nie wa¿na niezgodnoœæ z iloœci¹ dni, wa¿na hierarchia rok>miesi¹c>dzieñ | |
} | |
}; | |
#endif // DATE_H |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment