GRASS GIS 8 Programmer's Manual 8.4.1(2025)-45ca3179ab
Loading...
Searching...
No Matches
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
41int datetime_get_increment_type(const DateTime *dt, int *mode, int *from,
42 int *to, int *fracsec)
43{
45 return datetime_error_code();
46
47 *mode = DATETIME_RELATIVE;
48 *to = dt->to;
49 *fracsec = dt->fracsec;
50
51 if (datetime_is_absolute(dt)) {
53 *from = DATETIME_YEAR;
54 else
55 *from = DATETIME_DAY;
56 }
57 else {
58 *from = dt->from;
59 }
60 return 0;
61}
62
63/*!
64 * \brief
65 *
66 * src must be legal
67 * This is a convenience routine which is implemented as follows:
68 \code
69 int mode, from ,to;
70 int fracsec;
71 if(<b>datetime_get_increment_type</b>(src, &mode, &from, &to, &fracsec))
72 return <b>datetime_get_error_code()</b>;
73 return <b>datetime_set_type</b> (incr, mode, from, to, fracsec);
74 \endcode
75 * Timezone Timezones are represented in minutes from GMT in the range
76 * [-720,+780]. For a DateTime to have a timezone, it must be of type ABSOLUTE,
77 * and "to" must be in {MINUTE,SECOND}.
78 *
79 * \param src
80 * \param incr
81 * \return int
82 */
83
84int datetime_set_increment_type(const DateTime *src, DateTime *incr)
85{
86 int mode, from, to, fracsec;
87
88 if (datetime_get_increment_type(src, &mode, &from, &to, &fracsec) != 0)
89 return datetime_error_code();
90 return datetime_set_type(incr, mode, from, to, fracsec);
91}
int datetime_error_code(void)
returns an error code
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:41
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:84
int datetime_is_valid_type(const DateTime *dt)
Returns: 1 if datetime_check_type() returns 0 0 if not.
Definition type.c:77
int datetime_is_absolute(const DateTime *dt)
Returns: 1 if dt.mode is absolute 0 if not (even if dt.mode is not defined)
Definition type.c:168
int datetime_set_type(DateTime *dt, int mode, int from, int to, int fracsec)
Definition type.c:36
int datetime_in_interval_year_month(int x)
Definition type.c:147