GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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 
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 */
37  datetime_set_type(&incr, DATETIME_RELATIVE, DATETIME_MINUTE,
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 
63 int datetime_change_to_utc(DateTime * dt)
64 {
65  return datetime_change_timezone(dt, 0);
66 }
67 
68 
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_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
int datetime_set_type(DateTime *dt, int mode, int from, int to, int fracsec)
Definition: datetime/type.c:37
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
int datetime_is_valid_timezone(int minutes)
Returns: 1 OK: -720 &lt;= minutes &lt;= 780 (720 = 12 hours; 780 = 13 hours) 0 NOT OK.
Definition: tz1.c:111
int stat
Definition: g3dcolor.c:369
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_set_minute(DateTime *dt, int minute)
returns 0 on success or negative value on error
Definition: values.c:442
int datetime_get_timezone(const DateTime *dt, int *minutes)
returns 0 on success
Definition: tz1.c:49
int datetime_change_to_utc(DateTime *dt)
Return datetime_change_timezone (dt, 0);.
Definition: tz2.c:63
void datetime_invert_sign(DateTime *dt)
Definition: sign.c:80
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