GRASS GIS 7 Programmer's Manual  7.9.dev(2021)-e5379bbd7
incr2.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1995. Bill Brown <brown@gis.uiuc.edu> & Michael Shapiro
3  *
4  * This program is free software under the GPL (>=v2)
5  * Read the file GPL.TXT coming with GRASS for details.
6  */
7 #include <grass/datetime.h>
8 
9 
10 /*!
11  * \brief
12  *
13  * Returns:
14  * <b>datetime_check_increment</b>(src, incr) == 0
15  *
16  * \param src
17  * \param incr
18  * \return int
19  */
20 
21 int datetime_is_valid_increment(const DateTime * src, const DateTime * incr)
22 {
23  return datetime_check_increment(src, incr) == 0;
24 }
25 
26 
27 
28 /*!
29  * \brief
30  *
31  * This checks if the type of 'incr' is valid for incrementing/decrementing 'src'.
32  * The type (mode/from/to) of the 'src' can be anything.
33  * The incr.mode must be RELATIVE
34  * A timezone in 'src' is allowed - it's presence is ignored.
35  * To aid in setting the 'incr' type, see <b>datetime_get_increment_type()</b>.
36  * Returns:
37  * <ul>
38  <li> 0 valid increment
39  </li>
40  <li> 1 src is not a legal DateTime, error code/msg are those set by
41  * <b>datetime_is_valid_type()</b>
42  </li>
43  <li> 2 incr is not a legal DateTime, error code/msg are those set by
44  * <b>datetime_is_valid_type()</b>
45  </li>
46  <li> -1 incr.mode not relative
47  </li>
48  <li> -2 incr more precise that src
49  </li>
50  <li> -3 illegal incr, must be YEAR-MONTH
51  </li>
52  <li> -4 illegal incr, must be DAY-SECOND
53  </li></ul>
54  *
55  * \param src
56  * \param incr
57  * \return int
58  */
59 
60 int datetime_check_increment(const DateTime * src, const DateTime * incr)
61 {
62  if (!datetime_is_valid_type(src))
63  return 1;
64  if (!datetime_is_valid_type(incr))
65  return 2;
66 
67  if (!datetime_is_relative(incr))
68  return datetime_error(-1, "datetime increment mode not relative");
69  if (incr->to > src->to)
70  return datetime_error(-2, "datetime increment too precise");
71 
74  return datetime_error(-3, "illegal datetime increment interval");
75 
78  return datetime_error(-4, "illegal datetime increment interval");
79 
80  return 0;
81 }
int datetime_check_increment(const DateTime *src, const DateTime *incr)
This checks if the type of &#39;incr&#39; is valid for incrementing/decrementing &#39;src&#39;. The type (mode/from/t...
Definition: incr2.c:60
int datetime_is_valid_increment(const DateTime *src, const DateTime *incr)
Returns: datetime_check_increment(src, incr) == 0.
Definition: incr2.c:21
int datetime_error(int code, char *msg)
record &#39;code&#39; and &#39;msg&#39; as error code/msg (in static variables) code==0 will clear the error (ie set ...
int datetime_is_relative(const DateTime *dt)
Returns: 1 if dt.mode is relative 0 if not (even if dt.mode is not defined)
int datetime_in_interval_day_second(int x)
int datetime_is_valid_type(const DateTime *dt)
Returns: 1 if datetime_check_type() returns 0 0 if not.
Definition: datetime/type.c:80
int to
Definition: datetime.h:20
int datetime_in_interval_year_month(int x)