aboutsummaryrefslogtreecommitdiff
path: root/coreutils/touch.c
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2021-09-16 10:26:14 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2021-09-17 00:11:30 +0200
commit9fe1548bbfde548d54acaab113656a56ea0ccc72 (patch)
treebabe79b4f502417ca91a8fab3099f29ff718de19 /coreutils/touch.c
parent83e20cb81ca6d22a1ca268a0a64523b5af67325a (diff)
downloadbusybox-w32-9fe1548bbfde548d54acaab113656a56ea0ccc72.tar.gz
busybox-w32-9fe1548bbfde548d54acaab113656a56ea0ccc72.tar.bz2
busybox-w32-9fe1548bbfde548d54acaab113656a56ea0ccc72.zip
date,touch: allow timezone offsets in dates
Allow ISO 8601 style dates to include a timezone offset. Like the '@' format these dates aren't relative to the user's current timezone and shouldn't be subject to DST adjustment. - The implementation uses the strptime() '%z' format specifier. This an extension which may not be available so the use of timezones is a configuration option. - The 'touch' applet has been updated to respect whether DST adjustment is required, matching 'date'. function old new delta parse_datestr 624 730 +106 static.fmt_str 106 136 +30 touch_main 388 392 +4 date_main 818 819 +1 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 4/0 up/down: 141/0) Total: 141 bytes Signed-off-by: Ron Yorston <rmy@pobox.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'coreutils/touch.c')
-rw-r--r--coreutils/touch.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/coreutils/touch.c b/coreutils/touch.c
index 78100ba1d..7e13a27be 100644
--- a/coreutils/touch.c
+++ b/coreutils/touch.c
@@ -140,15 +140,17 @@ int touch_main(int argc UNUSED_PARAM, char **argv)
140 if (opts & (OPT_d|OPT_t)) { 140 if (opts & (OPT_d|OPT_t)) {
141 struct tm tm_time; 141 struct tm tm_time;
142 time_t t; 142 time_t t;
143 int check_dst;
143 144
144 //memset(&tm_time, 0, sizeof(tm_time)); 145 //memset(&tm_time, 0, sizeof(tm_time));
145 /* Better than memset: makes "HH:MM" dates meaningful */ 146 /* Better than memset: makes "HH:MM" dates meaningful */
146 time(&t); 147 time(&t);
147 localtime_r(&t, &tm_time); 148 localtime_r(&t, &tm_time);
148 parse_datestr(date_str, &tm_time); 149 check_dst = parse_datestr(date_str, &tm_time);
149 150
150 /* Correct any day of week and day of year etc. fields */ 151 /* Correct any day of week and day of year etc. fields */
151 tm_time.tm_isdst = -1; /* Be sure to recheck dst */ 152 if (check_dst)
153 tm_time.tm_isdst = -1; /* recheck dst unless date is UTC */
152 t = validate_tm_time(date_str, &tm_time); 154 t = validate_tm_time(date_str, &tm_time);
153 155
154 timebuf[1].tv_sec = timebuf[0].tv_sec = t; 156 timebuf[1].tv_sec = timebuf[0].tv_sec = t;