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) {
109 scan_size = sscanf(&
str[i],
"%10d", &digits);
113 if (scan_size != 1) {
120 if (time_flag == 0 || d.
hours != 0 || digits == -1) {
123 d.
hours = (
unsigned int)digits;
128 if (time_flag == 0 || d.
minutes != 0 || digits == -1) {
131 d.
minutes = (
unsigned int)digits;
136 if (time_flag == 0 || d.
seconds != 0 || digits == -1) {
139 d.
seconds = (
unsigned int)digits;
144 if (time_flag == 1 || date_flag == 1 || d.
weeks != 0 || digits == -1) {
147 d.
weeks = (
unsigned int)digits;
152 if (time_flag == 1 || d.
days != 0 || digits == -1) {
156 d.
days = (
unsigned int)digits;
173static void append_duration_segment(
char **buf,
char **buf_ptr,
size_t *buf_size,
174 const char *sep,
unsigned int value)
178 snprintf(temp,
sizeof(temp),
"%u", value);
196 size_t buf_size = 256;
216 append_duration_segment(&buf, &buf_ptr, &buf_size,
"W", d.
weeks);
220 append_duration_segment(&buf, &buf_ptr, &buf_size,
"D", d.
days);
227 append_duration_segment(&buf, &buf_ptr, &buf_size,
"H", d.
hours);
230 append_duration_segment(&buf, &buf_ptr, &buf_size,
"M", d.
minutes);
233 append_duration_segment(&buf, &buf_ptr, &buf_size,
"S", d.
seconds);
248 return (
int)(((int)dur.
seconds +
250 60 * ((int)dur.
hours))) *
251 (dur.
is_neg == 1 ? -1 : 1));
256 return (
int)(((int)dur.
seconds +
258 60 * ((int)dur.
hours +
259 24 * ((int)dur.
days +
260 7 * (int)dur.
weeks)))) *
261 (dur.
is_neg == 1 ? -1 : 1));
308 icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR);
309 return icaltime_null_time();
314 t.day += (int)d.days;
315 t.day += (int)(d.weeks * 7);
317 t.day -= (int)d.days;
318 t.day -= (int)(d.weeks * 7);
325 t.second += (int)d.seconds;
326 t.minute += (int)d.minutes;
327 t.hour += (int)d.hours;
329 t.second -= (int)d.seconds;
330 t.minute -= (int)d.minutes;
331 t.hour -= (int)d.hours;
351 if ((!t1.is_date && t2.is_date) ||
352 (t1.is_date && !t2.is_date)) {
353 icalerror_set_errno(ICAL_MALFORMEDDATA_ERROR);
354 return icaldurationtype_bad_duration();
359 icaltime_t t1t = icaltime_as_timet(t1);
360 icaltime_t t2t = icaltime_as_timet(t2);
361 ret = icaldurationtype_null_duration();
362 ret.days = ((unsigned int)(t1t - t2t)) / (60 * 60 * 24);
364 icaltime_t t1t = icaltime_as_timet_with_zone(t1, t1.zone);
365 icaltime_t t2t = icaltime_as_timet_with_zone(t2, t2.zone);
367 ret = icaldurationtype_from_seconds((int)(t1t - t2t));
375 newdur.
is_neg = dur.is_neg;
378 if (dur.days % 7 == 0 && !dur.hours && !dur.minutes && !dur.seconds) {
379 newdur.
weeks = dur.weeks + dur.days / 7;
381 newdur.
days = dur.days + dur.weeks * 7;
385 unsigned ut = dur.seconds + dur.minutes * 60 + dur.hours * 60 * 60;
387 newdur.
hours = (ut - used) / (60 * 60);
388 used += newdur.
hours * (60 * 60);
389 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