GRASS GIS 7 Programmer's Manual  7.9.dev(2021)-e5379bbd7
incr3.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  * This returns the components of a type
13  * (mode/from/to/fracsec) that can be used to construct a DateTime object that
14  * can be used to increment the 'src'. Also see
15  * <b>datetime_set_increment_type()</b>.
16  * returns:
17  * 0 dt is legal
18  * !=0 why dt is illegal
19  * Implemented as follows:
20  \code
21  *mode = RELATIVE
22  *to = src.to
23  *fracsec = src.fracsec
24  if src.mode is ABSOLUTE
25  if src.to is in {YEAR,MONTH} then
26  *from = YEAR
27  if src.to is in {DAY,HOUR,MINUTE,SECOND} then
28  *from = DAY
29  if src.mode is RELATIVE, then
30  *from = src.from
31  \endcode
32  *
33  * \param dt
34  * \param mode
35  * \param from
36  * \param to
37  * \param fracsec
38  * \return int
39  */
40 
41 int
42 datetime_get_increment_type(const DateTime * dt, int *mode, int *from,
43  int *to, int *fracsec)
44 {
45  if (!datetime_is_valid_type(dt))
46  return datetime_error_code();
47 
48  *mode = DATETIME_RELATIVE;
49  *to = dt->to;
50  *fracsec = dt->fracsec;
51 
52  if (datetime_is_absolute(dt)) {
54  *from = DATETIME_YEAR;
55  else
56  *from = DATETIME_DAY;
57  }
58  else {
59  *from = dt->from;
60  }
61  return 0;
62 }
63 
64 
65 /*!
66  * \brief
67  *
68  * src must be legal
69  * This is a convenience routine which is implemented as follows:
70  \code
71  int mode, from ,to;
72  int fracsec;
73  if(<b>datetime_get_increment_type</b>(src, &mode, &from, &to, &fracsec))
74  return <b>datetime_get_error_code()</b>;
75  return <b>datetime_set_type</b> (incr, mode, from, to, fracsec);
76  \endcode
77  * Timezone Timezones are represented in minutes from GMT in the range
78  * [-720,+780]. For a DateTime to have a timezone, it must be of type ABSOLUTE,
79  * and "to" must be in {MINUTE,SECOND}.
80  *
81  * \param src
82  * \param incr
83  * \return int
84  */
85 
87 {
88  int mode, from, to, fracsec;
89 
90  if (datetime_get_increment_type(src, &mode, &from, &to, &fracsec) != 0)
91  return datetime_error_code();
92  return datetime_set_type(incr, mode, from, to, fracsec);
93 }
int from
Definition: datetime.h:20
int datetime_error_code(void)
returns an error code
#define DATETIME_RELATIVE
Definition: datetime.h:5
int datetime_is_valid_type(const DateTime *dt)
Returns: 1 if datetime_check_type() returns 0 0 if not.
Definition: datetime/type.c:80
#define DATETIME_YEAR
Definition: datetime.h:10
int fracsec
Definition: datetime.h:21
#define DATETIME_DAY
Definition: datetime.h:12
int datetime_set_type(DateTime *dt, int mode, int from, int to, int fracsec)
Definition: datetime/type.c:37
int datetime_is_absolute(const DateTime *dt)
Returns: 1 if dt.mode is absolute 0 if not (even if dt.mode is not defined)
int to
Definition: datetime.h:20
int datetime_in_interval_year_month(int x)
int datetime_get_increment_type(const DateTime *dt, int *mode, int *from, int *to, int *fracsec)
This returns the components of a type (mode/from/to/fracsec) that can be used to construct a DateTime...
Definition: incr3.c:42
int datetime_set_increment_type(const DateTime *src, DateTime *incr)
src must be legal This is a convenience routine which is implemented as follows:
Definition: incr3.c:86