You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by GitBox <gi...@apache.org> on 2018/03/21 18:12:59 UTC

[GitHub] utzig closed pull request #928: datetime: use timezone for clocktime_to_timeval

utzig closed pull request #928: datetime: use timezone for clocktime_to_timeval
URL: https://github.com/apache/mynewt-core/pull/928
 
 
   

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 c6de1c1f8..2fc08fb18 100644
--- a/time/datetime/include/datetime/datetime.h
+++ b/time/datetime/include/datetime/datetime.h
@@ -68,7 +68,7 @@ int datetime_parse(const char *input, struct os_timeval *utctime,
  *
  * Returns 0 on success and OS_EINVAL on invalid input data
  */
-int clocktime_to_timeval(const struct clocktime *ct, struct os_timeval *tv);
+int clocktime_to_timeval(const struct clocktime *ct, const struct os_timezone *tz, struct os_timeval *tv);
 
 /*
  * Converts from struct os_timeval to struct clocktime
diff --git a/time/datetime/src/datetime.c b/time/datetime/src/datetime.c
index 82ee9dc5d..5661506e8 100644
--- a/time/datetime/src/datetime.c
+++ b/time/datetime/src/datetime.c
@@ -106,7 +106,7 @@ leapyear(int year)
 }
 
 int
-clocktime_to_timeval(const struct clocktime *ct, struct os_timeval *tv)
+clocktime_to_timeval(const struct clocktime *ct, const struct os_timezone *tz, struct os_timeval *tv)
 {
     int i, year, days;
 
@@ -140,6 +140,12 @@ clocktime_to_timeval(const struct clocktime *ct, struct os_timeval *tv)
         ct->sec;
     tv->tv_usec = ct->usec;
 
+    /* Convert localtime to utctime */
+    if (tz != NULL) {
+	tv->tv_sec += tz->tz_minuteswest * 60;
+	tv->tv_sec -= tz->tz_dsttime ? 3600 : 0;
+    }
+    
     return (0);
 }
 
@@ -340,13 +346,10 @@ datetime_parse(const char *input, struct os_timeval *tv, struct os_timezone *tz)
         goto err;
     }
 
-    if (clocktime_to_timeval(&ct, tv) != 0) {
+    if (clocktime_to_timeval(&ct, tz, tv) != 0) {
         goto err;
     }
 
-    /* Convert localtime to utctime */
-    tv->tv_sec += tz->tz_minuteswest * 60;
-    tv->tv_sec -= tz->tz_dsttime ? 3600 : 0;
     return (0);
 err:
     return (-1);


 

----------------------------------------------------------------
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