Modified for BG96

Fork of mbed-dev by mbed official

Revision:
187:0387e8f68319
Parent:
184:08ed48f1de7f
--- a/platform/mbed_mktime.c	Fri Jun 22 16:45:37 2018 +0100
+++ b/platform/mbed_mktime.c	Thu Sep 06 13:40:20 2018 +0100
@@ -20,7 +20,7 @@
 #define SECONDS_BY_MINUTES 60
 #define MINUTES_BY_HOUR 60
 #define SECONDS_BY_HOUR (SECONDS_BY_MINUTES * MINUTES_BY_HOUR)
-#define HOURS_BY_DAY 24 
+#define HOURS_BY_DAY 24
 #define SECONDS_BY_DAY (SECONDS_BY_HOUR * HOURS_BY_DAY)
 #define LAST_VALID_YEAR 206
 
@@ -29,48 +29,49 @@
 #define EDGE_TIMESTAMP_4_YEAR_LEAP_YEAR_SUPPORT 3133695  // 6th of February 1970 at 06:28:15
 
 /*
- * 2 dimensional array containing the number of seconds elapsed before a given 
+ * 2 dimensional array containing the number of seconds elapsed before a given
  * month.
  * The second index map to the month while the first map to the type of year:
- *   - 0: non leap year 
+ *   - 0: non leap year
  *   - 1: leap year
  */
 static const uint32_t seconds_before_month[2][12] = {
     {
         0,
         31 * SECONDS_BY_DAY,
-        (31 + 28) * SECONDS_BY_DAY,
-        (31 + 28 + 31) * SECONDS_BY_DAY,
-        (31 + 28 + 31 + 30) * SECONDS_BY_DAY,
-        (31 + 28 + 31 + 30 + 31) * SECONDS_BY_DAY,
-        (31 + 28 + 31 + 30 + 31 + 30) * SECONDS_BY_DAY,
-        (31 + 28 + 31 + 30 + 31 + 30 + 31) * SECONDS_BY_DAY,
-        (31 + 28 + 31 + 30 + 31 + 30 + 31 + 31) * SECONDS_BY_DAY,
-        (31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30) * SECONDS_BY_DAY,
-        (31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31) * SECONDS_BY_DAY,
-        (31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30) * SECONDS_BY_DAY,
+        (31 + 28) *SECONDS_BY_DAY,
+        (31 + 28 + 31) *SECONDS_BY_DAY,
+        (31 + 28 + 31 + 30) *SECONDS_BY_DAY,
+        (31 + 28 + 31 + 30 + 31) *SECONDS_BY_DAY,
+        (31 + 28 + 31 + 30 + 31 + 30) *SECONDS_BY_DAY,
+        (31 + 28 + 31 + 30 + 31 + 30 + 31) *SECONDS_BY_DAY,
+        (31 + 28 + 31 + 30 + 31 + 30 + 31 + 31) *SECONDS_BY_DAY,
+        (31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30) *SECONDS_BY_DAY,
+        (31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31) *SECONDS_BY_DAY,
+        (31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30) *SECONDS_BY_DAY,
     },
     {
         0,
         31 * SECONDS_BY_DAY,
-        (31 + 29) * SECONDS_BY_DAY,
-        (31 + 29 + 31) * SECONDS_BY_DAY,
-        (31 + 29 + 31 + 30) * SECONDS_BY_DAY,
-        (31 + 29 + 31 + 30 + 31) * SECONDS_BY_DAY,
-        (31 + 29 + 31 + 30 + 31 + 30) * SECONDS_BY_DAY,
-        (31 + 29 + 31 + 30 + 31 + 30 + 31) * SECONDS_BY_DAY,
-        (31 + 29 + 31 + 30 + 31 + 30 + 31 + 31) * SECONDS_BY_DAY,
-        (31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30) * SECONDS_BY_DAY,
-        (31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31) * SECONDS_BY_DAY,
-        (31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30) * SECONDS_BY_DAY,
+        (31 + 29) *SECONDS_BY_DAY,
+        (31 + 29 + 31) *SECONDS_BY_DAY,
+        (31 + 29 + 31 + 30) *SECONDS_BY_DAY,
+        (31 + 29 + 31 + 30 + 31) *SECONDS_BY_DAY,
+        (31 + 29 + 31 + 30 + 31 + 30) *SECONDS_BY_DAY,
+        (31 + 29 + 31 + 30 + 31 + 30 + 31) *SECONDS_BY_DAY,
+        (31 + 29 + 31 + 30 + 31 + 30 + 31 + 31) *SECONDS_BY_DAY,
+        (31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30) *SECONDS_BY_DAY,
+        (31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31) *SECONDS_BY_DAY,
+        (31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30) *SECONDS_BY_DAY,
     }
 };
 
-bool _rtc_is_leap_year(int year, rtc_leap_year_support_t leap_year_support) {
-    /* 
-     * since in practice, the value manipulated by this algorithm lie in the 
+bool _rtc_is_leap_year(int year, rtc_leap_year_support_t leap_year_support)
+{
+    /*
+     * since in practice, the value manipulated by this algorithm lie in the
      * range: [70 : 206] the algorithm can be reduced to: year % 4 with exception for 200 (year 2100 is not leap year).
-     * The algorithm valid over the full range of value is: 
+     * The algorithm valid over the full range of value is:
 
         year = 1900 + year;
         if (year % 4) {
@@ -82,7 +83,7 @@
         }
         return true;
 
-     */ 
+     */
     if (leap_year_support == RTC_FULL_LEAP_YEAR_SUPPORT && year == 200) {
         return false; // 2100 is not a leap year
     }
@@ -90,7 +91,8 @@
     return (year) % 4 ? false : true;
 }
 
-bool _rtc_maketime(const struct tm* time, time_t * seconds, rtc_leap_year_support_t leap_year_support) {
+bool _rtc_maketime(const struct tm *time, time_t *seconds, rtc_leap_year_support_t leap_year_support)
+{
     if (seconds == NULL || time == NULL) {
         return false;
     }
@@ -111,12 +113,12 @@
     /* Check if we are within valid range. */
     if (time->tm_year == LAST_VALID_YEAR) {
         if ((leap_year_support == RTC_FULL_LEAP_YEAR_SUPPORT && result > EDGE_TIMESTAMP_FULL_LEAP_YEAR_SUPPORT) ||
-            (leap_year_support == RTC_4_YEAR_LEAP_YEAR_SUPPORT && result > EDGE_TIMESTAMP_4_YEAR_LEAP_YEAR_SUPPORT)) {
-        return false;
+                (leap_year_support == RTC_4_YEAR_LEAP_YEAR_SUPPORT && result > EDGE_TIMESTAMP_4_YEAR_LEAP_YEAR_SUPPORT)) {
+            return false;
         }
     }
 
-    if (time->tm_year > 70) { 
+    if (time->tm_year > 70) {
         /* Valid in the range [70:206]. */
         uint32_t count_of_leap_days = ((time->tm_year - 1) / 4) - (70 / 4);
         if (leap_year_support == RTC_FULL_LEAP_YEAR_SUPPORT) {
@@ -133,7 +135,8 @@
     return true;
 }
 
-bool _rtc_localtime(time_t timestamp, struct tm* time_info, rtc_leap_year_support_t leap_year_support) {
+bool _rtc_localtime(time_t timestamp, struct tm *time_info, rtc_leap_year_support_t leap_year_support)
+{
     if (time_info == NULL) {
         return false;
     }
@@ -154,7 +157,7 @@
 
     /* Years start at 70. */
     time_info->tm_year = 70;
-    while (true) { 
+    while (true) {
         if (_rtc_is_leap_year(time_info->tm_year, leap_year_support) && seconds >= 366) {
             ++time_info->tm_year;
             seconds -= 366;