GRASS 8 Programmer's Manual 8.6.0dev(2026)-5f4f7ad06c
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 */
40int datetime_get_increment_type(const DateTime *dt, int *mode, int *from,
41 int *to, int *fracsec)
42{
44 return datetime_error_code();
45
46 *mode = DATETIME_RELATIVE;
47 *to = dt->to;
48 *fracsec = dt->fracsec;
49
50 if (datetime_is_absolute(dt)) {
52 *from = DATETIME_YEAR;
53 else
54 *from = DATETIME_DAY;
55 }
56 else {
57 *from = dt->from;
58 }
59 return 0;
60}
61
62/*!
63 * \brief
64 *
65 * src must be legal
66 * This is a convenience routine which is implemented as follows:
67 \code
68 int mode, from ,to;
69 int fracsec;
70 if(<b>datetime_get_increment_type</b>(src, &mode, &from, &to, &fracsec))
71 return <b>datetime_get_error_code()</b>;
72 return <b>datetime_set_type</b> (incr, mode, from, to, fracsec);
73 \endcode
74 * Timezone Timezones are represented in minutes from GMT in the range
75 * [-720,+780]. For a DateTime to have a timezone, it must be of type ABSOLUTE,
76 * and "to" must be in {MINUTE,SECOND}.
77 *
78 * \param src
79 * \param incr
80 * \return int
81 */
83{
84 int mode, from, to, fracsec;
85
86 if (datetime_get_increment_type(src, &mode, &from, &to, &fracsec) != 0)
87 return datetime_error_code();
88 return datetime_set_type(incr, mode, from, to, fracsec);
89}
#define DATETIME_DAY
Definition datetime.h:12
#define DATETIME_RELATIVE
Definition datetime.h:5
#define DATETIME_YEAR
Definition datetime.h:10
int datetime_is_valid_type(const DateTime *dt)
Returns: 1 if datetime_check_type() returns 0 0 if not.
int datetime_error_code(void)
returns an error code
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 datetime_set_type(DateTime *dt, int mode, int from, int to, int fracsec)
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:40
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:82
int to
Definition datetime.h:19
int fracsec
Definition datetime.h:20
int from
Definition datetime.h:19