Add date arthmetic

This commit is contained in:
realaltffour 2020-04-16 16:06:52 +03:00
parent 11a1b58f6f
commit f91629f68b
No known key found for this signature in database
GPG Key ID: 7115CD2AC9A76A56
2 changed files with 33 additions and 6 deletions

View File

@ -125,10 +125,10 @@ void loadSkid(Skid& skid, int skidNum) {
Date get_today() {
Date res;
time_t t = time(0);
time_t t = time(0);
struct tm* currentTime = localtime(&t);
res.day = currentTime->tm_mday;
res.day = currentTime->tm_mday;
res.month = currentTime->tm_mon;
res.year = currentTime->tm_year + 1900;
@ -136,7 +136,31 @@ Date get_today() {
return res;
}
// Date addDate(Date initial, int number, int* slot) {}
int get_day_num(Date initial) {
auto m = (initial.month + 9) % 12;
auto y = initial.year - m / 10;
return 365 * y + y / 4 - y / 100 + y / 400 + (m * 306 + 5) / 10 + (d - 1);
}
Date get_day_date(int intial) {
auto y = (10000 * g + 14780) / 3652425;
auto ddd = g - (365 * y + y / 4 - y / 100 + y / 400);
if (ddd < 0)
y = y - 1;
ddd = g - (365 * y + y / 4 - y / 100 + y / 400);
auto mi = (100 * ddd + 52) / 3060;
auto mm = (mi + 2) % 12 + 1;
auto y = y + (mi + 2) / 12;
auto dd = ddd - (mi * 306 + 5) / 10 + 1;
Date res;
res.year = y;
res.month = mm;
res.day = dd;
return res;
}
Date addDays_date(Date initial, int number) {}
bool is_empty(std::ifstream& pFile) {
return pFile.peek() == std::ifstream::traits_type::eof();

View File

@ -19,7 +19,7 @@ using nlohmann::json;
////// DATA STRUCTURES
struct Date {
int day = 0;
int day = 0;
int month = 0; // 0-11
int year = 0; // + 1900 for currentyear
int hour = 0;
@ -48,7 +48,7 @@ struct Skid {
enum EntryType { Access = 0, Creation = 1, Modification = 2, None = -1 };
struct Entry {
EntryType type = EntryType::None;
EntryType type = EntryType::None;
std::string mesg = "";
float timerTime = 0.0f;
Date creationDate;
@ -79,7 +79,10 @@ void writeSkid(Skid skid, int skidNum);
void loadSkid(Skid& skid, int skidNum);
Date get_today();
// Date addDate(Date initial, int number, int* slot = nullptr);
int get_day_num(Date initial);
Date get_day_date(int num);
Date addDays_date(Date initial, int number);
Date subDays_date(Date initial, int number);
bool is_empty(std::ifstream& pFile);
bool is_path_exist(const std::string& s);