grass  7.8.6
About: GRASS (Geographic Resources Analysis Support System) is a raster- and vector-based GIS, image processing system, graphics production system and spatial modeling system.
  Fossies Dox: grass-7.8.6.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

tz1.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
10static int have(int x, const DateTime * dt)
11{
12 return datetime_is_between(x, dt->from, dt->to);
13}
14
15
16/*!
17 * \brief
18 *
19 * returns 0 on success
20 *
21 * \param dt
22 * \param minutes
23 * \return int
24 */
25
26int datetime_check_timezone(const DateTime * dt, int minutes)
27{
28 if (!datetime_is_absolute(dt))
29 return datetime_error(-1, "datetime not absolute");
30 if (!have(DATETIME_MINUTE, dt))
31 return datetime_error(-2, "datetime has no minute");
32 if (!datetime_is_valid_timezone(minutes))
33 return datetime_error(-3, "invalid datetime timezone");
34
35 return 0;
36}
37
38
39/*!
40 * \brief
41 *
42 * returns 0 on success
43 *
44 * \param dt
45 * \param minutes
46 * \return int
47 */
48
49int datetime_get_timezone(const DateTime * dt, int *minutes)
50{
51 int stat;
52
53 stat = datetime_check_timezone(dt, dt->tz);
54 if (stat == 0)
55 *minutes = dt->tz;
56
57 return stat;
58}
59
60
61/*!
62 * \brief
63 *
64 * returns 0 on success
65 *
66 * \param dt
67 * \param minutes
68 * \return int
69 */
70
71int datetime_set_timezone(DateTime * dt, int minutes)
72{
73 int stat;
74
75 stat = datetime_check_timezone(dt, minutes);
76 if (stat == 0)
77 dt->tz = minutes;
78
79 return stat;
80}
81
82/*!
83 * \brief
84 *
85 * unsets timezone in 'dt'
86 * returns 0
87 *
88 * \param dt
89 * \return int
90 */
91
93{
94 dt->tz = -9999;
95
96 return 0;
97}
98
99
100/*!
101 * \brief
102 *
103 * Returns:
104 * 1 OK: -720 <= minutes <= 780 (720 = 12 hours; 780 = 13 hours)
105 * 0 NOT OK
106 *
107 * \param minutes
108 * \return int
109 */
110
112{
113 return (minutes >= -720 && minutes <= 780);
114}
int datetime_is_between(int x, int a, int b)
Definition: between.c:8
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 ...
Definition: error.c:30
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:173
#define DATETIME_MINUTE
Definition: datetime.h:14
int to
Definition: datetime.h:20
int tz
Definition: datetime.h:26
int from
Definition: datetime.h:20
int datetime_is_valid_timezone(int minutes)
Returns: 1 OK: -720 <= minutes <= 780 (720 = 12 hours; 780 = 13 hours) 0 NOT OK.
Definition: tz1.c:111
static int have(int x, const DateTime *dt)
Definition: tz1.c:10
int datetime_get_timezone(const DateTime *dt, int *minutes)
returns 0 on success
Definition: tz1.c:49
int datetime_unset_timezone(DateTime *dt)
unsets timezone in 'dt' returns 0
Definition: tz1.c:92
int datetime_set_timezone(DateTime *dt, int minutes)
returns 0 on success
Definition: tz1.c:71
int datetime_check_timezone(const DateTime *dt, int minutes)
returns 0 on success
Definition: tz1.c:26
#define x