| 
									
										
										
										
											2011-05-23 19:00:31 +01:00
										 |  |  | /* See LICENSE file for copyright and license details. */ | 
					
						
							|  |  |  | #include <stdio.h>
 | 
					
						
							|  |  |  | #include <stdlib.h>
 | 
					
						
							|  |  |  | #include <time.h>
 | 
					
						
							| 
									
										
										
										
											2014-11-13 18:29:30 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-23 19:00:31 +01:00
										 |  |  | #include "util.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-14 20:20:47 +02:00
										 |  |  | static void | 
					
						
							|  |  |  | usage(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	eprintf("usage: %s [-u] [-d format] [+FORMAT]\n", argv0); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-23 19:00:31 +01:00
										 |  |  | int | 
					
						
							|  |  |  | main(int argc, char *argv[]) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2013-06-14 20:20:47 +02:00
										 |  |  | 	char buf[BUFSIZ]; | 
					
						
							| 
									
										
										
										
											2011-06-10 05:41:40 +01:00
										 |  |  | 	char *fmt = "%c"; | 
					
						
							| 
									
										
										
										
											2011-05-23 19:00:31 +01:00
										 |  |  | 	struct tm *now = NULL; | 
					
						
							| 
									
										
										
										
											2012-04-23 08:32:24 -07:00
										 |  |  | 	struct tm *(*tztime)(const time_t *) = localtime; | 
					
						
							|  |  |  | 	const char *tz = "local"; | 
					
						
							| 
									
										
										
										
											2011-05-23 19:00:31 +01:00
										 |  |  | 	time_t t; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	t = time(NULL); | 
					
						
							| 
									
										
										
										
											2013-06-14 20:20:47 +02:00
										 |  |  | 	ARGBEGIN { | 
					
						
							|  |  |  | 	case 'd': | 
					
						
							| 
									
										
										
										
											2015-02-08 23:45:03 +00:00
										 |  |  | 		t = estrtonum(EARGF(usage()), 0, LLONG_MAX); | 
					
						
							| 
									
										
										
										
											2013-06-14 20:20:47 +02:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	case 'u': | 
					
						
							|  |  |  | 		tztime = gmtime; | 
					
						
							|  |  |  | 		tz = "gm"; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	default: | 
					
						
							|  |  |  | 		usage(); | 
					
						
							|  |  |  | 	} ARGEND; | 
					
						
							| 
									
										
										
										
											2015-01-23 22:54:25 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-13 18:29:30 +01:00
										 |  |  | 	if (argc > 0 && argv[0][0] == '+') | 
					
						
							| 
									
										
										
										
											2013-06-14 20:20:47 +02:00
										 |  |  | 		fmt = &argv[0][1]; | 
					
						
							| 
									
										
										
										
											2014-11-13 18:29:30 +01:00
										 |  |  | 	if (!(now = tztime(&t))) | 
					
						
							| 
									
										
										
										
											2012-04-23 08:32:24 -07:00
										 |  |  | 		eprintf("%stime failed\n", tz); | 
					
						
							| 
									
										
										
										
											2011-05-23 19:00:31 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-23 22:54:25 +01:00
										 |  |  | 	strftime(buf, sizeof(buf), fmt, now); | 
					
						
							| 
									
										
										
										
											2011-05-23 19:00:31 +01:00
										 |  |  | 	puts(buf); | 
					
						
							| 
									
										
										
										
											2013-06-14 20:20:47 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-10-02 23:46:04 +01:00
										 |  |  | 	return 0; | 
					
						
							| 
									
										
										
										
											2011-05-23 19:00:31 +01:00
										 |  |  | } |