2 Copyright © 2013 Alastair Stuart
4 This program is open source software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
20 #define VERSION "0.01"
27 char string
[128+1] = {'\0'};
28 char* format
= "%a %b %d %X %Z %Y";
30 int main(int argc
, char* argv
[])
37 for (arg
= 1; arg
< argc
; arg
++)
39 if (strcmp("--iso", argv
[arg
]) == 0 || strcmp("-I", argv
[arg
]) == 0) {
41 } else if (strcmp("--utc", argv
[arg
]) == 0 || strcmp("-u", argv
[arg
]) == 0) {
43 } else if (strcmp("--help", argv
[arg
]) == 0 || strcmp("-h", argv
[arg
]) == 0) {
44 printf("Usage: %s [options ...] [+format]\n", argv
[0]);
46 " -I, --iso Print time in ISO 8601 format.\n"
47 " -u, --utc Print time in UTC instead of localtime.\n"
49 " -h, --help Print this message.\n"
50 " -v, --version Show version info.\n");
52 } else if (strcmp("--version", argv
[arg
]) == 0 || strcmp("-v", argv
[arg
]) == 0) {
53 printf("date (mutos) v"VERSION
"\n");
61 if ((argc
- arg
) > 1) {
62 fprintf(stderr
, "%s: too many arguments\n",
65 } else if ((argc
- arg
) == 1) {
66 if (argv
[arg
][0] != '+') {
67 fprintf(stderr
, "%s: invalid format\n",
70 } else if (flags
.iso
){
71 fprintf(stderr
, "%s: multiple formats given\n",
75 format
= argv
[arg
] + 1;
79 time_t curr_time
= time(NULL
);
80 struct tm
*now
= NULL
;
82 now
= gmtime(&curr_time
);
84 now
= localtime(&curr_time
);
88 format
= "%Y-%m-%dT%X%z";
91 strftime(string
, 128, format
, now
);
93 printf("%s\n", string
);