int Date::test() { unsigned long long gg = getDays(2008,12,31); getDateFromDays(gg); gg = getHours(2008,12,31,12); getDateFromHours(gg); gg = getMinutes(2008,12,31,12,56); getDateFromMinutes(gg); gg = getSeconds(2008,12,31,12,56,56); getDateFromSeconds(gg); Date d; //logger << d.toString() << endl; Date d1 = d.addYears(1); //logger << d1.toString() << endl; Date d2 = d.addMonths(23); //logger << d2.toString() << endl; Date d3 = d.addDays(17); //logger << d3.toString() << endl; Date d4 = d.addHours(25); //logger << d4.toString() << endl; Date d5 = d.addMinutes(61); //logger << d5.toString() << endl; Date d6 = d.addSeconds(61); //logger << d6.toString() << endl; return 0; }
ostream& Time::putDataInStream( ostream& os) const { //put (semi-formatted) time (H:M:S) into an output stream os << getHours() << ":"; os << getMinutes() << ":"; os << getSeconds(); return os; }
int main() { struct Employee emps[SIZE] = { { 98401, 10.60 }, { 526488, 9.75 }, { 765349, 10.50 }, { 34645, 12.25 }, { 127615, 8.35 } }; for (int i = 0; i < SIZE; ++i){ emps[i].hours = getHours(emps[i]); emps[i].overtime = getOvertimeHours(emps[i]); /* Calculate total amount of overtime hours */ emps[i].overtimePay = getOvertimePay(emps[i]); /* Calculate total amount of overtime pay, if necessary */ emps[i].gross = getGross(emps[i]); /* Calculate gross pay */ } printData(emps); /* Calculate the total gross pay per employee for (int i = 0; i < SIZE; i++) { hours[i] = getHours(clockNumber[i]); overtime[i] = getOvertimeHours(hours[i]); /* Calculate total amount of overtime hours overtimePay[i] = getOvertimePay(overtime[i], wage[i]); /* Calculate total amount of overtime pay, if necessary gross[i] = getGross(hours[i], overtimePay[i], wage[i]); /* Calculate gross pay } printData(clockNumber, wage, hours, overtime, gross); */ return(0); }
long Date::getMinutes(long y,long m,long d, long hh, long mi) { long g = getHours(y,m,d,hh); int mfh = mi/60; mi = mi%60; return (g+mfh)*60 + mi; }
/** * Die Uhrzeit auslesen und in den Variablen ablegen */ void MyRTC::readTime() { byte returnStatus, count, result, retries = 0; do { // Reset the register pointer Wire.beginTransmission(_address); Wire.write((uint8_t) 0x00); result = Wire.endTransmission(false); // false, damit der Bus nicht freigegeben wird und eventuell andere dazwischen kommen (in Multi-MCU-Umgebungen) DEBUG_PRINT(F("Wire.endTransmission(false) = ")); DEBUG_PRINTLN(result); count = Wire.requestFrom(_address, 7); DEBUG_PRINT(F("Wire.requestFrom(_address, 7) = ")); DEBUG_PRINTLN(count); DEBUG_FLUSH(); if (count == 7) { // Success // A few of these need masks because certain bits are control bits _seconds = bcdToDec(Wire.read() & 0x7f); _minutes = bcdToDec(Wire.read()); _hours = bcdToDec(Wire.read() & 0x3f); // Need to change this if 12 hour am/pm _dayOfWeek = bcdToDec(Wire.read()); _date = bcdToDec(Wire.read()); _month = bcdToDec(Wire.read()); _year = bcdToDec(Wire.read()); } else { // Fail // keine 7 Byte zurueck gekommen? Buffer verwerfen... for (int i = 0; i < count; i++) { Wire.read(); } retries++; } result = Wire.endTransmission(true); // true, jetzt den Bus freigeben. DEBUG_PRINT(F("Wire.endTransmission(true) = ")); DEBUG_PRINTLN(result); } while ((count != 7) && (retries < 8)); if (retries == 8) { // Es konnte nichts gelesen werden _seconds = 11; _minutes = 11; _hours = 11; _dayOfWeek = 1; _date = 1; _month = 1; _year = 2014; } DEBUG_PRINT(F("Time: ")); DEBUG_PRINT(getHours()); DEBUG_PRINT(F(":")); DEBUG_PRINT(getMinutes()); DEBUG_PRINT(F(":")); DEBUG_PRINTLN(getSeconds()); DEBUG_FLUSH(); }
boolean RealTimeClockDS1307::isPM() { //if in 12-hour mode, but 5 of the hour register indicates PM if(is12hour()) { return ((_reg2_hour & 0x20) == 0x20); } //otherwise, let's consider any time with the hour >11 to be PM: return (getHours() > 11); }
void printPrettyTime() { tcputs(itoa(getHours()),COLOR_WHITE); tcputs(":",COLOR_WHITE); tcputs(itoa(getMinutes()),COLOR_WHITE); tcputs(":",COLOR_WHITE); tcputs(itoa(getSeconds()),COLOR_WHITE); tputs("\n"); }
ostream& Time::putDataInStream( ostream& os) const { //put digital clock formatted time ("HH:MM:SS") into an output stream os << setfill('0'); os << setw(2) << getHours() << ":"; os << setw(2) << getMinutes() << ":"; os << setw(2) << getSeconds(); os << setfill(' '); return os; }
// 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; }
const string Time::toFormattedString() const { //return time formatted output ("HH:MM:SS") ostringstream os_time; os_time << setfill('0'); os_time << setw(2) << getHours() << ":"; os_time << setw(2) << getMinutes() << ":"; os_time << setw(2) << getSeconds(); return ( os_time.str()); }
Duration *Period::toStandardDuration() { checkYearsAndMonths("Duration"); int64_t millis = getMillis(); // no overflow can happen, even with Integer.MAX_VALUEs millis += (((int64_t) getSeconds()) * ((int64_t) DateTimeConstants::MILLIS_PER_SECOND)); millis += (((int64_t) getMinutes()) * ((int64_t) DateTimeConstants::MILLIS_PER_MINUTE)); millis += (((int64_t) getHours()) * ((int64_t) DateTimeConstants::MILLIS_PER_HOUR)); millis += (((int64_t) getDays()) * ((int64_t) DateTimeConstants::MILLIS_PER_DAY)); millis += (((int64_t) getWeeks()) * ((int64_t) DateTimeConstants::MILLIS_PER_WEEK)); return new Duration(millis); }
char* DS1307::getTime(void) { uint8_t seconds = getSeconds(); uint8_t minutes = getMinutes(); hours_t hours = getHours(); snprintf(timeBuf, 10, "%02d:%02d:%02d", hours.hours, minutes, seconds); return timeBuf; }
Weeks *Period::toStandardWeeks() { checkYearsAndMonths("Weeks"); int64_t millis = getMillis(); // assign to a int64_t millis += ((int64_t) getSeconds()) * DateTimeConstants::MILLIS_PER_SECOND; millis += ((int64_t) getMinutes()) * DateTimeConstants::MILLIS_PER_MINUTE; millis += ((int64_t) getHours()) * DateTimeConstants::MILLIS_PER_HOUR; millis += ((int64_t) getDays()) * DateTimeConstants::MILLIS_PER_DAY; int64_t weeks = ((int64_t) getWeeks()) + millis / DateTimeConstants::MILLIS_PER_WEEK; return Weeks::weeks(FieldUtils::safeToInt(weeks)); }
Seconds *Period::toStandardSeconds() { checkYearsAndMonths("Seconds"); int64_t seconds = getMillis() / DateTimeConstants::MILLIS_PER_SECOND; seconds = FieldUtils::safeAdd(seconds, (int64_t) getSeconds()); seconds = FieldUtils::safeAdd(seconds, ((int64_t) getMinutes()) * ((int64_t) DateTimeConstants::SECONDS_PER_MINUTE)); seconds = FieldUtils::safeAdd(seconds, ((int64_t) getHours()) * ((int64_t) DateTimeConstants::SECONDS_PER_HOUR)); seconds = FieldUtils::safeAdd(seconds, ((int64_t) getDays()) * ((int64_t) DateTimeConstants::SECONDS_PER_DAY)); seconds = FieldUtils::safeAdd(seconds, ((int64_t) getWeeks()) * ((int64_t) DateTimeConstants::SECONDS_PER_WEEK)); return Seconds::seconds(FieldUtils::safeToInt(seconds)); }
Minutes *Period::toStandardMinutes() { checkYearsAndMonths("Minutes"); int64_t millis = getMillis(); // assign to a int64_t millis += ((int64_t) getSeconds()) * DateTimeConstants::MILLIS_PER_SECOND; int64_t minutes = millis / DateTimeConstants::MILLIS_PER_MINUTE; minutes = FieldUtils::safeAdd(minutes, (int64_t) getMinutes()); minutes = FieldUtils::safeAdd(minutes, ((int64_t) getHours()) * ((int64_t) DateTimeConstants::MINUTES_PER_HOUR)); minutes = FieldUtils::safeAdd(minutes, ((int64_t) getDays()) * ((int64_t) DateTimeConstants::MINUTES_PER_DAY)); minutes = FieldUtils::safeAdd(minutes, ((int64_t) getWeeks()) * ((int64_t) DateTimeConstants::MINUTES_PER_WEEK)); return Minutes::minutes(FieldUtils::safeToInt(minutes)); }
void consoleService() { char ch ; ch = readKey(); if ( ch < 1 ) { ch = readServer(); if (ch < 1) return; } if ( controlMode(ch) ) { p(" -> %02d:%02d:%02d ", getHours(), getMinutes(), getSeconds() ); } }
Days *Period::toStandardDays() { checkYearsAndMonths("Days"); int64_t millis = getMillis(); // assign to a int64_t millis += ((int64_t) getSeconds()) * DateTimeConstants::MILLIS_PER_SECOND; millis += ((int64_t) getMinutes()) * DateTimeConstants::MILLIS_PER_MINUTE; millis += ((int64_t) getHours()) * DateTimeConstants::MILLIS_PER_HOUR; int64_t days = millis / DateTimeConstants::MILLIS_PER_DAY; days = FieldUtils::safeAdd(days, (int64_t) getDays()); days = FieldUtils::safeAdd(days, ((int64_t) getWeeks()) * ((int64_t) DateTimeConstants::DAYS_PER_WEEK)); return Days::days(FieldUtils::safeToInt(days)); }
/* get time in string format * default format is: * "hh:mm::ss'ddd", * where: * hh - hour, * mm - minures, * ss - seconds, * ddd - miliseconds. */ rfc::String rfc::Time::getTimeString() const { /* if (isInfinity) return QString("infinity"); */ return String::toString(getHours()) + QString(":") + String::toString(getMinutes()) + QString(":") + String::toString(getSeconds()) + QString("'") + String::toString(getMilliSec()); } /* end of 'Time::getTimeString' function */
// Part 3 int addTimes( int start, int duration ) { /* This function returns the finishing time given a starting time and the duration of time elapsed since. Pre: 'start' and 'duration' are specified in military time (ie 1400) Post: Finishing time is returned in military time */ int mins; mins = getMins( start ) + getMins( duration ); return getHours( mins ); }
void RealTimeClockDS1307::switchTo24h() { if(!is12hour()) { return ; } int h = getHours(); if(h==12) {//12 PM is just 12; 12 AM is 0 hours. h = 0; } if (isPM()) {//if it was 12 PM, then h=0 above and so we're back to 12: h = h+12; } set24h(); setHours(h); }
zstring TimeZone::toString() const { zstring result; if ( *this ) { if ( !gmtoff_ ) result = 'Z'; else { result += *this < 0 ? '-' : '+'; result += zero_pad( std::abs( getHours() ), 2 ); result += ':'; result += zero_pad( std::abs( getMinutes() ), 2 ); } } return result; }
// returns str of length 6 (with zero symbol) const char* getTimeStrHoursMinutes(void) { static char timeStrBuff[6]; const uint08 hours = getHours(); timeStrBuff[0] = GET_PROGMEM_DIGIT(hours / 10); timeStrBuff[1] = GET_PROGMEM_DIGIT(hours % 10); timeStrBuff[2] = ':'; const uint08 minutes = getMinutes(); timeStrBuff[3] = GET_PROGMEM_DIGIT(minutes / 10); timeStrBuff[4] = GET_PROGMEM_DIGIT(minutes % 10); timeStrBuff[5] = '\0'; return timeStrBuff; }
void RealTimeClockDS1307::switchTo12h() { if(is12hour()) { return; } int h = getHours(); if (h < 12) { setAM(); } else { h = h-12; setPM(); } if (h==0) { h=12; } setHours(h); }
string Time::toString() { stringstream h; h << getHours(); stringstream m; m << getMinutes(); stringstream s; s << getSeconds(); string output = ""; output += h.str(); output += ':'; output += m.str(); output += ':'; output += s.str(); return output; }
// Print the current time and A/B signal levels on the console void showTime() { unsigned int s = getSeconds(); //-- Newline + whole time every minute if ( s == 0 ) p("\r\n%02u%s:%02u:%02u ", getHours(), getDST() ? "D" : "", getMinutes(), s); else if ( (s % 10 ) == 0) p("%02u", s ); else p("-"); //-- Show the A/B/D/E pulse status, F level if (getA()) p("A"); if (getB()) p("B"); if (getD()) p("D"); if (getE()) p("E"); if (getF()) p("F"); }
int main() { long int clockNumber[NUM_EMPL] = {98401,526488,765349,34645,127615}; /* unique ID */ float gross[NUM_EMPL]; /* Gross pay */ float hours[NUM_EMPL]; /* Hours worked in a given week */ float overtime[NUM_EMPL]; /* Overtime hours */ float wageRate[NUM_EMPL] = {10.60,9.75,10.50,12.25,8.35}; /* hourly wage rate */ float sumWages; /* Sum of wages per hour */ float sumHours; /* Sum of Hours worked in a given week */ float sumOver; /* Sum of overtime hours */ float sumGross; /* Sum of gross pay in a given week */ float avgWages; /* Average of wage rates */ float avgHours; /* Average hours worked */ float avgOver; /* Average overtime hours worked */ float avgGross; /* Average gross pay for the week */ int i; /* Loop and array index */ for (i = 0; i < NUM_EMPL; ++i) { hours[i] = getHours (clockNumber[i]); /* Calls user's input */ overtime[i] = calcOvertime (hours[i]); /* Calculates overtime */ gross[i] = calcGross (overtime[i], hours[i], wageRate[i]); /* calculates gross */ sumWages = sumWageRate (wageRate[i]); /* Sums all wages */ sumHours = sumHoursWorked (hours[i]); /* Sums all hours */ sumOver = sumOvertime (overtime[i]); /* Sums overtime */ sumGross = sumGrossPay (gross[i]); /* Sums gross pay*/ } avgWages = avgWageRate (sumWages); /* Calculates avg wage */ avgHours = avgHoursWorked (sumHours); /* Calculates avg hours */ avgOver = avgOvertime (sumOver); /* Calculates avg overtime */ avgGross = avgGrossPay (sumGross); /* Calculates avg gross */ printf ("\n"); /* New line for output */ printf ("Clock# \tWages \tHours \tOvTime \tGross\n"); /* Display table headings */ printf ("------ \t------ \t------ \t------ \t------ \n"); /* Format display header */ printData (clockNumber, wageRate, hours, overtime, gross, NUM_EMPL); /* Prints by reference */ printf ("------ \t------ \t------ \t------ \t------ \n"); /* Format display header*/ printTotals (sumWages, sumHours, sumOver, sumGross); /* Function prints totals */ printAvgs (avgWages, avgHours, avgOver, avgGross); /* Function prints averages */ return (0); }
uint32_t RTCDue::unixtime () { uint32_t _ticks; uint16_t _days; _hour = getHours (); _minute = getMinutes (); _second = getSeconds (); _day = getDay (); _month = getMonth (); _year = getYear (); //4 digits // Based on https://github.com/punkiller/workspace/blob/master/string2UnixTimeStamp.cpp // days of the years between start of unixtime and now _days = 365 * (_year - 1970); // add days from switch years in between except year from date for( int i = 1970; i < _year; i++ ){ if( switch_years (i) ) { _days++; } } // Based on https://github.com/adafruit/RTClib/blob/master/RTClib.cpp // add switch day from actuall year if necessary for ( int i = 1; i < _month; ++i ) _days += daysInMonth[i - 1]; if ( _month > 2 && switch_years (_year) ) ++_days; _days += _day - 1; _ticks = ((_days * 24 + _hour) * 60 + _minute) * 60 + _second; return _ticks; }
int main() { /* declaring variables needed for program */ long int clockNumber[SIZE] = { 98401, 526488, 765349, 34645, 127615 }; /* form of worker identification */ float gross[SIZE]; /* Gross pay for the employee */ float hours[SIZE]; /* Number of hours worked */ int i; /* loop index */ float overtime[SIZE] {}; /* Number of overtime hours */ float overtimePay[SIZE] {}; /* Number of overtime pay */ float wage[SIZE] = { 10.6, 9.75, 10.5, 12.25, 8.35 }; /* money earned per hour of work */ /* Calculate the total gross pay per employee */ for (int i = 0; i < SIZE; i++) { hours[i] = getHours(clockNumber[i]); overtime[i] = getOvertimeHours(hours[i]); /* Calculate total amount of overtime hours */ overtimePay[i] = getOvertimePay(overtime[i], wage[i]); /* Calculate total amount of overtime pay, if necessary */ gross[i] = getGross(hours[i], overtimePay[i], wage[i]); /* Calculate gross pay */ } printData(clockNumber, wage, hours, overtime, gross); return(0); }
void setSeconds(const uint08 seconds) { setClock(getHours(), getMinutes(), seconds); }
void setMinutes(const uint08 minutes) { setClock(getHours(), minutes, getSeconds()); }