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