GRASS GIS 7 Programmer's Manual  7.5.svn(2018)-r73101
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
change.c File Reference
#include <grass/datetime.h>
Include dependency graph for change.c:

Go to the source code of this file.

Functions

int datetime_change_from_to (DateTime *dt, int from, int to, int round)
 Changes the from/to of the type for dt. The 'from/to' must be legal values for the mode of dt; (if they are not legal, then the original values are preserved, dt is not changed). Returns: 0 OK -1 invalid 'dt' -2 invalid 'from/to'
More...
 

Function Documentation

int datetime_change_from_to ( DateTime dt,
int  from,
int  to,
int  round 
)

Changes the from/to of the type for dt. The 'from/to' must be legal values for the mode of dt; (if they are not legal, then the original values are preserved, dt is not changed). Returns: 0 OK -1 invalid 'dt' -2 invalid 'from/to'

  • round = negative implies floor() [decrease magnitude] 0 implies normal rounding, [incr/decr magnitude] positive implies ceil() [increase magnitude]
  • If dt.from < 'from' (losing "lower" elements), convert the "lost" values to the equivalent value for the new 'from' Lost elements are then set to zero. (This case can only occur for dt.mode relative): months += lost years * 12 ; years = 0 hours += lost days * 24 ; days = 0 minutes += lost hours * 60 ; hours = 0 seconds += lost minutes * 60.0 ; minutes = 0
  • If dt.from > 'from' (adding "lower" elements), the new elements are set to zero.
  • If dt.to < 'to' (adding "higher" elements), the new elements are set to zero.
  • If dt.to > 'to' (losing "higher" elements), the the new 'to' is adjusted according to the value for 'round' After rounding the "lost" elements are set to zero.
Parameters
dt
from
to
round
Returns
int

Definition at line 55 of file change.c.

References DATETIME_DAY, datetime_days_in_year(), DATETIME_HOUR, datetime_increment(), datetime_is_absolute(), datetime_is_valid_type(), DATETIME_MINUTE, DATETIME_MONTH, DATETIME_SECOND, datetime_set_type(), DATETIME_YEAR, DateTime::day, DateTime::fracsec, DateTime::from, DateTime::hour, DateTime::minute, DateTime::mode, DateTime::month, DateTime::positive, DateTime::second, DateTime::to, x, and DateTime::year.

Referenced by datetime_difference(), datetime_get_local_timezone(), and datetime_increment().