From commits-return-16997-archive-asf-public=cust-asf.ponee.io@mynewt.apache.org Wed Mar 14 09:35:01 2018 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id 9C783180654 for ; Wed, 14 Mar 2018 09:35:00 +0100 (CET) Received: (qmail 74380 invoked by uid 500); 14 Mar 2018 08:34:59 -0000 Mailing-List: contact commits-help@mynewt.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@mynewt.apache.org Delivered-To: mailing list commits@mynewt.apache.org Received: (qmail 74367 invoked by uid 99); 14 Mar 2018 08:34:58 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 14 Mar 2018 08:34:58 +0000 From: GitBox To: commits@mynewt.apache.org Subject: [GitHub] mkiiskila closed pull request #915: Expose timeval <-> clocktime conversion functions from time/datetime library Message-ID: <152101649841.4335.825450308466968370.gitbox@gitbox.apache.org> Date: Wed, 14 Mar 2018 08:34:58 -0000 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit 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 +#include #include #include #include #include -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