51 int size = (int)strlen(str);
57 for (i = 0; i != size; i++) {
62 if (i != 0 || begin_flag == 1) {
68 if (i != 0 || begin_flag == 1) {
76 if (i != 0 && i != 1) {
104 if (begin_flag == 0) {
108 scan_size = sscanf(&str[i],
"%10d", &digits);
110 if (scan_size != 1) {
117 if (time_flag == 0 || d.
hours != 0 || digits == -1) {
120 d.
hours = (
unsigned int)digits;
125 if (time_flag == 0 || d.
minutes != 0 || digits == -1) {
128 d.
minutes = (
unsigned int)digits;
133 if (time_flag == 0 || d.
seconds != 0 || digits == -1) {
136 d.
seconds = (
unsigned int)digits;
141 if (time_flag == 1 || date_flag == 1 || d.
weeks != 0 || digits == -1) {
144 d.
weeks = (
unsigned int)digits;
149 if (time_flag == 1 || d.
days != 0 || digits == -1) {
153 d.
days = (
unsigned int)digits;
170static void append_duration_segment(
char **buf,
char **buf_ptr,
size_t *buf_size,
171 const char *sep,
unsigned int value)
175 snprintf(temp,
sizeof(temp),
"%u", value);
193 size_t buf_size = 256;
213 append_duration_segment(&buf, &buf_ptr, &buf_size,
"W", d.
weeks);
217 append_duration_segment(&buf, &buf_ptr, &buf_size,
"D", d.
days);
224 append_duration_segment(&buf, &buf_ptr, &buf_size,
"H", d.
hours);
227 append_duration_segment(&buf, &buf_ptr, &buf_size,
"M", d.
minutes);
230 append_duration_segment(&buf, &buf_ptr, &buf_size,
"S", d.
seconds);
245 return (
int)(((int)dur.
seconds +
247 60 * ((int)dur.
hours))) *
248 (dur.
is_neg == 1 ? -1 : 1));
253 return (
int)(((int)dur.
seconds +
255 60 * ((int)dur.
hours +
256 24 * ((int)dur.
days +
257 7 * (int)dur.
weeks)))) *
258 (dur.
is_neg == 1 ? -1 : 1));
305 icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR);
306 return icaltime_null_time();
311 t.day += (int)d.days;
312 t.day += (int)(d.weeks * 7);
314 t.day -= (int)d.days;
315 t.day -= (int)(d.weeks * 7);
322 t.second += (int)d.seconds;
323 t.minute += (int)d.minutes;
324 t.hour += (int)d.hours;
326 t.second -= (int)d.seconds;
327 t.minute -= (int)d.minutes;
328 t.hour -= (int)d.hours;
348 if ((!t1.is_date && t2.is_date) ||
349 (t1.is_date && !t2.is_date)) {
350 icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR);
351 return icaldurationtype_bad_duration();
356 icaltime_t t1t = icaltime_as_timet(t1);
357 icaltime_t t2t = icaltime_as_timet(t2);
358 ret = icaldurationtype_null_duration();
359 ret.days = ((unsigned int)(t1t - t2t)) / (60 * 60 * 24);
361 icaltime_t t1t = icaltime_as_timet_with_zone(t1, t1.zone);
362 icaltime_t t2t = icaltime_as_timet_with_zone(t2, t2.zone);
364 ret = icaldurationtype_from_seconds((int)(t1t - t2t));
372 newdur.
is_neg = dur.is_neg;
375 if (dur.days % 7 == 0 && !dur.hours && !dur.minutes && !dur.seconds) {
376 newdur.
weeks = dur.weeks + dur.days / 7;
378 newdur.
days = dur.days + dur.weeks * 7;
382 unsigned ut = dur.seconds + dur.minutes * 60 + dur.hours * 60 * 60;
384 newdur.
hours = (ut - used) / (60 * 60);
385 used += newdur.
hours * (60 * 60);
386 newdur.
minutes = (ut - used) / (60);
struct icaldurationtype icaldurationtype_bad_duration(void)
Creates a bad duration (used to indicate error).
struct icaldurationtype icalduration_from_times(struct icaltimetype t1, struct icaltimetype t2)
Creates a duration from two icaltimetype endpoints.
struct icaltimetype icalduration_extend(struct icaltimetype t, struct icaldurationtype d)
Extends a time duration.
bool icaldurationtype_is_bad_duration(struct icaldurationtype d)
Checks if a duration is a bad duration.
struct icaldurationtype icaldurationtype_from_seconds(int seconds)
Creates a new icaldurationtype from a duration in seconds.
int icaldurationtype_as_seconds(struct icaldurationtype dur)
Extracts the duration in integer seconds from an icaldurationtype.
int icaldurationtype_as_utc_seconds(struct icaldurationtype dur)
Extracts the duration in integer seconds from an icaldurationtype in UTC time.
char * icaldurationtype_as_ical_string_r(struct icaldurationtype d)
struct icaldurationtype icaldurationtype_from_string(const char *str)
Creates a new icaldurationtype from a duration given as a string.
bool icaldurationtype_is_null_duration(struct icaldurationtype d)
Checks if a duration is a null duration.
struct icaldurationtype icaldurationtype_null_duration(void)
Creates a duration with zero length.
char * icaldurationtype_as_ical_string(struct icaldurationtype d)
struct icaldurationtype icaldurationtype_normalize(struct icaldurationtype dur)
Create a normalized duration from another duration.
Defines the data structure for time durations.
struct icaldurationtype icaldurationtype_null_duration(void)
Creates a duration with zero length.
void icalerror_set_errno(icalerrorenum x)
Sets the icalerrno to a given error.
Error handling for libical.
@ ICAL_MALFORMEDDATA_ERROR
void icalmemory_append_string(char **buf, char **pos, size_t *buf_size, const char *string)
Appends a string to a buffer.
void * icalmemory_new_buffer(size_t size)
Creates new buffer with the specified size.
void icalmemory_append_char(char **buf, char **pos, size_t *buf_size, char ch)
Appends a character to a buffer.
void icalmemory_add_tmp_buffer(void *buf)
Adds an externally allocated buffer to the ring.
Common memory management routines.
struct icaltimetype icaltime_normalize(const struct icaltimetype tt)
Defines the data structure for representing date-times.
void icaltime_adjust(struct icaltimetype *tt, const int days, const int hours, const int minutes, const int seconds)
int icaltimezone_get_utc_offset(icaltimezone *zone, const struct icaltimetype *tt, int *is_daylight)
Timezone handling routines.
struct _icaltimezone icaltimezone