/** * @description Funcao responsavel por realizar a devolucao de um livro a biblioteca. * @param m Parametro do tipo modulo de emprestimos, onde serao consultados todos os emprestimos ja realizados afim de encontrar o emprestimo de um determinado usuario. * @param e Parametro do tipo emprestimo que contera os dados do emprestimo que se deseja realizar a devolucao. */ void devolucaoEmprestimo(TModuloEmprestimo *m, TEmprestimo *e) { int pesquisa, qtdeDias, qtdeMeses, qtdeAnos; double multa = 0; leituraDataSaida(&(*e)); pesquisa = pesquisarEmprestimo(*m, *e); if (pesquisa == -1) { printf("\nEmprestimo nao encontrado!\n\n"); } else { e->dataDevolucao.dia = getDay(); e->dataDevolucao.mes = getMonth(); e->dataDevolucao.ano = getYear(); if ((*e).dataDevolucao.dia == (*e).dataEntrega.dia || (*e).dataDevolucao.dia < (*e).dataEntrega.dia) { if ((*e).dataDevolucao.mes == (*e).dataEntrega.mes || (*e).dataDevolucao.mes < (*e).dataEntrega.mes) { if ((*e).dataDevolucao.ano == (*e).dataEntrega.ano || (*e).dataDevolucao.ano < (*e).dataEntrega.ano) { printf("\nDevolucao de livro concedida!\n\n"); } else { qtdeAnos = getYear() - e->dataDevolucao.ano; multa = qtdeAnos * 365 * 0.50; confimaDevolucaoEPgMulta(&(*m), &(*e), pesquisa, multa); } } else { qtdeMeses = getMonth() - e->dataDevolucao.mes; multa = qtdeMeses * 30 * 0.50; confimaDevolucaoEPgMulta(&(*m), &(*e), pesquisa, multa); } } else { qtdeDias = getDay() - (*e).dataEntrega.dia; multa = qtdeDias * 0.50; confimaDevolucaoEPgMulta(&(*m), &(*e), pesquisa, multa); } } }
QString WeatherPlugin::forecastReplace(const QString &text) { if (*getDay(m_day) == 0) return ""; QString res = text; QString temp; int minT = atol(getMinT(m_day)); int maxT = atol(getMaxT(m_day)); temp += QString::number(minT); temp += QChar((unsigned short)176); temp += getUT(); if ((strcmp(getMaxT(m_day), "N/A")) && (maxT != -255)) { temp += "/"; temp += QString::number(maxT); temp += QChar((unsigned short)176); temp += getUT(); } string dd = getDay(m_day); string mon = getToken(dd, ' '); QString day = dd.c_str(); day += ". "; day += i18n(mon.c_str()); res = res.replace(QRegExp("\\%n"), getDayIcon(m_day)); res = res.replace(QRegExp("\\%t"), temp); res = res.replace(QRegExp("\\%c"), i18n_conditions(getDayConditions(m_day))); res = res.replace(QRegExp("\\%w"), i18n(getWDay(m_day))); res = res.replace(QRegExp("\\%d"), day); return res; }
// =========================================================================== // method definitions // =========================================================================== bool AGTrip::operator <(const AGTrip& trip) const { if (getDay() < trip.getDay()) { return true; } if (getDay() == trip.getDay()) if (getTime() < trip.getTime()) { return true; } return false; }
void calculateDate(){ int r = calculateRemainDate(); if(r > D){ addDay(); return; } D -= r; d = 1; m = 1; y++; while(D >= getDay()){ D -= getDay(); y++; } addDay(); }
bool Date::operator<(const Date &right) { if (getYear() == right.getYear()) { if (getMonth() == right.getMonth()) { if (getDay() == right.getDay()) return false; return (getDay() < right.getDay()); } return (getMonth() < right.getMonth()); } return (getYear() < right.getYear()); }
int controlDates(char * client_date, char * server_date,time_t * time) { struct tm newServer_date; struct tm newClient_date; time_t server_time; time_t client_time; char server_day[4] = "\0"; char client_day[4] = "\0"; char server_mon[4] = "\0"; char client_mon[4] = "\0"; double diff; strncpy(server_day,server_date,3); strncpy(client_day,client_date,3); strncpy(server_mon,server_date + 4,3); strncpy(client_mon,client_date + 4,3); newServer_date.tm_wday = getDay(server_day); newClient_date.tm_wday = getDay(client_day); newServer_date.tm_mon = getMonth(server_mon); newClient_date.tm_mon = getMonth(client_mon); newServer_date.tm_mday = atoi((&server_date[7]) + 1); newClient_date.tm_mday = atoi((&client_date[7]) + 1); newServer_date.tm_hour = atoi((&server_date[10]) + 1); newClient_date.tm_hour = atoi((&client_date[10]) + 1); newServer_date.tm_min = atoi((&server_date[13]) + 1); newClient_date.tm_min = atoi((&client_date[13]) + 1); newServer_date.tm_sec = atoi((&server_date[16]) + 1); newClient_date.tm_sec = atoi((&client_date[16]) + 1); newServer_date.tm_year = atoi((&server_date[17]) + 3) - 1900; newClient_date.tm_year = atoi((&client_date[17]) + 3) - 1900; newServer_date.tm_isdst = 0; newClient_date.tm_isdst = 0; server_time = mktime(&newServer_date); client_time = mktime(&newClient_date); *time = mktime(&newClient_date); diff = difftime(server_time, client_time); return diff > 0; }
int Date::dateDifference(Date dateToCompare) { Date temp; temp.setDay(getDay()); temp.setMonth(getMonth()); temp.setYear(getYear()); int difference=0; if(temp.compareDates(dateToCompare)>=0) { while(temp.compareDates(dateToCompare)!=0) { temp.incrementDays(1); difference++; } } else { while(dateToCompare.compareDates(temp)!=0) { dateToCompare.incrementDays(1); difference++; } } return difference; }
int main() { int n;char ch; printf("Enter 2, 3 or 4:"); scanf("%d",&n); ch=getDay(n); printf("The day is %c\n",ch); if(ch=='M') printf("The day is Monday\n"); else if(ch=='T') printf("The day is Tuseday\n"); else if(ch=='W') printf("The day is Wednesday\n"); else printf("There is an Error\n"); return 0; }
void AGTime::setDay(int d) { if (0 <= d) { sec -= 86400 * getDay(); sec += 86400 * d; } }
void Date::setSeconds( int aSeconds ) throw ( DateException ) { settm( getDay(), getMonth(), getYear(), aSeconds ); } /* end Date::setSeconds() */
void Date::setYear( int aYear ) throw( DateException ) { settm( getDay(), getMonth(), aYear, getSecond() ); } /* end Date::setYear() */
/*! * \brief UTCからローカル時間に変換 */ void DateTime::toLocal() { #if defined(_WINDOWS) TIME_ZONE_INFORMATION timeZone; GetTimeZoneInformation(&timeZone); int32_t bias = -timeZone.Bias / 60; #else struct timezone tz; gettimeofday(nullptr, &tz); int32_t bias = -tz.tz_minuteswest / 60; #endif struct tm tm; tm.tm_year = getYear() - 1900; tm.tm_mon = getMonth() - 1; tm.tm_mday = getDay(); tm.tm_hour = getHour() + bias; tm.tm_min = getMinute(); tm.tm_sec = getSecond(); tm.tm_yday = tm.tm_wday = tm.tm_isdst = 0; #if defined(_WINDOWS) time_t time = mktime(&tm); #else time_t time = mktime(&tm); // time_t time = timegm(&tm); #endif struct tm* tmLocal = localtime(&time); toValue(tmLocal, getMilliSecond()); }
string ViewType::getDateTaskString(int date) { string dateString; string day; string month; string year; int weekRange; Commons commons; int test = _dayToEndOfWeek; weekRange = commons.addToDate(_dayToEndOfWeek, _currentDate); if(_currentDate <= date && date <= weekRange && date > 0) { if(_currentDate == date) { return MESSAGE_TODAY; } else { return commons.getDateStringDay(commons.getDayNumber(date)); } } else { if(date > 0) { if(weekRange < date && date <= weekRange + NO_OF_DAYS_IN_WEEK) { return MESSAGE_NEXT + commons.getDateStringDay(commons.getDayNumber(date)); } else { day = getDay(date); month = getMonth(date); dateString = day + MESSAGE_MONTH_SEPERATOR + month; return dateString; } } else { return MESSAGE_VOID_STRING; } } }
//vygeneruje XML subor bool generateXML(Car *car, int n) { FILE *xmlOut = fopen("cars.xml", "w"); int i; if (xmlOut != NULL) { fprintf(xmlOut, "<?xml version=\"1.0\" encoding=\"UTF - 8\"?>\n"); fprintf(xmlOut, "<cars>\n"); for (i = 0; i < n; i++) { fprintf(xmlOut, "\n\t<car id=%d>\n", i + 1); //item start nextElement(xmlOut, "type", car[i].type, "brand", car[i].brand, 2); //brand & type nextElement(xmlOut, "color", getColor(car[i].color), NULL, NULL, 2); //color nextElement(xmlOut, "year", getYear(car[i].year),NULL,NULL,2); //year char temp[2]; //fuel temp[0] = car[i].fuel; temp[1] = '\0'; nextElement(xmlOut, "fuel", temp, NULL, NULL, 2); //date char **tags = (char**)malloc(sizeof(char*) * 3); //tags tags[0] = (char*)malloc(sizeof(char) * 4); strcpy(tags[0], "day\0"); tags[1] = (char*)malloc(sizeof(char) * 6); strcpy(tags[1], "month\0"); tags[2] = (char*)malloc(sizeof(char) * 5); strcpy(tags[2], "year\0"); char **values = (char**)malloc(sizeof(char*) * 3); //values values[0] = (char*)malloc(sizeof(char) * (strlen(getDay(car[i].evidDate.day)) + 1)); strcpy(values[0], getDay(car[i].evidDate.day)); values[1] = (char*)malloc(sizeof(char) * (strlen(getMonth(car[i].evidDate.month)) + 1)); strcpy(values[1], getMonth(car[i].evidDate.month)); values[2] = (char*)malloc(sizeof(char) * (strlen(getYear(car[i].evidDate.year)) + 1)); strcpy(values[2], getYear(car[i].evidDate.year)); nextStructElement(xmlOut, "date", tags, values, 3, NULL, NULL, 2); nextElement(xmlOut, "plate", car[i].licansePlate, NULL, NULL, 2); //licanse plate fprintf(xmlOut, "\t<performance>%d KW</performance>\n", car[i].performance); //performance fprintf(xmlOut, "\t<driven>%d km</driven>\n", car[i].driven); //driven fprintf(xmlOut, "\t</car>\n"); //item end } fprintf(xmlOut, "\n</cars>\n"); return true; } return false; }
Date Date::addDaysGet(long days) { long months = getMonth(); long year = getYear() + months/12; months = months%12; long g = getDays(year,months,getDay()+days); return getDateFromDays(g); }
Date Date::addMonthsGet(long months) { months = getMonth() + months; long year = getYear() + months/12; months = months%12; long g = getDays(year,months,getDay()); return getDateFromDays(g); }
// Based on http://www.webexhibits.org/daylightsaving/i.html // Equations by Wei-Hwa Huang (US), and Robert H. van Gent (EC) int RTCDue::isSummertime (int select) { int _sundaysommertime, _sundaywintertime, _begin_Month, _end_Month, _summertime; _summertime = 0; _hour = getHours (); _day = getDay (); _month = getMonth (); _year = getYear (); //4 digits switch (select) { default: case EEC: // European Economic Community (EEC): // Begin DST: Sunday March _sundaysommertime = 31 - ( 4 + _year * 5 / 4 ) % 7; // End DST: Sunday October _sundaywintertime = 31 - ( 1 + _year * 5 / 4 ) % 7; _begin_Month = 3; _end_Month = 10; break; case US: // For the United States (US): if ( _year < 2007 ) { // Valid for years 1900 to 2006, though DST wasn't adopted until the 1950s-1960s. // Begin DST: Sunday April _sundaysommertime = ( 2 + 6 * _year - _year / 4 ) % 7 + 1; // End DST: Sunday October _sundaywintertime = 31 - ( _year * 5 / 4 + 1 ) % 7; _begin_Month = 4; _end_Month = 10; } else { // Valid for 2007 and after: // Begin DST: Sunday March _sundaysommertime = 14 - ( 1 + _year * 5 / 4 ) % 7; // End DST: Sunday November _sundaywintertime = 7 - ( 1 + _year * 5 / 4 ) % 7; _begin_Month = 3; _end_Month = 11; } break; } if ( _month >= _begin_Month && _month <= _end_Month ) { _summertime = 1; if ( _month == _begin_Month && _day < _sundaysommertime ) { _summertime = 0; } if ( _month == _end_Month && _day > _sundaywintertime ) { _summertime = 0; } } return _summertime; }
void Date::updateYears(long years) { long g = getDays(getYear()+years,getMonth(),getDay()); Date d = getDateFromDays(g); setDay(d.getDay()); setMonth(d.getMm()); setYear(d.getYear()); setDayw(d.getDayw()); }
QString WeatherPlugin::forecastReplace(const QString &text) { if (*getDay(m_day) == 0) return ""; QString res = text; QString temp; int minT = atol(getMinT(m_day)); int maxT = atol(getMaxT(m_day)); if ((minT < 0) && (maxT < 0)){ int r = minT; minT = maxT; maxT = r; } if (minT < 0){ temp += "-"; minT = -minT; }else if (minT > 0){ temp += "+"; } temp += number((unsigned)minT).c_str(); temp += QChar((unsigned short)176); temp += getUT(); if (maxT < 0){ temp += "-"; maxT = -maxT; }else if (maxT >= 0){ temp += "+"; } temp += number((unsigned)maxT).c_str(); temp += QChar((unsigned short)176); temp += getUT(); string dd = getDay(m_day); string mon = getToken(dd, ' '); QString day = dd.c_str(); day += " "; day += i18n(mon.c_str()); res = res.replace(QRegExp("\\%n"), number(m_day).c_str()); res = res.replace(QRegExp("\\%t"), temp); res = res.replace(QRegExp("\\%c"), i18n_conditions(getDayConditions(m_day))); res = res.replace(QRegExp("\\%w"), i18n(getWDay(m_day))); res = res.replace(QRegExp("\\%d"), day); return res; }
long Date::getDaysInt() { long y = getYear(); long m = getMonth(); long d = getDay(); y = y -1900; m = (m + 9) % 12; y = y - m/10; return 365*y + y/4 - y/100 + y/400 + (m*306 + 5)/10 + ( d - 1 ); }
void print_time(time_t tim) { std::cout << getWeekday(tim) << std::endl; std::cout << getSec(tim) << std::endl; std::cout << getMin(tim) << std::endl; std::cout << getHour(tim) << std::endl; std::cout << getYear(tim) << std::endl; std::cout << getDay(tim) << std::endl; std::cout << getMonth(tim) << std::endl; }
bool MrgSorter::isDateValid ( const DateType &date // in: Date ) { int day, month, year; day = getDay( date ); month = getMonth( date ); year = getYear( date ); // Check if any were invalid if( day == -1 || month == -1 || year == -1 ) { return false; } // Months that should only have 30 days // getMonth already made sure day is less than or equal to 31 if( month == 2 || month == 4 || month == 6 || month == 9 || month == 11 ) { if( day > 30 ) { return false; } // Check for February, including leap years if( month == 2 ) { if( day > 29 ) { return false; } else if( day == 29 ) { if( isLeapYear( year ) ) { return true; } else { return false; } } } } return true; }
int RTCDue::setMonth (int month) { _day_of_week = calculateDayofWeek( getYear(), _month, getDay() ); _day_of_week = BIN2BCD( _day_of_week ) << RTC_CALR_DAY_Pos; _changed = BIN2BCD( month ) << RTC_CALR_MONTH_Pos; _current_date = ( currentDate() & ~RTC_CALR_DAY_Msk & ~RTC_CALR_MONTH_Msk ) ^ ( _changed | _day_of_week ); return (int)changeDate(_current_date); }
int RTCDue::setYear (uint16_t year) { _day_of_week = calculateDayofWeek( year, getMonth(), getDay() ); _day_of_week = BIN2BCD( _day_of_week ) << RTC_CALR_DAY_Pos; _changed = BIN2BCD( year / seperator ) << RTC_CALR_CENT_Pos | BIN2BCD( year % seperator ) << RTC_CALR_YEAR_Pos; _current_date = ( currentDate() & ~RTC_CALR_DAY_Msk & ~RTC_CALR_YEAR_Msk ) ^ ( _changed | _day_of_week ); return (int)changeDate(_current_date); }
int main () { int y, m, d, days, resYear, resMonth, resDay; printf ("Input year, month, day (y,m,d) :"); scanf ("%d,%d,%d", &y, &m, &d); printf ("Input how many days later:"); scanf ("%d", &days); getDay (y, m, d, days,&resYear, &resMonth, &resDay); printf ("%d days after %d.%d.%d is %d.%d.%d. \n", days, y, m, d, resYear, resMonth, resDay); return 0; }
double ossimLocalTm::getJulian()const { int J = getMonth(); int K = getDay(); int I = getYear(); return (K-32075+1461*(I+4800+(J-14)/12)/4+367*(J-2-(J-14)/12*12) /12-3*((I+4900+(J-14)/12)/100)/4+ (getHour()/24.0)+ (getMin()/1440.0)+ ((getSec()+theFractionalSecond)/86400.0)); }
void Date::updateMonths(long months) { months = getMonth() + months; long year = getYear() + months/12; months = months%12; long g = getDays(year,months,getDay()); Date d = getDateFromDays(g); setDay(d.getDay()); setMonth(d.getMm()); setYear(d.getYear()); setDayw(d.getDayw()); }
/*! * \brief 日付時間をミリ秒に変換 */ int64_t DateTime::toMilliSeconds() const { enum { January = 0, February = January + 31, March = February + 28, April = March + 31, May = April + 30, June = May + 31, July = June + 30, August = July + 31, September = August + 31, October = September + 30, November = October + 31, December = November + 30, }; static const int64_t daySpan[] = { January, February, March, April, May, June, July, August, September, October, November, December, }; int64_t y = getYear(); int64_t m = getMonth(); int64_t d = getDay(); int64_t dy = (y - 1) * 365; // 年数分の日数 int64_t dl = (y / 4) - (y / 100) + (y / 400); // 閏年分の日数 int64_t dm = daySpan[m - 1]; // 1月1日からm月1日までの日数 int64_t result = dy + dl + dm + d - 1; result = (result * 24 * 60 * 60 * 1000) + (getHour() * 60 * 60 * 1000) + (getMinute() * 60 * 1000) + (getSecond() * 1000) + getMilliSecond(); return result; }
// Convert to tm struct tm strToTm(const char *strDate) { struct tm tmDate = { 0 }; int year = 0; char strMonth[4] = {0},strDay[4] = { 0 }; sscanf(strDate, "%3s, %d %3s %d %d:%d:%d %*s", strDay, &(tmDate.tm_mday), strMonth, &year, &(tmDate.tm_hour), &(tmDate.tm_min), &(tmDate.tm_sec)); tmDate.tm_wday = getDay(strDay); tmDate.tm_mon = getMonth(strMonth); tmDate.tm_year = year - 1900; tmDate.tm_isdst = -1; return tmDate; }
/*! * 曜日を取得する */ int32_t DateTime::getWeekDay() const { static int32_t t[] = {0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4}; int32_t y = getYear(); int32_t m = getMonth(); int32_t d = getDay(); if (m < 3) y--; return ((y + y / 4 - y / 100 + y / 400 + t[m - 1] + d) % 7); }