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

[mynewt-core] branch master updated: use timezone for clocktime_to_timeval

This is an automated email from the ASF dual-hosted git repository.

utzig pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git


The following commit(s) were added to refs/heads/master by this push:
     new 16240ee  use timezone for clocktime_to_timeval
16240ee is described below

commit 16240eead3488267239578e29318fa430d36018a
Author: Stephane D'Alu <sd...@sdalu.com>
AuthorDate: Thu Mar 15 22:01:22 2018 +0100

    use timezone for clocktime_to_timeval
---
 time/datetime/include/datetime/datetime.h |  2 +-
 time/datetime/src/datetime.c              | 13 ++++++++-----
 2 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/time/datetime/include/datetime/datetime.h b/time/datetime/include/datetime/datetime.h
index c6de1c1..2fc08fb 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 82ee9dc..5661506 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);

-- 
To stop receiving notification emails like this one, please contact
utzig@apache.org.