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