From 9574b300666acfdef3e364d87bdea4bdcf4832e0 Mon Sep 17 00:00:00 2001 From: Dominik Riebeling Date: Sun, 9 Jun 2013 17:18:14 +0200 Subject: time-sync: allow passing an arbitrary time. During testing it can be useful to set an arbitrary (non-current) time on the device. Extend time-sync to accept an additional (optional) parameter with the time to set. Only changes date / time, no timezone. Change-Id: Ib320777cb245cff19ca00b20540db3a43a4e488f --- utils/time-sync/time-sync.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) (limited to 'utils/time-sync/time-sync.c') diff --git a/utils/time-sync/time-sync.c b/utils/time-sync/time-sync.c index ebb46ed2fc..ed4ef3ce42 100644 --- a/utils/time-sync/time-sync.c +++ b/utils/time-sync/time-sync.c @@ -16,6 +16,7 @@ * */ +#define _XOPEN_SOURCE /* to enable strptime() */ #include #include #include @@ -27,14 +28,27 @@ int main (int argc, char **argv) { if (argc < 2) { - printf ("usage: %s \n", basename(argv[0])); - return 1; + printf ("usage: %s [time]\n", basename(argv[0])); + return 1; } - if (sync_time (argv[1], NULL)) { - printf ("Error occured while syncing time.\n"); + struct tm time; + struct tm* ptime = NULL; + if (argc > 2) { + if(strptime(argv[2], "%Y-%m-%dT%H:%M:%S", &time)) { + ptime = &time; + } + else { + printf ("Could not parse time. Using local time.\n"); + printf ("Time string needs to use the format YYYY-MM-DDThh:mm:ss\n"); + printf ("(ISO 8601 format)\n"); + } + } + + if (sync_time (argv[1], ptime)) { + printf ("Error occured while syncing time.\n"); } else { - printf ("Time was synced!\n"); + printf ("Time was synced!\n"); } return 0; -- cgit v1.2.3