From 25f42dd0767c084121e311d9c0ec25b8b3023e57 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 3 Jun 2019 11:18:17 -0600 Subject: [PATCH] libs/libc/time/: Costmetic changes to make gmtime() and gmtimer() follow the coding standard more closely. --- libs/libc/time/lib_gmtime.c | 28 ---------- libs/libc/time/lib_gmtimer.c | 100 +++++++++++++++++++---------------- 2 files changed, 55 insertions(+), 73 deletions(-) diff --git a/libs/libc/time/lib_gmtime.c b/libs/libc/time/lib_gmtime.c index e4b0351488..600b27b26d 100644 --- a/libs/libc/time/lib_gmtime.c +++ b/libs/libc/time/lib_gmtime.c @@ -45,34 +45,6 @@ #include -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Private Type Declarations - ****************************************************************************/ - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Public Constant Data - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - /**************************************************************************** * Public Functions ****************************************************************************/ diff --git a/libs/libc/time/lib_gmtimer.c b/libs/libc/time/lib_gmtimer.c index d892baca79..67925ed9da 100644 --- a/libs/libc/time/lib_gmtimer.c +++ b/libs/libc/time/lib_gmtimer.c @@ -1,7 +1,8 @@ /**************************************************************************** * libs/libc/time/lib_gmtimer.c * - * Copyright (C) 2007, 2009, 2011, 2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2007, 2009, 2011, 2015, 2019 Gregory Nutt. All rights + * reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -60,27 +61,17 @@ /* Calendar/UTC conversion routines */ -static void clock_utc2calendar(time_t utc, int *year, int *month, int *day); +static void clock_utc2calendar(time_t utc, FAR int *year, FAR int *month, + FAR int *day); #ifdef CONFIG_GREGORIAN_TIME -static void clock_utc2gregorian (time_t jdn, int *year, int *month, int *day); - +static void clock_utc2gregorian(time_t jdn, FAR int *year, FAR int *month, + FAR int *day); #ifdef CONFIG_JULIAN_TIME -static void clock_utc2julian(time_t jdn, int *year, int *month, int *day); +static void clock_utc2julian(time_t jdn, FAR int *year, FAR int *month, + FAR int *day); #endif /* CONFIG_JULIAN_TIME */ #endif /* CONFIG_GREGORIAN_TIME */ -/**************************************************************************** - * Public Constant Data - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/**************************************************************************** - * Private Data - ****************************************************************************/ - /**************************************************************************** * Private Functions ****************************************************************************/ @@ -97,7 +88,8 @@ static void clock_utc2julian(time_t jdn, int *year, int *month, int *day); ****************************************************************************/ #ifdef CONFIG_GREGORIAN_TIME -static void clock_utc2calendar(time_t utc, int *year, int *month, int *day) +static void clock_utc2calendar(time_t utc, FAR int *year, FAR int *month, + FAR int *day) { #ifdef CONFIG_JULIAN_TIME @@ -117,20 +109,27 @@ static void clock_utc2calendar(time_t utc, int *year, int *month, int *day) #endif /* CONFIG_JULIAN_TIME */ } -static void clock_utc2gregorian(time_t jd, int *year, int *month, int *day) +static void clock_utc2gregorian(time_t jd, FAR int *year, FAR int *month, + FAR int *day) { - long l, n, i, j, d, m, y; + long l; + long n; + long i; + long j; + long d; + long m; + long y; l = jd + 68569; - n = (4*l) / 146097; - l = l - (146097*n + 3)/4; - i = (4000*(l+1))/1461001; - l = l - (1461*i)/4 + 31; - j = (80*l)/2447; - d = l - (2447*j)/80; - l = j/11; - m = j + 2 - 12*l; - y = 100*(n-49) + i + l; + n = (4 * l) / 146097; + l = l - (146097 * n + 3)/4; + i = (4000 * (l + 1)) / 1461001; + l = l - (1461 * i) / 4 + 31; + j = (80 * l) / 2447; + d = l - (2447 * j) / 80; + l = j / 11; + m = j + 2 - 12 * l; + y = 100 * (n - 49) + i + l; *year = y; *month = m; @@ -139,20 +138,28 @@ static void clock_utc2gregorian(time_t jd, int *year, int *month, int *day) #ifdef CONFIG_JULIAN_TIME -static void clock_utc2julian(time_t jd, int *year, int *month, int *day) +static void clock_utc2julian(time_t jd, FAR int *year, FAR int *month, + FAR int *day) { - long j, k, l, n, d, i, m, y; + long j; + long k; + long l; + long n; + long d; + long i; + long m; + long y; j = jd + 1402; - k = (j-1)/1461; - l = j - 1461*k; - n = (l-1)/365 - l/1461; - i = l - 365*n + 30; - j = (80*i)/2447; - d = i - (2447*j)/80; - i = j/11; - m = j + 2 - 12*i; - y = 4*k + n + i - 4716; + k = (j - 1) / 1461; + l = j - 1461 * k; + n = (l - 1) / 365 - l / 1461; + i = l - 365 * n + 30; + j = (80 * i) / 2447; + d = i - (2447 * j)/80; + i = j / 11; + m = j + 2 - 12 * i; + y = 4 * k + n + i - 4716; *year = y; *month = m; @@ -210,7 +217,9 @@ static void clock_utc2calendar(time_t days, FAR int *year, FAR int *month, } } - /* At this point, value has the year and days has number days into this year */ + /* At this point, value has the year and days has number days into this + * year + */ *year = 1970 + value; @@ -225,8 +234,8 @@ static void clock_utc2calendar(time_t days, FAR int *year, FAR int *month, value = (min + max) >> 1; - /* Get the number of days that occurred before the beginning of the month - * following the midpoint. + /* Get the number of days that occurred before the beginning of the + * month following the midpoint. */ tmp = clock_daysbeforemonth(value + 1, leapyear); @@ -348,10 +357,11 @@ FAR struct tm *gmtime_r(FAR const time_t *timer, FAR struct tm *result) #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_yday = day + + clock_daysbeforemonth(result->tm_mon, + clock_isleapyear(year)); result->tm_isdst = 0; #endif return result; } -