s
yy1717
2020-01-14 cc4be69e76709579c80efcc24801004461011c46
lib/src/main/cpp/utils/xconvert.cpp
@@ -6,6 +6,18 @@
#include <cstdint>
#include <cstring>
#define SECONDS_PER_MINUTE  60
#define SECONDS_PER_HOUR    3600
#define SECONDS_PER_DAY     (86400L)
#define MINUTES_PER_HOUR    60
#define MINUTES_PER_DAY     1440
#define HOURS_PER_DAY       24
#define DAYS_PER_WEEK       7
#define DAYS_PER_YEAR       365
void ConvertPhoneNum(uint8_t *dst, int length, const char *src)
{
    int p = length - 1;
@@ -59,3 +71,39 @@
        }
    }
}
const int LibTimeDays[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
static inline bool TimeYearIsLeap(int year)
{
    if ((year % 4) || year == 2100)
        return false;
    else
        return true;
}
uint32_t TimeMakeComposite(int year, int month, int day, int hour, int minute, int second)
{
    int i;
    uint32_t totalSeconds;
    int daysThisYear;
    totalSeconds = second;
    totalSeconds += minute*SECONDS_PER_MINUTE;
    totalSeconds += hour*SECONDS_PER_HOUR;
    daysThisYear = day - 1;
    if (TimeYearIsLeap(year) && month>2)
        daysThisYear += 1;
    for (i = 0; i<(month - 1); i++)
        daysThisYear += (int)LibTimeDays[i];
    for (i = 2000; i<year; i++) {
        daysThisYear += 365;
        if (TimeYearIsLeap(i))
            daysThisYear += 1;
    }
    totalSeconds += daysThisYear * SECONDS_PER_DAY;
    return totalSeconds;
}