TimeStamp::TimeStamp(byte seconds, byte minutes, byte hours, byte dayOfWeek, byte day, byte month, byte year) { setSeconds(seconds); setMinutes(minutes); setHours(hours); setDayOfWeek(dayOfWeek); setDay(day); setMonth(month); setYear(year); }
time_t parseDateTimeString(const char *str) { yy_switch_to_buffer(yy_scan_string(str)); yyparse(); time_t tempTime = mktime(str_time); str_time= localtime(&tempTime); setFinalTime(&set_time, finalSpecAmount, fromChangeAmount); tempTime = mktime(str_time); str_time= localtime(&tempTime); if(fromModifier.specValue[1]) { setDayOfWeek(fromModifier.specValue[1], fromModifier.specAmount); } return mktime(str_time); }
void Clock::tick(void) { unsigned long delta_millis = millis() - lastMillis; unsigned long secs_elapsed = delta_millis / 1000; lastMillis += secs_elapsed * 1000; secsToday += secs_elapsed; if (secsToday >= SECS_PER_DAY) { // Roll the seccond counter secsToday = secsToday - SECS_PER_DAY; // Increment the day counters setDayOfWeek((getDayOfWeek() + 1) % 7); // Don't let the day number roll over if (dayNumber < 0xFF) { setDayNumber(getDayNumber() + 1); } } }
void setFinalTime(struct tm *temp, int amount[], int *change) { // printf("set final time BEFORE= temp time= %s\n", asctime(str_time)); time_t tempTime = mktime(str_time); str_time= localtime(&tempTime); if(temp->tm_year >= 0) { str_time->tm_year = temp->tm_year; amount[2] = 0; } *timePointer[6] += change[6]; tempTime = mktime(str_time); str_time= localtime(&tempTime); int mon = str_time->tm_mon; if(temp->tm_mon >= 0) { amount[2] = 0; if(temp->tm_mon >=12) { str_time->tm_mon = mon = temp->tm_mon-12; str_time->tm_year +=1; } else { if(str_time->tm_mon > temp->tm_mon && (temp->tm_year < 0 && change[6]==0)) { if(amount[0] <= 0) str_time->tm_year += (amount[0]+1); else str_time->tm_year += amount[0]; } else if(str_time->tm_mon < temp->tm_mon) { if(amount[0] <= 0) str_time->tm_year += (amount[0]); else str_time->tm_year += (amount[0]-1); } else if(str_time->tm_mon == temp->tm_mon) { str_time->tm_year += amount[0]; } str_time->tm_mon = mon = temp->tm_mon; } } // printf("set final time after= temp time= %s\n", asctime(str_time)); *timePointer[5] += change[5]; tempTime = mktime(str_time); str_time= localtime(&tempTime); if(str_time->tm_mon != (mon+change[5])) str_time->tm_mon = (mon+change[5]); /******* change[7] is the number of weeks ******/ if(change[7]) { str_time->tm_mday += 7*change[7]; str_time->tm_mday -= str_time->tm_wday; tempTime = mktime(str_time); str_time= localtime(&tempTime); // printf("main time after month/year change = %s\n", asctime(str_time)); } if(temp->tm_mday >=0) { if(change[7]) { str_time->tm_mday += temp->tm_mday; } else str_time->tm_mday = temp->tm_mday; tempTime = mktime(str_time); str_time= localtime(&tempTime); // printf("the set day %d and is %s \n", temp->tm_mday, asctime(str_time)); } if(amount[1]>0 && temp->tm_mday >=0 && temp->tm_wday <0) temp->tm_wday = 0;//str_time->tm_wday; setDayOfWeek(temp->tm_wday, amount); // printf("amount2 = %d and change3 = %d", amount[2], change[3]); if(amount[2]!= 0 && change[3]==0) { switch(change[8]) { case 'm': { // printf("in the morning"); if(temp->tm_hour >= 0) { if((temp->tm_hour < str_time->tm_hour || (temp->tm_hour == str_time->tm_hour && temp->tm_min < str_time->tm_min))) str_time->tm_mday += 1; } else if(str_time->tm_hour > 12) str_time->tm_mday += 1; } break; case 'a': { // printf("in the afternoon"); if(temp->tm_hour >= 0) { if((temp->tm_hour < str_time->tm_hour || (temp->tm_hour == str_time->tm_hour && temp->tm_min < str_time->tm_min))) str_time->tm_mday += 1; } else if(str_time->tm_hour > 17) str_time->tm_mday += 1; } break; case 'e': { // printf("in the evening %d", temp->tm_hour); if(temp->tm_hour >= 0) { if((temp->tm_hour < str_time->tm_hour || (temp->tm_hour == str_time->tm_hour && temp->tm_min < str_time->tm_min))) str_time->tm_mday += 1; } else if(str_time->tm_hour > 20) str_time->tm_mday += 1; } break; case 'n': { } break; default: break; } } if(temp->tm_hour >= 0) str_time->tm_hour = temp->tm_hour; if(temp->tm_min >= 0) str_time->tm_min = temp->tm_min; if(temp->tm_sec >= 0) str_time->tm_sec = temp->tm_sec; change[6] = 0; change[5] = 0; for(int i=0; i<7; i++){ *timePointer[i] += change[i]; } tempTime = mktime(str_time); str_time= localtime(&tempTime); temp->tm_sec = -1; temp->tm_min = -1; temp->tm_hour = -1; temp->tm_mday = -1; temp->tm_wday = -1; temp->tm_mon = -1; temp->tm_year = -1; amount[0] = 0; amount[1] = 0; amount[2] = 0; for(int i=0; i< 9; i++) { change[i] = 0; } time_t finalTime = mktime(str_time); str_time= localtime(&finalTime); }
static void initRtcTime(RtcTime * self) { FirstSetYearAndDayOfYear(self); ThenSetMonthAndDayOfMonth(self); setDayOfWeek(self); }