Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added default values to TimeElements #185

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
cmake_minimum_required(VERSION 3.24)
idf_component_register(
SRCS "Time.cpp" # Add all source files here
INCLUDE_DIRS "./"
REQUIRES "arduino" # Add include directories here
)
12 changes: 10 additions & 2 deletions Time.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,14 +208,16 @@ time_t makeTime(const tmElements_t &tm){

int i;
uint32_t seconds;

// Serial.println("start");
// seconds from 1970 till 1 jan 00:00:00 of the given year
seconds= tm.Year*(SECS_PER_DAY * 365);
// Serial.println(seconds);
for (i = 0; i < tm.Year; i++) {
if (LEAP_YEAR(i)) {
seconds += SECS_PER_DAY; // add extra days for leap years
}
}
// Serial.println(seconds);

// add days for this year, months start from 1
for (i = 1; i < tm.Month; i++) {
Expand All @@ -225,10 +227,16 @@ time_t makeTime(const tmElements_t &tm){
seconds += SECS_PER_DAY * monthDays[i-1]; //monthDay array starts from 0
}
}
seconds+= (tm.Day-1) * SECS_PER_DAY;
// Serial.println(seconds);
seconds+= (tm.Day!=0?(tm.Day-1):0) * SECS_PER_DAY;
// Serial.println(seconds);
seconds+= tm.Hour * SECS_PER_HOUR;
// Serial.println(seconds);
seconds+= tm.Minute * SECS_PER_MIN;
// Serial.println(seconds);
seconds+= tm.Second;
// Serial.println(seconds);
// Serial.println("end");
return (time_t)seconds;
}
/*=====================================================*/
Expand Down