summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDominik Riebeling <Dominik.Riebeling@gmail.com>2013-06-09 17:18:14 +0200
committerDominik Riebeling <Dominik.Riebeling@gmail.com>2013-06-09 19:51:08 +0200
commit9574b300666acfdef3e364d87bdea4bdcf4832e0 (patch)
tree466e3b61549cb440c6e2153d0a89cbceb2d58fe8
parent11280e20cc8164f4dc9cbb66f66086e9950c03c6 (diff)
downloadrockbox-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
-rw-r--r--utils/time-sync/time-sync.c24
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 @@
16 * 16 *
17 */ 17 */
18 18
19#define _XOPEN_SOURCE /* to enable strptime() */
19#include <stdlib.h> 20#include <stdlib.h>
20#include <stdio.h> 21#include <stdio.h>
21#include <time.h> 22#include <time.h>
@@ -27,14 +28,27 @@ int
27main (int argc, char **argv) 28main (int argc, char **argv)
28{ 29{
29 if (argc < 2) { 30 if (argc < 2) {
30 printf ("usage: %s <device>\n", basename(argv[0])); 31 printf ("usage: %s <device> [time]\n", basename(argv[0]));
31 return 1; 32 return 1;
32 } 33 }
33 34
34 if (sync_time (argv[1], NULL)) { 35 struct tm time;
35 printf ("Error occured while syncing time.\n"); 36 struct tm* ptime = NULL;
37 if (argc > 2) {
38 if(strptime(argv[2], "%Y-%m-%dT%H:%M:%S", &time)) {
39 ptime = &time;
40 }
41 else {
42 printf ("Could not parse time. Using local time.\n");
43 printf ("Time string needs to use the format YYYY-MM-DDThh:mm:ss\n");
44 printf ("(ISO 8601 format)\n");
45 }
46 }
47
48 if (sync_time (argv[1], ptime)) {
49 printf ("Error occured while syncing time.\n");
36 } else { 50 } else {
37 printf ("Time was synced!\n"); 51 printf ("Time was synced!\n");
38 } 52 }
39 53
40 return 0; 54 return 0;