mynewt-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] mkiiskila closed pull request #915: Expose timeval <-> clocktime conversion functions from time/datetime library
Date Wed, 14 Mar 2018 08:34:58 GMT
mkiiskila closed pull request #915: Expose timeval <-> clocktime conversion functions
from time/datetime library
URL: https://github.com/apache/mynewt-core/pull/915
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/time/datetime/include/datetime/datetime.h b/time/datetime/include/datetime/datetime.h
index 664ee8ef4..c6de1c1f8 100644
--- a/time/datetime/include/datetime/datetime.h
+++ b/time/datetime/include/datetime/datetime.h
@@ -28,6 +28,17 @@ struct os_timezone;
 
 #define DATETIME_BUFSIZE    33
 
+struct clocktime {
+    int year;   /* year (4 digit year) */
+    int mon;    /* month (1 - 12) */
+    int day;    /* day (1 - 31) */
+    int hour;   /* hour (0 - 23) */
+    int min;    /* minute (0 - 59) */
+    int sec;    /* second (0 - 59) */
+    int dow;    /* day of week (0 - 6; 0 = Sunday) */
+    int usec;   /* micro seconds */
+};
+
 /*
  * Format the time specified by 'utctime' and 'tz' as per RFC 3339 in
  * the 'output' string. The size of the buffer pointed to by 'output'
@@ -51,6 +62,22 @@ int datetime_format(const struct os_timeval *utctime,
 int datetime_parse(const char *input, struct os_timeval *utctime,
     struct os_timezone *tz);
 
+
+/*
+ * Converts from struct clocktime to struct os_timeval
+ *
+ * Returns 0 on success and OS_EINVAL on invalid input data
+ */
+int clocktime_to_timeval(const struct clocktime *ct, struct os_timeval *tv);
+
+/*
+ * Converts from struct os_timeval to struct clocktime
+ *
+ * Returns 0 on success and OS_EINVAL on invalid input data
+ */
+int timeval_to_clocktime(const struct os_timeval *tv, const struct os_timezone *tz,
+    struct clocktime *ct);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/time/datetime/src/datetime.c b/time/datetime/src/datetime.c
index 31a3641e4..82ee9dc5d 100644
--- a/time/datetime/src/datetime.c
+++ b/time/datetime/src/datetime.c
@@ -58,23 +58,13 @@
  */
 
 #include <os/os_time.h>
+#include <os/os_error.h>
 
 #include <stdio.h>
 #include <ctype.h>
 #include <string.h>
 #include <datetime/datetime.h>
 
-struct clocktime {
-    int year;   /* year (4 digit year) */
-    int mon;    /* month (1 - 12) */
-    int day;    /* day (1 - 31) */
-    int hour;   /* hour (0 - 23) */
-    int min;    /* minute (0 - 59) */
-    int sec;    /* second (0 - 59) */
-    int dow;    /* day of week (0 - 6; 0 = Sunday) */
-    int usec;   /* micro seconds */
-};
-
 #define days_in_year(y)     (leapyear(y) ? 366 : 365)
 
 #define    FEBRUARY    2
@@ -115,7 +105,7 @@ leapyear(int year)
     return (rv);
 }
 
-static int
+int
 clocktime_to_timeval(const struct clocktime *ct, struct os_timeval *tv)
 {
     int i, year, days;
@@ -130,7 +120,7 @@ clocktime_to_timeval(const struct clocktime *ct, struct os_timeval *tv)
         ct->min < 0 || ct->min > 59 ||
         ct->sec < 0 || ct->sec > 59 ||
         ct->usec < 0 || ct->usec > 999999) {
-        return (-1);
+        return (OS_EINVAL);
     }
 
     /*
@@ -153,7 +143,7 @@ clocktime_to_timeval(const struct clocktime *ct, struct os_timeval *tv)
     return (0);
 }
 
-static int
+int
 timeval_to_clocktime(const struct os_timeval *tv, const struct os_timezone *tz,
     struct clocktime *ct)
 {
@@ -169,7 +159,7 @@ timeval_to_clocktime(const struct os_timeval *tv, const struct os_timezone
*tz,
     }
 
     if (secs < 0 || tv->tv_usec < 0 || tv->tv_usec > 999999) {
-        return (-1);
+        return (OS_EINVAL);
     }
 
     days = secs / SECDAY;


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message