From cc4be69e76709579c80efcc24801004461011c46 Mon Sep 17 00:00:00 2001
From: yy1717 <fctom1215@outlook.com>
Date: 星期二, 14 一月 2020 11:17:09 +0800
Subject: [PATCH] s

---
 lib/src/main/cpp/utils/xconvert.cpp |   48 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 48 insertions(+), 0 deletions(-)

diff --git a/lib/src/main/cpp/utils/xconvert.cpp b/lib/src/main/cpp/utils/xconvert.cpp
index 713260b..62aeca2 100644
--- a/lib/src/main/cpp/utils/xconvert.cpp
+++ b/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;
+}

--
Gitblit v1.8.0