$darkmode
Libical API Documentation 4.0 STABLE VERSION Visit the v3.0 documentation
icalperiod.c
Go to the documentation of this file.
1 /*======================================================================
2  FILE: icalperiod.c
3  CREATOR: eric 02 June 2000
4 
5  SPDX-FileCopyrightText: 2000, Eric Busboom <eric@civicknowledge.com>
6  SPDX-License-Identifier: LGPL-2.1-only OR MPL-2.0
7 
8  The Original Code is eric. The Initial Developer of the Original
9  Code is Eric Busboom
10 ======================================================================*/
11 
17 #ifdef HAVE_CONFIG_H
18 #include <config.h>
19 #endif
20 
21 #include "icalperiod.h"
22 #include "icalerror_p.h"
23 #include "icalmemory.h"
24 
26 {
27  struct icalperiodtype p, null_p;
28  char *s = icalmemory_strdup(str);
29  const char *start;
30  char *end;
31  icalerrorstate es;
32 
33  /* Errors are normally generated in the following code, so save
34  the error state for resoration later */
35 
37 
38  p.start = p.end = icaltime_null_time();
40 
41  null_p = p;
42 
43  if (s == 0) {
44  goto error;
45  }
46 
47  start = s;
48  end = strchr(s, '/');
49 
50  if (end == 0) {
51  goto error;
52  }
53 
54  *end = 0;
55  end++;
56 
57  p.start = icaltime_from_string(start);
58 
60  goto error;
61  }
62 
65 
66  p.end = icaltime_from_string(end);
67 
69 
70  if (icaltime_is_null_time(p.end)) {
72 
74  goto error;
75  }
76  }
77 
78  icalerrno = e;
80  return p;
81 
82 error:
85  return null_p;
86 }
87 
89 {
90  char *buf;
91 
94  return buf;
95 }
96 
98 {
99  const char *start;
100  const char *end;
101 
102  char *buf;
103  size_t buf_size = 40;
104  char *buf_ptr = 0;
105 
106  buf = (char *)icalmemory_new_buffer(buf_size);
107  buf_ptr = buf;
108 
109  start = icaltime_as_ical_string_r(p.start);
110  icalmemory_append_string(&buf, &buf_ptr, &buf_size, start);
111  icalmemory_free_buffer((void *)start);
112 
113  if (!icaltime_is_null_time(p.end)) {
115  } else {
117  }
118 
119  icalmemory_append_char(&buf, &buf_ptr, &buf_size, '/');
120 
121  icalmemory_append_string(&buf, &buf_ptr, &buf_size, end);
122  icalmemory_free_buffer((void *)end);
123 
124  return buf;
125 }
126 
128 {
129  struct icalperiodtype p;
130 
132  p.end = icaltime_null_time();
134 
135  return p;
136 }
137 
139 {
140  if (icaltime_is_null_time(p.start) &&
142  return true;
143  } else {
144  return false;
145  }
146 }
147 
149 {
150  if (icaltime_is_valid_time(p.start) &&
152  return true;
153  }
154 
155  return false;
156 }
Common memory management routines.
char * icalmemory_strdup(const char *s)
Creates a duplicate of a string.
Definition: icalmemory.c:242
void icalmemory_free_buffer(void *buf)
Releases a buffer.
Definition: icalmemory.c:355
icalerrorstate
Determine if an error is fatal or non-fatal.
Definition: icalerror.h:88
struct icaldurationtype duration
Definition: icalperiod.h:36
void icalerror_set_errno(icalerrorenum x)
Sets the icalerrno to a given error.
Definition: icalerror.c:90
icalerrorenum
Represents the different types of errors that can be triggered in libical.
Definition: icalerror.h:41
icalerrorstate icalerror_get_error_state(icalerrorenum error)
Gets the error state (severity) for a given error.
bool icalperiodtype_is_null_period(struct icalperiodtype p)
Definition: icalperiod.c:138
void icalmemory_append_char(char **buf, char **pos, size_t *buf_size, char ch)
Appends a character to a buffer.
Definition: icalmemory.c:406
bool icaldurationtype_is_null_duration(struct icaldurationtype d)
Checks if a duration is a null duration.
Definition: icalduration.c:270
const char * icalperiodtype_as_ical_string(struct icalperiodtype p)
Converts an icalperiodtype into an iCal-formatted string.
Definition: icalperiod.c:88
struct icaltimetype icaltime_null_time(void)
Definition: icaltime.c:579
char * icaldurationtype_as_ical_string_r(struct icaldurationtype d)
Definition: icalduration.c:190
struct icaltimetype end
Definition: icalperiod.h:34
bool icalperiodtype_is_valid_period(struct icalperiodtype p)
Definition: icalperiod.c:148
bool icaltime_is_valid_time(const struct icaltimetype t)
Definition: icaltime.c:607
void * icalmemory_new_buffer(size_t size)
Creates new buffer with the specified size.
Definition: icalmemory.c:315
void icalmemory_append_string(char **buf, char **pos, size_t *buf_size, const char *string)
Appends a string to a buffer.
Definition: icalmemory.c:365
struct icaltimetype icaltime_from_string(const char *str)
Definition: icaltime.c:374
struct icaltimetype start
Definition: icalperiod.h:31
char * icalperiodtype_as_ical_string_r(struct icalperiodtype p)
Converts an icalperiodtype into an iCal-formatted string.
Definition: icalperiod.c:97
struct icaldurationtype icaldurationtype_null_duration(void)
Creates a duration with zero length.
Definition: icalduration.c:261
Defines data structures for working with iCal periods (of time).
struct icalperiodtype icalperiodtype_null_period(void)
Definition: icalperiod.c:127
struct icalperiodtype icalperiodtype_from_string(const char *str)
Constructs a new icalperiodtype from str.
Definition: icalperiod.c:25
#define icalerrno
Access the current icalerrno value.
Definition: icalerror.h:133
void icalerror_set_error_state(icalerrorenum error, icalerrorstate state)
Sets the icalerrorstate for a given icalerrorenum error.
bool icaltime_is_null_time(const struct icaltimetype t)
Definition: icaltime.c:630
struct icaldurationtype icaldurationtype_from_string(const char *str)
Creates a new icaldurationtype from a duration given as a string.
Definition: icalduration.c:43
void icalmemory_add_tmp_buffer(void *buf)
Adds an externally allocated buffer to the ring.
Definition: icalmemory.c:158
char * icaltime_as_ical_string_r(const struct icaltimetype tt)
Definition: icaltime.c:341