GRASS GIS 8 Programmer's Manual  8.5.0dev(2024)-57a646b4a4
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

◆ datetime_change_from_to()

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 54 of file change.c.

Referenced by datetime_get_local_timezone(), and datetime_increment().