diff options
author | Dominik Riebeling <Dominik.Riebeling@gmail.com> | 2013-06-09 17:18:14 +0200 |
---|---|---|
committer | Dominik Riebeling <Dominik.Riebeling@gmail.com> | 2013-06-09 19:51:08 +0200 |
commit | 9574b300666acfdef3e364d87bdea4bdcf4832e0 (patch) | |
tree | 466e3b61549cb440c6e2153d0a89cbceb2d58fe8 /utils | |
parent | 11280e20cc8164f4dc9cbb66f66086e9950c03c6 (diff) | |
download | rockbox-9574b300666acfdef3e364d87bdea4bdcf4832e0.tar.gz rockbox-9574b300666acfdef3e364d87bdea4bdcf4832e0.zip |
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
Diffstat (limited to 'utils')
-rw-r--r-- | utils/time-sync/time-sync.c | 24 |
1 files changed, 19 insertions, 5 deletions
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 <stdlib.h> #include <stdio.h> #include <time.h> @@ -27,14 +28,27 @@ int main (int argc, char **argv) { if (argc < 2) { - printf ("usage: %s <device>\n", basename(argv[0])); - return 1; + printf ("usage: %s <device> [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; |