2 ======================================================================
4 CREATOR: eric 02 June 2000
9 (C) COPYRIGHT 2000, Eric Busboom, http://www.softwarestudio.org
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of either:
14 The LGPL as published by the Free Software Foundation, version
15 2.1, available at: http://www.fsf.org/copyleft/lesser.html
19 The Mozilla Public License Version 1.0. You may obtain a copy of
20 the License at http://www.mozilla.org/MPL/
22 The Original Code is eric. The Initial Developer of the Original
26 ======================================================================*/
32 #include "icalperiod.h"
39 #ifdef ICAL_NO_LIBICAL
40 #define icalerror_set_errno(x)
41 #define icalerror_check_arg_rv(x,y)
42 #define icalerror_check_arg_re(x,y,z)
44 #include "icalerror.h"
45 #include "icalmemory.h"
51 struct icalperiodtype icalperiodtype_from_string (const char* str)
54 struct icalperiodtype p, null_p;
55 char *s = icalmemory_strdup(str);
56 char *start, *end = s;
59 /* Errors are normally generated in the following code, so save
60 the error state for resoration later */
62 icalerrorenum e = icalerrno;
64 p.start = p.end = icaltime_null_time();
65 p.duration = icaldurationtype_from_int(0);
69 if(s == 0) goto error;
74 if(end == 0) goto error;
79 p.start = icaltime_from_string(start);
81 if (icaltime_is_null_time(p.start)) goto error;
83 es = icalerror_get_error_state(ICAL_MALFORMEDDATA_ERROR);
84 icalerror_set_error_state(ICAL_MALFORMEDDATA_ERROR,ICAL_ERROR_NONFATAL);
86 p.end = icaltime_from_string(end);
88 icalerror_set_error_state(ICAL_MALFORMEDDATA_ERROR,es);
91 if (icaltime_is_null_time(p.end)){
93 p.duration = icaldurationtype_from_string(end);
95 if(icaldurationtype_as_int(p.duration) == 0) goto error;
99 icalmemory_free_buffer(s);
103 icalmemory_free_buffer(s);
104 icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR);
109 const char* icalperiodtype_as_ical_string(struct icalperiodtype p)
116 size_t buf_size = 40;
119 buf = (char*)icalmemory_new_buffer(buf_size);
123 start = icaltime_as_ical_string(p.start);
125 icalmemory_append_string(&buf, &buf_ptr, &buf_size, start);
127 if(!icaltime_is_null_time(p.end)){
128 end = icaltime_as_ical_string(p.end);
130 end = icaldurationtype_as_ical_string(p.duration);
133 icalmemory_append_char(&buf, &buf_ptr, &buf_size, '/');
135 icalmemory_append_string(&buf, &buf_ptr, &buf_size, end);
137 icalmemory_add_tmp_buffer(buf);
144 struct icalperiodtype icalperiodtype_null_period() {
145 struct icalperiodtype p;
146 p.start = icaltime_null_time();
147 p.end = icaltime_null_time();
148 p.duration = icaldurationtype_null_duration();
152 int icalperiodtype_is_null_period(struct icalperiodtype p){
154 if(icaltime_is_null_time(p.start) &&
155 icaltime_is_null_time(p.end) &&
156 icaldurationtype_is_null_duration(p.duration)){
163 int icalperiodtype_is_valid_period(struct icalperiodtype p){
164 if(icaltime_is_valid_time(p.start) &&
165 (icaltime_is_valid_time(p.end) || icaltime_is_null_time(p.end)) )