mirror of
https://github.com/apache/nuttx.git
synced 2026-05-30 05:16:47 +08:00
Fix errors in gmtime and gmtime_r
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3933 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
@@ -2049,3 +2049,5 @@
|
|||||||
crashes on Cortex-M3 if the ARM libgcc is used, for example. The fix
|
crashes on Cortex-M3 if the ARM libgcc is used, for example. The fix
|
||||||
is to include ARCHCPUFLAGS on the gcc command line when asking it to
|
is to include ARCHCPUFLAGS on the gcc command line when asking it to
|
||||||
-print-libgcc-file-name.
|
-print-libgcc-file-name.
|
||||||
|
* lib/time/lib_gmtimer.c: Correct several calculations that could lead
|
||||||
|
to errors in dates.
|
||||||
|
|||||||
+101
-63
File diff suppressed because it is too large
Load Diff
+13
-7
@@ -191,7 +191,7 @@ static void clock_utc2calendar(time_t days, int *year, int *month, int *day)
|
|||||||
{
|
{
|
||||||
/* Is this year a leap year (we'll need this later too) */
|
/* Is this year a leap year (we'll need this later too) */
|
||||||
|
|
||||||
leapyear = clock_isleapyear(value + 1900);
|
leapyear = clock_isleapyear(value + 1970);
|
||||||
|
|
||||||
/* Get the number of days in the year */
|
/* Get the number of days in the year */
|
||||||
|
|
||||||
@@ -239,14 +239,14 @@ static void clock_utc2calendar(time_t days, int *year, int *month, int *day)
|
|||||||
* number of days we have remaining?
|
* number of days we have remaining?
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (tmp >= days)
|
if (tmp > days)
|
||||||
{
|
{
|
||||||
/* Yes.. then the month we want is somewhere from 'min' and to the
|
/* Yes.. then the month we want is somewhere from 'min' and to the
|
||||||
* midpoint, 'value'. Could it be the midpoint?
|
* midpoint, 'value'. Could it be the midpoint?
|
||||||
*/
|
*/
|
||||||
|
|
||||||
tmp = clock_daysbeforemonth(value, leapyear);
|
tmp = clock_daysbeforemonth(value, leapyear);
|
||||||
if (tmp >= days)
|
if (tmp > days)
|
||||||
{
|
{
|
||||||
/* No... The one we want is somewhere between min and value-1 */
|
/* No... The one we want is somewhere between min and value-1 */
|
||||||
|
|
||||||
@@ -265,21 +265,27 @@ static void clock_utc2calendar(time_t days, int *year, int *month, int *day)
|
|||||||
|
|
||||||
min = value + 1;
|
min = value + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* If we break out of the loop because min == max, then we want value
|
||||||
|
* to be equal to min == max.
|
||||||
|
*/
|
||||||
|
|
||||||
|
value = min;
|
||||||
}
|
}
|
||||||
while (min < max);
|
while (min < max);
|
||||||
|
|
||||||
/* The selected month number is in min (and max). Subtract the number of days in the
|
/* The selected month number is in value. Subtract the number of days in the
|
||||||
* selected month
|
* selected month
|
||||||
*/
|
*/
|
||||||
|
|
||||||
days -= clock_daysbeforemonth(min, leapyear);
|
days -= clock_daysbeforemonth(value, leapyear);
|
||||||
|
|
||||||
/* At this point, value has the month into this year (zero based) and days has
|
/* At this point, value has the month into this year (zero based) and days has
|
||||||
* number of days into this month (zero based)
|
* number of days into this month (zero based)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
*month = min + 1; /* 1-based */
|
*month = value + 1; /* 1-based */
|
||||||
*day = days + 1; /* 1-based */
|
*day = days + 1; /* 1-based */
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* CONFIG_GREGORIAN_TIME */
|
#endif /* CONFIG_GREGORIAN_TIME */
|
||||||
|
|||||||
@@ -109,7 +109,7 @@ time_t mktime(const struct tm *tp)
|
|||||||
#else
|
#else
|
||||||
|
|
||||||
/* Simple version that only works for dates within a (relatively) small range
|
/* Simple version that only works for dates within a (relatively) small range
|
||||||
* from the epoch. It does not handle earlier days on longer days where leap
|
* from the epoch. It does not handle earlier days or longer days where leap
|
||||||
* seconds, etc. apply.
|
* seconds, etc. apply.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user