From b93f5908e2f0932620e5120fb52a942fa5573cf9 Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Tue, 1 Jun 2021 15:59:08 -0700 Subject: date: add -s. Used by someone's script. --- toys/posix/date.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/toys/posix/date.c b/toys/posix/date.c index 86c2d343..99a41695 100644 --- a/toys/posix/date.c +++ b/toys/posix/date.c @@ -7,7 +7,7 @@ * Note: setting a 2 year date is 50 years back/forward from today, * not posix's hardwired magic dates. -USE_DATE(NEWTOY(date, "d:D:I(iso)(iso-8601):;r:u(utc)[!dr]", TOYFLAG_BIN)) +USE_DATE(NEWTOY(date, "d:D:I(iso)(iso-8601):;r:s:u(utc)[!dr]", TOYFLAG_BIN)) config DATE bool "date" @@ -21,6 +21,7 @@ config DATE -D +FORMAT for SET or -d (instead of MMDDhhmm[[CC]YY][.ss]) -I RES ISO 8601 with RESolution d=date/h=hours/m=minutes/s=seconds/n=ns -r Use modification time of FILE instead of current date + -s DATE Set the system clock to DATE. -u Use UTC instead of current timezone Supported input formats: @@ -59,7 +60,7 @@ config DATE #include "toys.h" GLOBALS( - char *r, *I, *D, *d; + char *s, *r, *I, *D, *d; unsigned nano; ) @@ -170,6 +171,11 @@ void date_main(void) TT.nano = ts.tv_nsec; } + if (FLAG(s)) { + if (setdate) help_exit("can't set two dates at once"); + setdate = TT.s; + } + // Fall through if no arguments if (!setdate); // Display the date? -- cgit v1.2.3