2
* Copyright (C) 2005 Andrew Beekhof <andrew@beekhof.net>
4
* This program is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU General Public
6
* License as published by the Free Software Foundation; either
7
* version 2.1 of the License, or (at your option) any later version.
9
* This software 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 GNU
12
* General Public License for more details.
14
* You should have received a copy of the GNU General Public
15
* License along with this library; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
#include <lha_internal.h>
20
#include <crm/common/iso8601.h>
22
#define OPTARGS "V?d:p:D:WOLn"
29
fprintf(stderr, "Usage: iso8601 [-(O|W|L)] -(n|d|p|D) <string> \n");
30
fprintf(stderr, "Input Options:\n");
31
fprintf(stderr, "\t-n Display the current date/time\n");
32
fprintf(stderr, "\t-d Parse an ISO8601 date/time. Eg. '2005-01-20 00:30:00 +01:00' or '2005-040'\n");
33
fprintf(stderr, "\t-p Parse an ISO8601 date/time interval/period (wth start time). Eg. '2005-040/2005-043'\n");
34
fprintf(stderr, "\t-D Parse an ISO8601 date/time duration (wth start time). Eg. '2005-040/P1M'\n");
35
fprintf(stderr, "\nOutput Options:\n");
36
fprintf(stderr, "\tBy default, shows the result in 'universal' date/time\n");
37
fprintf(stderr, "\t-L Show result as a 'local' date/time\n");
38
fprintf(stderr, "\t-O Show result as an 'ordinal' date/time\n");
39
fprintf(stderr, "\t-W Show result as an 'calendar week' date/time\n");
40
fprintf(stderr, "\nFor more information on the ISO8601 standard, see: http://en.wikipedia.org/wiki/ISO_8601\n");
45
main(int argc, char **argv)
49
int print_options = 0;
51
char *mutable_s = NULL;
53
crm_log_init("iso8601", LOG_INFO, FALSE, TRUE, 0, NULL);
60
flag = getopt(argc, argv, OPTARGS);
66
cl_log_enable_stderr(TRUE);
67
alter_debug(DEBUG_INC);
79
input_s = crm_strdup(optarg);
82
print_options |= ha_date_weeks;
85
print_options |= ha_date_ordinal;
88
print_options |= ha_log_local;
93
if(input_s == NULL && command != 'n') {
100
ha_time_t *date_time = parse_date(&mutable_s);
101
if(date_time == NULL) {
102
fprintf(stderr, "Invalid date/time specified: %s\n", input_s);
105
log_date(LOG_INFO, "parsed", date_time,
106
print_options|ha_log_date|ha_log_time);
108
} else if(command == 'p') {
109
ha_time_period_t *interval = parse_time_period(&mutable_s);
110
if(interval == NULL) {
111
fprintf(stderr, "Invalid interval specified: %s\n", input_s);
114
log_time_period(LOG_INFO, interval,
115
print_options|ha_log_date|ha_log_time);
117
} else if(command == 'D') {
118
ha_time_t *duration = parse_time_duration(&mutable_s);
119
if(duration == NULL) {
120
fprintf(stderr, "Invalid duration specified: %s\n", input_s);
123
log_date(LOG_INFO, "Duration", duration,
124
print_options|ha_log_date|ha_log_time|ha_log_local);
126
} else if(command == 'n') {
127
ha_time_t *now = new_ha_date(TRUE);
129
fprintf(stderr, "Internal error: couldnt determin 'now' !\n");
132
log_date(LOG_INFO, "Current date/time", now,
133
print_options|ha_log_date|ha_log_time);