Correct time initialization for the case where time is initialized from settings in the .config file. The correct range for month (tm_mon) internally is 0-11, not 1-12 as it is in the .config file.

This commit is contained in:
Gregory Nutt 2016-10-27 08:36:24 -06:00
parent 0967864c92
commit 123c520db4
3 changed files with 14 additions and 32 deletions

View File

@ -44,26 +44,6 @@
#include <nuttx/time.h> #include <nuttx/time.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Private Type Declarations
****************************************************************************/
/****************************************************************************
* Private Function Prototypes
****************************************************************************/
/****************************************************************************
* Public Constant Data
****************************************************************************/
/****************************************************************************
* Public Data
****************************************************************************/
/**************************************************************************** /****************************************************************************
* Private Data * Private Data
****************************************************************************/ ****************************************************************************/
@ -73,10 +53,6 @@ static const uint16_t g_daysbeforemonth[13] =
0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365
}; };
/****************************************************************************
* Private Functions
****************************************************************************/
/**************************************************************************** /****************************************************************************
* Public Functions * Public Functions
****************************************************************************/ ****************************************************************************/
@ -85,7 +61,16 @@ static const uint16_t g_daysbeforemonth[13] =
* Function: clock_daysbeforemonth * Function: clock_daysbeforemonth
* *
* Description: * Description:
* Get the number of days that occurred before the beginning of the month. * Get the number of days that occurred before the beginning of the
* month.
*
* Input Parameters:
* month - The month in the form of tm_mon, that is a range of 0-11.
* leapyear - True if leap year and there are 29 days in February.
* NOTE the month=1 is February.
*
* Returned Value:
* The number of days that occurred before the month
* *
****************************************************************************/ ****************************************************************************/
@ -96,6 +81,7 @@ int clock_daysbeforemonth(int month, bool leapyear)
{ {
retval++; retval++;
} }
return retval; return retval;
} }

View File

@ -54,10 +54,6 @@
#define SEC_PER_HOUR ((time_t)60 * SEC_PER_MIN) #define SEC_PER_HOUR ((time_t)60 * SEC_PER_MIN)
#define SEC_PER_DAY ((time_t)24 * SEC_PER_HOUR) #define SEC_PER_DAY ((time_t)24 * SEC_PER_HOUR)
/****************************************************************************
* Private Type Declarations
****************************************************************************/
/**************************************************************************** /****************************************************************************
* Private Function Prototypes * Private Function Prototypes
****************************************************************************/ ****************************************************************************/
@ -90,8 +86,7 @@ static void clock_utc2julian(time_t jdn, int *year, int *month, int *day);
****************************************************************************/ ****************************************************************************/
/**************************************************************************** /****************************************************************************
* Function: clock_calendar2utc, clock_gregorian2utc, * Function: clock_utc2calendar, clock_utc2gregorian, and clock_utc2julian
* and clock_julian2utc
* *
* Description: * Description:
* Calendar to UTC conversion routines. These conversions * Calendar to UTC conversion routines. These conversions

View File

@ -61,6 +61,7 @@
/**************************************************************************** /****************************************************************************
* Pre-processor Definitions * Pre-processor Definitions
****************************************************************************/ ****************************************************************************/
/* Standard time definitions (in units of seconds) */ /* Standard time definitions (in units of seconds) */
#define SEC_PER_MIN ((time_t)60) #define SEC_PER_MIN ((time_t)60)
@ -151,7 +152,7 @@ static inline int clock_basetime(FAR struct timespec *tp)
* month, and date * month, and date
*/ */
jdn = clock_calendar2utc(CONFIG_START_YEAR, CONFIG_START_MONTH, jdn = clock_calendar2utc(CONFIG_START_YEAR, CONFIG_START_MONTH - 1,
CONFIG_START_DAY); CONFIG_START_DAY);
/* Set the base time as seconds into this julian day. */ /* Set the base time as seconds into this julian day. */