Loading...
Searching...
No Matches
incr3.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
*
* This returns the components of a type
* (mode/from/to/fracsec) that can be used to construct a DateTime object that
* can be used to increment the 'src'. Also see
* <b>datetime_set_increment_type()</b>.
* returns:
* 0 dt is legal
* !=0 why dt is illegal
* Implemented as follows:
\code
*mode = RELATIVE
*to = src.to
*fracsec = src.fracsec
if src.mode is ABSOLUTE
if src.to is in {YEAR,MONTH} then
*from = YEAR
if src.to is in {DAY,HOUR,MINUTE,SECOND} then
*from = DAY
if src.mode is RELATIVE, then
*from = src.from
\endcode
*
* \param dt
* \param mode
* \param from
* \param to
* \param fracsec
* \return int
*/
int datetime_get_increment_type(const DateTime *dt, int *mode, int *from,
int *to, int *fracsec)
{
if (!datetime_is_valid_type(dt))
return datetime_error_code();
*mode = DATETIME_RELATIVE;
*to = dt->to;
*fracsec = dt->fracsec;
if (datetime_is_absolute(dt)) {
if (datetime_in_interval_year_month(dt->to))
*from = DATETIME_YEAR;
else
*from = DATETIME_DAY;
}
else {
*from = dt->from;
}
return 0;
}
/*!
* \brief
*
* src must be legal
* This is a convenience routine which is implemented as follows:
\code
int mode, from ,to;
int fracsec;
if(<b>datetime_get_increment_type</b>(src, &mode, &from, &to, &fracsec))
return <b>datetime_get_error_code()</b>;
return <b>datetime_set_type</b> (incr, mode, from, to, fracsec);
\endcode
* Timezone Timezones are represented in minutes from GMT in the range
* [-720,+780]. For a DateTime to have a timezone, it must be of type ABSOLUTE,
* and "to" must be in {MINUTE,SECOND}.
*
* \param src
* \param incr
* \return int
*/
int datetime_set_increment_type(const DateTime *src, DateTime *incr)
{
int mode, from, to, fracsec;
if (datetime_get_increment_type(src, &mode, &from, &to, &fracsec) != 0)
return datetime_error_code();
return datetime_set_type(incr, mode, from, to, fracsec);
}
datetime_error_code
int datetime_error_code(void)
returns an error code
Definition datetime/error.c:44
datetime_get_increment_type
int datetime_get_increment_type(const DateTime *dt, int *mode, int *from, int *to, int *fracsec)
This returns the components of a type (mode/from/to/fracsec) that can be used to construct a DateTime...
Definition incr3.c:40
datetime_set_increment_type
int datetime_set_increment_type(const DateTime *src, DateTime *incr)
src must be legal This is a convenience routine which is implemented as follows:
Definition incr3.c:82
datetime_is_valid_type
int datetime_is_valid_type(const DateTime *dt)
Returns: 1 if datetime_check_type() returns 0 0 if not.
Definition type.c:76
datetime_is_absolute
int datetime_is_absolute(const DateTime *dt)
Returns: 1 if dt.mode is absolute 0 if not (even if dt.mode is not defined).
Definition type.c:165
datetime_set_type
int datetime_set_type(DateTime *dt, int mode, int from, int to, int fracsec)
Definition type.c:36
datetime_in_interval_year_month
int datetime_in_interval_year_month(int x)
Definition type.c:145