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