GRASS GIS 8 Programmer's Manual  8.2.2dev(2023)-3d2c704037
tz2.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 /*!
11  * \brief
12  *
13  * if dt has a timezone, increment dt by minutes-dt.tz MINUTES and set dt.tz = minutes
14  * Returns:
15  * 0 OK
16  * <b>datetime_check_timezone</b> (dt) if not
17  * -4 if minutes invalid
18  *
19  * \param dt
20  * \param minutes
21  * \return int
22  */
23 
24 int datetime_change_timezone(DateTime * dt, int minutes)
25 { /* new timezone in minutes */
26  int stat;
27  int old_minutes, diff_minutes;
28  DateTime incr;
29 
30  stat = datetime_get_timezone(dt, &old_minutes);
31  if (stat != 0)
32  return stat;
33  if (!datetime_is_valid_timezone(minutes))
34  return datetime_error(-4, "invalid datetime timezone");
35 
36  /* create a relative minute increment */
38  DATETIME_MINUTE, 0);
39 
40  /* BB - needed to set SIGN here */
41  diff_minutes = minutes - old_minutes;
42  if (diff_minutes >= 0) {
43  datetime_set_minute(&incr, diff_minutes);
44  }
45  else {
46  datetime_invert_sign(&incr);
47  datetime_set_minute(&incr, -diff_minutes);
48  }
49 
50  return datetime_increment(dt, &incr);
51 }
52 
53 
54 /*!
55  * \brief
56  *
57  * Return <b>datetime_change_timezone</b> (dt, 0);
58  *
59  * \param dt
60  * \return int
61  */
62 
64 {
65  return datetime_change_timezone(dt, 0);
66 }
67 
68 
69 /*!
70  * \brief
71  *
72  * tz = abs(tz)
73  * *hour = tz/60
74  * *minute = tz%60
75  * Note: hour,minute are non-negative. Must look at sign of tz itself to see if
76  * the tz is negative offset or not. This routine would be used to format tz for
77  * output. For example if tz=-350 this would be hour=5 minute=50, but negative.
78  * Output might encode this as -0550: printf ("%s%02d%02d", tz<0?"-":"",
79  * hour, minute)
80  *
81  * \param tz
82  * \param hours
83  * \param minutes
84  * \return void
85  */
86 
87 void datetime_decompose_timezone(int tz, int *hours, int *minutes)
88 {
89  if (tz < 0)
90  tz = -tz;
91 
92  *hours = tz / 60;
93  *minutes = tz % 60;
94 }
int datetime_get_timezone(const DateTime *dt, int *minutes)
returns 0 on success
Definition: tz1.c:49
int datetime_error(int code, char *msg)
record &#39;code&#39; and &#39;msg&#39; as error code/msg (in static variables) code==0 will clear the error (ie set ...
int datetime_change_timezone(DateTime *dt, int minutes)
if dt has a timezone, increment dt by minutes-dt.tz MINUTES and set dt.tz = minutes Returns: 0 OK dat...
Definition: tz2.c:24
#define DATETIME_MINUTE
Definition: datetime.h:14
#define DATETIME_RELATIVE
Definition: datetime.h:5
void datetime_invert_sign(DateTime *dt)
Definition: sign.c:80
int datetime_change_to_utc(DateTime *dt)
Return datetime_change_timezone (dt, 0);.
Definition: tz2.c:63
int datetime_set_type(DateTime *dt, int mode, int from, int to, int fracsec)
Definition: datetime/type.c:37
int datetime_set_minute(DateTime *dt, int minute)
returns 0 on success or negative value on error
Definition: values.c:442
void datetime_decompose_timezone(int tz, int *hours, int *minutes)
tz = abs(tz) *hour = tz/60 *minute = tz%60 Note: hour,minute are non-negative. Must look at sign of t...
Definition: tz2.c:87
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
int datetime_increment(DateTime *src, DateTime *incr)
This function changes the &#39;src&#39; date/time data based on the &#39;incr&#39; The type (mode/from/to) of the &#39;sr...
Definition: incr1.c:67