GRASS Programmer's Manual  6.4.2(2012)
tz2.c
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 1995.  Bill Brown <brown@gis.uiuc.edu> & Michael Shapiro
00003  *
00004  * This program is free software under the GPL (>=v2)
00005  * Read the file GPL.TXT coming with GRASS for details.
00006  */
00007 #include <grass/datetime.h>
00008 
00009 
00024 int datetime_change_timezone(DateTime * dt, int minutes)
00025 {                               /* new timezone in minutes */
00026     int stat;
00027     int old_minutes, diff_minutes;
00028     DateTime incr;
00029 
00030     stat = datetime_get_timezone(dt, &old_minutes);
00031     if (stat != 0)
00032         return stat;
00033     if (!datetime_is_valid_timezone(minutes))
00034         return datetime_error(-4, "invalid datetime timezone");
00035 
00036     /* create a relative minute increment */
00037     datetime_set_type(&incr, DATETIME_RELATIVE, DATETIME_MINUTE,
00038                       DATETIME_MINUTE, 0);
00039 
00040     /* BB - needed to set SIGN here */
00041     diff_minutes = minutes - old_minutes;
00042     if (diff_minutes >= 0) {
00043         datetime_set_minute(&incr, diff_minutes);
00044     }
00045     else {
00046         datetime_invert_sign(&incr);
00047         datetime_set_minute(&incr, -diff_minutes);
00048     }
00049 
00050     return datetime_increment(dt, &incr);
00051 }
00052 
00053 
00063 int datetime_change_to_utc(DateTime * dt)
00064 {
00065     return datetime_change_timezone(dt, 0);
00066 }
00067 
00068 
00087 void datetime_decompose_timezone(int tz, int *hours, int *minutes)
00088 {
00089     if (tz < 0)
00090         tz = -tz;
00091 
00092     *hours = tz / 60;
00093     *minutes = tz % 60;
00094 }
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines