Elf_calendar::tm Elf_calendar::time_split()const { tm time; if ( tf2.count() < 0 ) { return time; } std::chrono::minutes temp = tf2; // Minutes time.minute = (temp % std::chrono::hours{1}).count(); temp -= std::chrono::minutes{1} * time.minute; // Hours time.hour = (std::chrono::duration_cast<std::chrono::hours>(temp % one_day)).count(); temp -= std::chrono::hours{1} * time.hour; // Now days etc. int numdays = temp.count() / std::chrono::duration_cast<std::chrono::minutes>(one_day).count(); time.year = 2014 + numdays / 365; while ( day_count(2014, time.year) > numdays ) { // Correct if problem due to leap years --time.year; } numdays -= day_count(2014, time.year); // Now month for (time.month = 1; numdays >= days_a_month(time.year, time.month); ++time.month) { numdays -= days_a_month(time.year, time.month); } time.day = numdays + 1; return time; }
int recent_manager::how_old_hours(const CString& article_date){ if (!(article_date.StrLength())) return(0); struct tm *newtime; time_t aclock; time( &aclock ); newtime = localtime( &aclock ); struct tm thisdate = encode_date_article(article_date); int day_diff = abs(- day_count(thisdate.tm_mon, thisdate.tm_mday, thisdate.tm_year) + day_count(newtime->tm_mon + 1, newtime->tm_mday, newtime->tm_year)); int hour_diff = newtime->tm_hour - thisdate.tm_hour; if (hour_diff < 0) {day_diff--; hour_diff+=24;} return(day_diff * 24 + hour_diff); }
int recent_manager::how_old(const CString& article_date, int TimeShift){ if (!(article_date.StrLength())) return(0); struct tm ArticleTime = encode_date_article(article_date); ArticleTime.tm_mon--; time_t tclock = mktime(&ArticleTime); if (TimeShift != 0) tclock += (TimeShift * 3600); memcpy(&ArticleTime, localtime(&tclock), sizeof(ArticleTime)); time_t aclock; time( &aclock ); if (TimeShift != 0) aclock += (TimeShift * 3600); struct tm * MachineTime = localtime( &aclock ); return (abs(- day_count(ArticleTime.tm_mon + 1, ArticleTime.tm_mday, ArticleTime.tm_year) + day_count(MachineTime->tm_mon + 1, MachineTime->tm_mday, MachineTime->tm_year))); }
int Chain::Chain_Data::week_count() const { // The number of days the chain spans int days = day_count(); // Add days to make this into a factor of 7 days += weekdays_before_start(); days += weekdays_after_end(); return days / 7; //return start_date().weekNumber() - end_date().weekNumber() + 1; }
long recent_manager::how_old_seconds(const CString& article_date){ if (!(article_date.StrLength())) return(0); struct tm *newtime; time_t aclock; time( &aclock ); newtime = localtime( &aclock ); struct tm thisdate = encode_date_article(article_date); int day_diff = abs(- day_count(thisdate.tm_mon, thisdate.tm_mday, thisdate.tm_year) + day_count(newtime->tm_mon + 1, newtime->tm_mday, newtime->tm_year)); int hour_diff = newtime->tm_hour - thisdate.tm_hour; if (hour_diff < 0) {day_diff--; hour_diff+=24;} hour_diff = day_diff * 24 + hour_diff; long min_diff = newtime->tm_min - thisdate.tm_min; if (min_diff < 0) {hour_diff--; min_diff+=60;} min_diff = hour_diff * 60 + min_diff; long sec_diff = newtime->tm_sec - thisdate.tm_sec; if (sec_diff < 0) {min_diff--; sec_diff+=60;} sec_diff = min_diff * 60 + sec_diff; return(sec_diff); }
date_type date() const { if(time_count_.is_special()) { return date_type(time_count_.as_special()); } else { typename calendar_type::date_int_type dc = day_count(); //std::cout << "time_rep here:" << dc << std::endl; ymd_type ymd = calendar_type::from_day_number(dc); return date_type(ymd); } }
Elf_calendar::Elf_calendar(tm t) { tf2 = std::chrono::minutes{0}; // Minimal validation if ( t.year < 2014 or t.month < 1 or t.month > 12 ) { return; } // Move to correct year counting leap years tf2 += one_day * day_count(2014, t.year); // Move to current month for (int current_month = 1; current_month < t.month; ++current_month) { tf2 += one_day * days_a_month(t.year,current_month); } // Now the rest tf2 += one_day * (t.day - 1); tf2 += std::chrono::hours{1} * t.hour; tf2 += std::chrono::minutes{1} * t.minute; }
void main() { // clrscr(); printf("\n enter the year"); scanf("%d",&yer); printf("\n enter the month"); scanf("%d",&mnt); printf("\n enter the date"); scanf("%d",&dt); yc=yer-1; day_count(); leap_count(); if(yer>=1800) leap_count2(); unknown(); calc(); fake_engine(); print(); getch(); }