From c7c34eef065cafe99c5675e6349724c17be81ff7 Mon Sep 17 00:00:00 2001 From: "jc_.kim" Date: Tue, 7 Feb 2017 14:49:03 +0900 Subject: [PATCH] For supporting day of week and year in time structure. This allows integration with 3rd party libraries that expect the tm struct to contain these members. Merge code related to CONFIG_TIME_EXTENDED from Nuttx 7.19 Change-Id: I00c37c1175cb6eaaacbfb8d0d738760c924dfe71 --- lib/libc/Kconfig | 5 ++ lib/libc/time/Make.defs | 7 +++ lib/libc/time/lib_asctime.c | 90 ++++++++++++++++++++++++++++++ lib/libc/time/lib_asctimer.c | 109 ++++++++++++++++++++++++++++++++++++ lib/libc/time/lib_ctime.c | 99 +++++++++++++++++++++++++++++++++ lib/libc/time/lib_ctimer.c | 100 +++++++++++++++++++++++++++++++++ lib/libc/time/lib_dayofweek.c | 125 ++++++++++++++++++++++++++++++++++++++++++ lib/libc/time/lib_gmtimer.c | 6 ++ lib/libc/time/lib_strftime.c | 31 ++++++++++- os/include/time.h | 28 +++++++++- os/include/tinyara/time.h | 21 +++++++ 11 files changed, 619 insertions(+), 2 deletions(-) create mode 100644 lib/libc/time/lib_asctime.c create mode 100644 lib/libc/time/lib_asctimer.c create mode 100644 lib/libc/time/lib_ctime.c create mode 100644 lib/libc/time/lib_ctimer.c create mode 100644 lib/libc/time/lib_dayofweek.c diff --git a/lib/libc/Kconfig b/lib/libc/Kconfig index fe94dc3..3caa4a7 100644 --- a/lib/libc/Kconfig +++ b/lib/libc/Kconfig @@ -206,6 +206,11 @@ config LIBC_LOCALTIME ---help--- localtime API call support +config TIME_EXTENDED + bool "enable time extended" + default "n" + depends on !LIBC_LOCALTIME + if LIBC_LOCALTIME config LIBC_TZ_MAX_TIMES diff --git a/lib/libc/time/Make.defs b/lib/libc/time/Make.defs index cc2a805..55adb1b 100644 --- a/lib/libc/time/Make.defs +++ b/lib/libc/time/Make.defs @@ -59,6 +59,13 @@ ifdef CONFIG_ENABLE_IOTIVITY CSRCS +=lib_strptime.c endif +ifdef CONFIG_LIBC_LOCALTIME +CSRCS +=lib_asctime.c lib_asctimer.c lib_ctime.c lib_ctimer.c +else +ifdef CONFIG_TIME_EXTENDED +CSRCS +=lib_asctime.c lib_asctimer.c lib_ctime.c lib_ctimer.c lib_dayofweek.c +endif +endif ifdef CONFIG_LIBC_LOCALTIME CSRCS += lib_localtime.c diff --git a/lib/libc/time/lib_asctime.c b/lib/libc/time/lib_asctime.c new file mode 100644 index 0000000..d31aa02 --- /dev/null +++ b/lib/libc/time/lib_asctime.c @@ -0,0 +1,90 @@ +/**************************************************************************** + * + * Copyright 2016 Samsung Electronics All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the License. + * + ****************************************************************************/ +/**************************************************************************** + * libc/time/lib_asctime.c + * + * Copyright (C) 2015 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include + +#if defined(CONFIG_LIBC_LOCALTIME) || defined(CONFIG_TIME_EXTENDED) + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Function: asctime + * + * Description: + * asctime and asctime_r convert the time provided in a struct tm to a + * string representation. asctime is not re-entrant; asctime_r is re- + * entrant + * + * Parameters: + * tp - Pointer to the time to be converted. + * + * Return Value: + * One success a pointer to the string is returned; on failure, NULL is + * returned. + * + ****************************************************************************/ + +FAR char *asctime(FAR const struct tm *tp) +{ + static char buf[26]; + return asctime_r(tp, buf); +} + +#endif /* CONFIG_LIBC_LOCALTIME || CONFIG_TIME_EXTENDED */ diff --git a/lib/libc/time/lib_asctimer.c b/lib/libc/time/lib_asctimer.c new file mode 100644 index 0000000..4d0d4a8 --- /dev/null +++ b/lib/libc/time/lib_asctimer.c @@ -0,0 +1,109 @@ +/**************************************************************************** + * + * Copyright 2016 Samsung Electronics All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the License. + * + ****************************************************************************/ +/**************************************************************************** + * libc/time/lib_asctimer.c + * + * Copyright (C) 2015 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#if defined(CONFIG_LIBC_LOCALTIME) || defined(CONFIG_TIME_EXTENDED) + +/**************************************************************************** + * Private Data + ****************************************************************************/ +/* Note: These strings duplicate other definitions in other files. These + * definitions could be combined to save a little FLASH space. + */ + +static const char *const g_wday_name[7] = { + "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" +}; + +static const char *const g_mon_name[12] = { + "Jan", "Feb", "Mar", "Apr", "May", "Jun", + "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" +}; + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Function: asctime_r + * + * Description: + * asctime and asctime_r convert the time provided in a struct tm to a + * string representation. asctime is not re-entrant; asctime_r is re- + * entrant. + * + * Parameters: + * tp - Pointer to the time to be converted. + * buf - A user provided buffer to receive the 26 character time string. + * + * Return Value: + * One success, the pointer to the 'buf' is returned; on failure, NULL is + * returned. + * + ****************************************************************************/ + +FAR char *asctime_r(FAR const struct tm *tp, FAR char *buf) +{ + snprintf(buf, 26, "%.3s %.3s%3d %.2d:%.2d:%.2d %d\n", g_wday_name[tp->tm_wday], g_mon_name[tp->tm_mon], tp->tm_mday, tp->tm_hour, tp->tm_min, tp->tm_sec, 1900 + tp->tm_year); + + return buf; +} + +#endif /* CONFIG_LIBC_LOCALTIME || CONFIG_TIME_EXTENDED */ diff --git a/lib/libc/time/lib_ctime.c b/lib/libc/time/lib_ctime.c new file mode 100644 index 0000000..48da1e0 --- /dev/null +++ b/lib/libc/time/lib_ctime.c @@ -0,0 +1,99 @@ +/**************************************************************************** + * + * Copyright 2016 Samsung Electronics All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the License. + * + ****************************************************************************/ +/**************************************************************************** + * libc/time/lib_ctime.c + * + * Copyright (C) 2015 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include + +#if defined(CONFIG_LIBC_LOCALTIME) || defined(CONFIG_TIME_EXTENDED) + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Function: ctime + * + * Description: + * ctime and ctime_r convert the time provided in seconds since the + * epoch to a string representation. ctime is not re-entrant; ctime_r is + * re-entrant. + * + * Parameters: + * timep - The current time represented as seconds since the epoch. + * + * Return Value: + * One success a pointer to the string is returned; on failure, NULL is + * returned. + * + ****************************************************************************/ + +FAR char *ctime(FAR const time_t *timep) +{ +#ifdef CONFIG_LIBC_LOCALTIME + /* Section 4.12.3.2 of X3.159-1989 requires that + * The ctime function converts the calendar time pointed to by timer + * to local time in the form of a string. It is equivalent to + * asctime(localtime(timer)) + */ + + return asctime(localtime(timep)); +#else + return asctime(gmtime(timep)); +#endif +} + +#endif /* CONFIG_LIBC_LOCALTIME || CONFIG_TIME_EXTENDED */ diff --git a/lib/libc/time/lib_ctimer.c b/lib/libc/time/lib_ctimer.c new file mode 100644 index 0000000..de8cc75 --- /dev/null +++ b/lib/libc/time/lib_ctimer.c @@ -0,0 +1,100 @@ +/**************************************************************************** + * + * Copyright 2016 Samsung Electronics All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the License. + * + ****************************************************************************/ +/**************************************************************************** + * libc/time/lib_ctimer.c + * + * Copyright (C) 2015 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include + +#if defined(CONFIG_LIBC_LOCALTIME) || defined(CONFIG_TIME_EXTENDED) + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Function: ctime_r + * + * Description: + * ctime and ctime_r convert the time provided in seconds since the + * epoch to a string representation. ctime is not re-entrant; ctime_r is + * re-entrant. + * + * Parameters: + * timep - The current time represented as seconds since the epoch. + * buf - A user provided buffer to receive the 26 character time string. + * + * Return Value: + * One success, the pointer to the 'buf' is returned; on failure, NULL is + * returned. + * + ****************************************************************************/ + +FAR char *ctime_r(FAR const time_t *timep, FAR char *buf) +{ + struct tm tm; + +#ifdef CONFIG_LIBC_LOCALTIME + return asctime_r(localtime_r(timep, &tm), buf); +#else + return asctime_r(gmtime_r(timep, &tm), buf); +#endif +} + +#endif /* CONFIG_LIBC_LOCALTIME || CONFIG_TIME_EXTENDED */ diff --git a/lib/libc/time/lib_dayofweek.c b/lib/libc/time/lib_dayofweek.c new file mode 100644 index 0000000..ff3a513 --- /dev/null +++ b/lib/libc/time/lib_dayofweek.c @@ -0,0 +1,125 @@ +/**************************************************************************** + * + * Copyright 2016 Samsung Electronics All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the License. + * + ****************************************************************************/ +/**************************************************************************** + * libc/time/lib_dayofweek.c + * + * Copyright (C) 2015 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * David Sidrane + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +#include + +#if defined(CONFIG_TIME_EXTENDED) + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Type Declarations + ****************************************************************************/ + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Public Constant Data + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Function: clock_dayoftheweek + * + * Description: + * Get the day of the week + * + * Input Parameters: + * mday - The day of the month 1 - 31 + * month - The month of the year 1 - 12 + * year - the year including the 1900 + * + * Returned value: + * Zero based day of the week 0-6, 0 = Sunday, 1 = Monday... 6 = Saturday + * + ****************************************************************************/ + +int clock_dayoftheweek(int mday, int month, int year) +{ + if (month <= 2) { + year--; + month += 12; + } + + month -= 2; + return (mday + year + year / 4 - year / 100 + year / 400 + (31 * month) / 12) % 7; +} +#endif /* CONFIG_TIME_EXTENDED */ diff --git a/lib/libc/time/lib_gmtimer.c b/lib/libc/time/lib_gmtimer.c index 9e34e29..966bc21 100644 --- a/lib/libc/time/lib_gmtimer.c +++ b/lib/libc/time/lib_gmtimer.c @@ -363,5 +363,11 @@ FAR struct tm *gmtime_r(FAR const time_t *timer, FAR struct tm *result) result->tm_min = (int)min; result->tm_sec = (int)sec; +#if defined(CONFIG_TIME_EXTENDED) + result->tm_wday = clock_dayoftheweek(day, month, year); + result->tm_yday = day + clock_daysbeforemonth(result->tm_mon, clock_isleapyear(year)); + result->tm_isdst = 0; +#endif + return result; } diff --git a/lib/libc/time/lib_strftime.c b/lib/libc/time/lib_strftime.c index fc642d6..4246d80 100644 --- a/lib/libc/time/lib_strftime.c +++ b/lib/libc/time/lib_strftime.c @@ -86,6 +86,15 @@ /**************************************************************************** * Private Data ****************************************************************************/ +#if defined(CONFIG_LIBC_LOCALTIME) || defined(CONFIG_TIME_EXTENDED) +static const char *const g_abbrev_wdayname[7] = { + "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" +}; + +static const char *const g_wdayname[7] = { + "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" +}; +#endif static const char *const g_abbrevmonthname[12] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", @@ -180,6 +189,26 @@ size_t strftime(FAR char *s, size_t max, FAR const char *format, FAR const struc len = 0; switch (*format++) { +#if defined(CONFIG_LIBC_LOCALTIME) || defined(CONFIG_TIME_EXTENDED) + /* %a: A three-letter abbreviation for the day of the week. */ + + case 'a': { + if (tm->tm_wday < 7) { + str = g_abbrev_wdayname[tm->tm_wday]; + len = snprintf(dest, chleft, "%s", str); + } + } + break; + + /* %A: The full name for the day of the week. */ + case 'A': { + if (tm->tm_wday < 7) { + str = g_wdayname[tm->tm_wday]; + len = snprintf(dest, chleft, "%s", str); + } + } + break; +#else /* %a: A three-letter abbreviation for the day of the week. */ /* %A: The full name for the day of the week. */ @@ -188,7 +217,7 @@ size_t strftime(FAR char *s, size_t max, FAR const char *format, FAR const struc len = snprintf(dest, chleft, "Day"); /* Not supported */ } break; - +#endif /* %h: Equivalent to %b */ case 'h': diff --git a/os/include/time.h b/os/include/time.h index d836fd0..130e94d 100644 --- a/os/include/time.h +++ b/os/include/time.h @@ -171,7 +171,7 @@ struct tm { int tm_mday; /* day of the month (1-31) */ int tm_mon; /* month (0-11) */ int tm_year; /* years since 1900 */ -#ifdef CONFIG_LIBC_LOCALTIME +#if defined(CONFIG_LIBC_LOCALTIME) || defined(CONFIG_TIME_EXTENDED) int tm_wday; /* day of the week (0-6) */ int tm_yday; /* day of the year (0-365) */ int tm_isdst; /* non-0 if daylight savings time is in effect */ @@ -273,6 +273,32 @@ FAR struct tm *localtime_r(FAR const time_t *timer, FAR struct tm *result); */ size_t strftime(char *s, size_t max, FAR const char *format, FAR const struct tm *tm); +/** + * @cond + * @internal + */ +#if defined(CONFIG_LIBC_LOCALTIME) || defined(CONFIG_TIME_EXTENDED) +/** + * @internal + */ +FAR char *asctime(FAR const struct tm *tp); +/** + * @internal + */ +FAR char *asctime_r(FAR const struct tm *tp, FAR char *buf); +/** + * @internal + */ +FAR char *ctime(FAR const time_t *timep); +/** + * @internal + */ +FAR char *ctime_r(FAR const time_t *timep, FAR char *buf); +#endif +/** + * @endcond + */ + #ifdef CONFIG_ENABLE_IOTIVITY /** * @cond diff --git a/os/include/tinyara/time.h b/os/include/tinyara/time.h index 93bf490..31c3a24 100644 --- a/os/include/tinyara/time.h +++ b/os/include/tinyara/time.h @@ -117,6 +117,27 @@ EXTERN int clock_isleapyear(int year); EXTERN int clock_daysbeforemonth(int month, bool leapyear); /** + * @cond + * @internal + */ +/** + * @ingroup TIME_KERNEL + * @todo + * @brief Get the day of the week + * @param[in] The day of the month 1 - 31 + * @param[in] The month of the year 1 - 12 + * @param[in] the year including the 1900 + * @return Zero based day of the week 0-6, 0 = Sunday, 1 = Monday... 6 = Saturday + * @since Tizen RT v1.0 + */ +#if defined(CONFIG_TIME_EXTENDED) +int clock_dayoftheweek(int mday, int month, int year); +#endif +/** + * @endcond + */ + +/** * @ingroup TIME_KERNEL * @brief Conversion Calendar/UTC * @details based on algorithms from p. 604 -- 2.7.4