GRASS 8 Programmer's Manual  8.5.0dev(2025)-c070206eb1
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  * \brief
11  *
12  * Returns:
13  * <b>datetime_check_increment</b>(src, incr) == 0
14  *
15  * \param src
16  * \param incr
17  * \return int
18  */
19 int datetime_is_valid_increment(const DateTime *src, const DateTime *incr)
20 {
21  return datetime_check_increment(src, incr) == 0;
22 }
23 
24 /*!
25  * \brief
26  *
27  * This checks if the type of 'incr' is valid for incrementing/decrementing
28  'src'.
29  * The type (mode/from/to) of the 'src' can be anything.
30  * The incr.mode must be RELATIVE
31  * A timezone in 'src' is allowed - it's presence is ignored.
32  * To aid in setting the 'incr' type, see <b>datetime_get_increment_type()</b>.
33  * Returns:
34  * <ul>
35  <li> 0 valid increment
36  </li>
37  <li> 1 src is not a legal DateTime, error code/msg are those set by
38  * <b>datetime_is_valid_type()</b>
39  </li>
40  <li> 2 incr is not a legal DateTime, error code/msg are those set by
41  * <b>datetime_is_valid_type()</b>
42  </li>
43  <li> -1 incr.mode not relative
44  </li>
45  <li> -2 incr more precise that src
46  </li>
47  <li> -3 illegal incr, must be YEAR-MONTH
48  </li>
49  <li> -4 illegal incr, must be DAY-SECOND
50  </li></ul>
51  *
52  * \param src
53  * \param incr
54  * \return int
55  */
56 int datetime_check_increment(const DateTime *src, const DateTime *incr)
57 {
58  if (!datetime_is_valid_type(src))
59  return 1;
60  if (!datetime_is_valid_type(incr))
61  return 2;
62 
63  if (!datetime_is_relative(incr))
64  return datetime_error(-1, "datetime increment mode not relative");
65  if (incr->to > src->to)
66  return datetime_error(-2, "datetime increment too precise");
67 
70  return datetime_error(-3, "illegal datetime increment interval");
71 
74  return datetime_error(-4, "illegal datetime increment interval");
75 
76  return 0;
77 }
int datetime_error(int code, char *msg)
record 'code' and 'msg' as error code/msg (in static variables) code==0 will clear the error (ie set ...
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:76
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_year_month(int x)
int datetime_check_increment(const DateTime *src, const DateTime *incr)
This checks if the type of 'incr' is valid for incrementing/decrementing 'src'. The type (mode/from/t...
Definition: incr2.c:56
int datetime_is_valid_increment(const DateTime *src, const DateTime *incr)
Returns: datetime_check_increment(src, incr) == 0.
Definition: incr2.c:19
int to
Definition: datetime.h:19