diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2011-01-02 20:02:09 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2011-01-02 20:02:09 +0100 |
commit | 92ffe0571a49077f06fc65bf0ada753b30fd8a53 (patch) | |
tree | 706e3cd2aeb23ddfece91b6f9612e272070d3e44 /libbb | |
parent | a5d3d3436b16bf6e1a92ed969e171ac812e8f906 (diff) | |
download | busybox-w32-92ffe0571a49077f06fc65bf0ada753b30fd8a53.tar.gz busybox-w32-92ffe0571a49077f06fc65bf0ada753b30fd8a53.tar.bz2 busybox-w32-92ffe0571a49077f06fc65bf0ada753b30fd8a53.zip |
date,touch: treat 2-digit years better (fit them into +-50 yrs around today)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'libbb')
-rw-r--r-- | libbb/time.c | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/libbb/time.c b/libbb/time.c index 2a74d34c2..1eb2d75c2 100644 --- a/libbb/time.c +++ b/libbb/time.c | |||
@@ -93,6 +93,7 @@ void FAST_FUNC parse_datestr(const char *date_str, struct tm *ptm) | |||
93 | * | 93 | * |
94 | * This coincides with the format of "touch -t TIME" | 94 | * This coincides with the format of "touch -t TIME" |
95 | */ | 95 | */ |
96 | unsigned cur_year = ptm->tm_year; | ||
96 | int len = strchrnul(date_str, '.') - date_str; | 97 | int len = strchrnul(date_str, '.') - date_str; |
97 | 98 | ||
98 | /* MM[.SS] */ | 99 | /* MM[.SS] */ |
@@ -133,6 +134,17 @@ void FAST_FUNC parse_datestr(const char *date_str, struct tm *ptm) | |||
133 | &end) >= 5) { | 134 | &end) >= 5) { |
134 | /* Adjust month from 1-12 to 0-11 */ | 135 | /* Adjust month from 1-12 to 0-11 */ |
135 | ptm->tm_mon -= 1; | 136 | ptm->tm_mon -= 1; |
137 | if ((int)cur_year >= 50) { /* >= 1950 */ | ||
138 | /* Adjust year: */ | ||
139 | /* 1. Put it in the current century */ | ||
140 | ptm->tm_year += (cur_year / 100) * 100; | ||
141 | /* 2. If too far in the past, +100 years */ | ||
142 | if (ptm->tm_year < cur_year - 50) | ||
143 | ptm->tm_year += 100; | ||
144 | /* 3. If too far in the future, -100 years */ | ||
145 | if (ptm->tm_year > cur_year + 50) | ||
146 | ptm->tm_year -= 100; | ||
147 | } | ||
136 | } else | 148 | } else |
137 | /* ccyymmddHHMM[.SS] */ | 149 | /* ccyymmddHHMM[.SS] */ |
138 | if (len == 12 && sscanf(date_str, "%4u%2u%2u%2u%2u%c", | 150 | if (len == 12 && sscanf(date_str, "%4u%2u%2u%2u%2u%c", |