diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2011-09-01 17:56:03 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2011-09-01 17:56:03 +0000 |
commit | 12ede7f8e242f87c62ad3e7739d6a6452be813a1 (patch) | |
tree | a09a716fb96e2a520a6d35bb9603b4eb14bd208c /nuttx/lib | |
parent | 0c65db21d1bdc2ca3419f947288e08033f890662 (diff) | |
download | px4-nuttx-12ede7f8e242f87c62ad3e7739d6a6452be813a1.tar.gz px4-nuttx-12ede7f8e242f87c62ad3e7739d6a6452be813a1.tar.bz2 px4-nuttx-12ede7f8e242f87c62ad3e7739d6a6452be813a1.zip |
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
Diffstat (limited to 'nuttx/lib')
-rw-r--r-- | nuttx/lib/time/lib_gmtimer.c | 20 | ||||
-rw-r--r-- | nuttx/lib/time/lib_mktime.c | 2 |
2 files changed, 14 insertions, 8 deletions
diff --git a/nuttx/lib/time/lib_gmtimer.c b/nuttx/lib/time/lib_gmtimer.c index b410a74f2..082bd8cf8 100644 --- a/nuttx/lib/time/lib_gmtimer.c +++ b/nuttx/lib/time/lib_gmtimer.c @@ -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) */ - leapyear = clock_isleapyear(value + 1900); + leapyear = clock_isleapyear(value + 1970); /* 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? */ - if (tmp >= days) + if (tmp > days) { /* Yes.. then the month we want is somewhere from 'min' and to the * midpoint, 'value'. Could it be the midpoint? */ tmp = clock_daysbeforemonth(value, leapyear); - if (tmp >= days) + if (tmp > days) { /* 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; } + + /* 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); - /* 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 */ - 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 * number of days into this month (zero based) */ - *month = min + 1; /* 1-based */ - *day = days + 1; /* 1-based */ + *month = value + 1; /* 1-based */ + *day = days + 1; /* 1-based */ } #endif /* CONFIG_GREGORIAN_TIME */ diff --git a/nuttx/lib/time/lib_mktime.c b/nuttx/lib/time/lib_mktime.c index f0168aa6b..2e8cfc119 100644 --- a/nuttx/lib/time/lib_mktime.c +++ b/nuttx/lib/time/lib_mktime.c @@ -109,7 +109,7 @@ time_t mktime(const struct tm *tp) #else /* 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. */ |