Loading...
Searching...
No Matches
tz2.c
Go to the documentation of this file.
/*
* Copyright (C) 1995. Bill Brown <brown@gis.uiuc.edu> & Michael Shapiro
*
* This program is free software under the GPL (>=v2)
* Read the file GPL.TXT coming with GRASS for details.
*/
#include <grass/datetime.h>
/*!
* \brief
*
* if dt has a timezone, increment dt by minutes-dt.tz MINUTES and set dt.tz =
* minutes Returns: 0 OK <b>datetime_check_timezone</b> (dt) if not -4 if
* minutes invalid
*
* \param dt
* \param minutes
* \return int
*/
int datetime_change_timezone(DateTime *dt, int minutes)
{ /* new timezone in minutes */
int stat;
int old_minutes, diff_minutes;
DateTime incr;
stat = datetime_get_timezone(dt, &old_minutes);
if (stat != 0)
return stat;
if (!datetime_is_valid_timezone(minutes))
return datetime_error(-4, "invalid datetime timezone");
/* create a relative minute increment */
datetime_set_type(&incr, DATETIME_RELATIVE, DATETIME_MINUTE,
DATETIME_MINUTE, 0);
/* BB - needed to set SIGN here */
diff_minutes = minutes - old_minutes;
if (diff_minutes >= 0) {
datetime_set_minute(&incr, diff_minutes);
}
else {
datetime_invert_sign(&incr);
datetime_set_minute(&incr, -diff_minutes);
}
return datetime_increment(dt, &incr);
}
/*!
* \brief
*
* Return <b>datetime_change_timezone</b> (dt, 0);
*
* \param dt
* \return int
*/
int datetime_change_to_utc(DateTime *dt)
{
return datetime_change_timezone(dt, 0);
}
/*!
* \brief
*
* tz = abs(tz)
* *hour = tz/60
* *minute = tz%60
* Note: hour,minute are non-negative. Must look at sign of tz itself to see if
* the tz is negative offset or not. This routine would be used to format tz for
* output. For example if tz=-350 this would be hour=5 minute=50, but negative.
* Output might encode this as -0550: printf ("%s%02d%02d", tz<0?"-":"",
* hour, minute)
*
* \param tz
* \param hours
* \param minutes
* \return void
*/
void datetime_decompose_timezone(int tz, int *hours, int *minutes)
{
if (tz < 0)
tz = -tz;
*hours = tz / 60;
*minutes = tz % 60;
}
datetime_error
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 ...
Definition datetime/error.c:27
datetime_increment
int datetime_increment(DateTime *src, DateTime *incr)
This function changes the 'src' date/time data based on the 'incr' The type (mode/from/to) of the 'sr...
Definition incr1.c:67
datetime_invert_sign
void datetime_invert_sign(DateTime *dt)
Definition sign.c:71
datetime_set_type
int datetime_set_type(DateTime *dt, int mode, int from, int to, int fracsec)
Definition type.c:36
datetime_is_valid_timezone
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
datetime_get_timezone
int datetime_get_timezone(const DateTime *dt, int *minutes)
returns 0 on success
Definition tz1.c:44
datetime_change_to_utc
int datetime_change_to_utc(DateTime *dt)
Return datetime_change_timezone (dt, 0);.
Definition tz2.c:57
datetime_change_timezone
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:20
datetime_decompose_timezone
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:79
datetime_set_minute
int datetime_set_minute(DateTime *dt, int minute)
returns 0 on success or negative value on error
Definition values.c:407