mirror of
https://gitee.com/Vancouver2017/luban-lite-t3e-pro.git
synced 2025-12-16 19:38:56 +00:00
first commit
This commit is contained in:
@@ -54,6 +54,52 @@
|
||||
* EXTERNAL FUNCTIONS
|
||||
*/
|
||||
|
||||
|
||||
int isLeapYear(int year)
|
||||
{
|
||||
return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);
|
||||
}
|
||||
|
||||
|
||||
int daysInMonth(int year, int month)
|
||||
{
|
||||
if (month == 2)
|
||||
{
|
||||
return isLeapYear(year) ? 29 : 28;
|
||||
}
|
||||
else if (month == 4 || month == 6 || month == 9 || month == 11)
|
||||
{
|
||||
return 30;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 31;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
long dateToEpoch(int year, int month, int day, int hour, int minute, int second)
|
||||
{
|
||||
int days = 0;
|
||||
|
||||
for (int y = 1970; y < year; y++)
|
||||
{
|
||||
days += isLeapYear(y) ? 366 : 365;
|
||||
}
|
||||
|
||||
for (int m = 1; m < month; m++)
|
||||
{
|
||||
days += daysInMonth(year, m);
|
||||
}
|
||||
|
||||
days += day - 1;
|
||||
|
||||
long seconds = days * 86400 + hour * 3600 + minute * 60 + second;
|
||||
|
||||
return seconds;
|
||||
|
||||
|
||||
}
|
||||
/*********************************************************************
|
||||
* LOCAL VARIABLES
|
||||
*/
|
||||
|
||||
@@ -132,7 +132,7 @@ typedef struct
|
||||
* tm - pointer to UTC time struct
|
||||
*/
|
||||
extern UTCTime esp32_ConvertUTCSecs( UTCTimeStruct *tm );
|
||||
|
||||
extern long dateToEpoch(int year, int month, int day, int hour, int minute, int second);
|
||||
/*
|
||||
* Update/Adjust the esp32 clock and timers
|
||||
* Msec - elapsed time in milli seconds
|
||||
|
||||
Reference in New Issue
Block a user