[PATCH] date: fix incorrect year in dates of the form [[[MM]DD]hh]mm
Denys Vlasenko
vda.linux at googlemail.com
Tue Jan 21 06:59:56 UTC 2014
Thanks for the report!
I applied with a slightly different fix.
The fix will go into 1.22.2 too.
On Mon, Jan 20, 2014 at 9:53 PM, Ron Yorston <rmy at tigress.co.uk> wrote:
> Since commit 688a7e3f dates of the form [[[MM]DD]hh]mm have the
> wrong year:
>
> $ ./busybox date -d 10101010
> Fri Oct 10 10:10:00 GMT 10102910
>
> Signed-off-by: Ron Yorston <rmy at tigress.co.uk>
> ---
> libbb/time.c | 7 ++++---
> 1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/libbb/time.c b/libbb/time.c
> index ea2f72e..5aa5aeb 100644
> --- a/libbb/time.c
> +++ b/libbb/time.c
> @@ -12,6 +12,7 @@ void FAST_FUNC parse_datestr(const char *date_str, struct tm *ptm)
> {
> char end = '\0';
> const char *last_colon = strrchr(date_str, ':');
> + unsigned year;
>
> if (last_colon != NULL) {
> /* Parse input and assign appropriately to ptm */
> @@ -69,16 +70,16 @@ void FAST_FUNC parse_datestr(const char *date_str, struct tm *ptm)
> }
> } else
> /* yyyy-mm-dd HH */
> - if (sscanf(date_str, "%u-%u-%u %u%c", &ptm->tm_year,
> + if (sscanf(date_str, "%u-%u-%u %u%c", &year,
> &ptm->tm_mon, &ptm->tm_mday,
> &ptm->tm_hour,
> &end) >= 4
> /* yyyy-mm-dd */
> - || sscanf(date_str, "%u-%u-%u%c", &ptm->tm_year,
> + || sscanf(date_str, "%u-%u-%u%c", &year,
> &ptm->tm_mon, &ptm->tm_mday,
> &end) >= 3
> ) {
> - ptm->tm_year -= 1900; /* Adjust years */
> + ptm->tm_year = year - 1900; /* Adjust years */
> ptm->tm_mon -= 1; /* Adjust month from 1-12 to 0-11 */
> } else
> if (date_str[0] == '@') {
> --
> 1.8.4.2
>
> _______________________________________________
> busybox mailing list
> busybox at busybox.net
> http://lists.busybox.net/mailman/listinfo/busybox
More information about the busybox
mailing list