README 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743
  1. /****************************************************************************
  2. *
  3. * MODULE: datetime
  4. * AUTHOR(S): Bill Brown <brown gis.uiuc.edu> and Michael Shapiro (CERL)
  5. * (original contributors, 1995)
  6. * Brad Douglas <rez touchofmadness.com>,
  7. * Markus Neteler <neteler itc.it>,
  8. * Bernhard Reiter <bernhard intevation.de>,
  9. * Radim Blazek <radim.blazek gmail.com>
  10. * Glynn Clements <glynn gclements.plus.com>,
  11. * PURPOSE: library for date time structure
  12. * COPYRIGHT: (C) 2002-2007 by the GRASS Development Team
  13. *
  14. * This program is free software under the GNU General Public
  15. * License (>=v2). Read the file COPYING that comes with GRASS
  16. * for details.
  17. *
  18. *****************************************************************************/
  19. Note: The timestamp routines
  20. G_read_grid3_timestamp +
  21. G_remove_grid3_timestamp +
  22. G_write_grid3_timestamp
  23. are stored in src/libes/gis/timestamp.c
  24. (added 3/2001)
  25. ---------------------------------------------------------------------------
  26. This is the DateTime structure
  27. typedef struct {
  28. int mode; /* absolute or relative */
  29. int from, to; /* range of values */
  30. int positive; /* positive/negative datetime */
  31. int year, month, day;
  32. int hour, minute;
  33. double second;
  34. int fracsec; /* #decimal place in printed seconds */
  35. int tz; /* timezone - minutes from UTC */
  36. } DateTime;
  37. DateTimes have a 3-part type consisting of
  38. 'mode' and
  39. range qualifiers 'from' and 'to'
  40. mode: one of
  41. #define DATETIME_TYPE_ABSOLUTE 1
  42. #define DATETIME_TYPE_RELATIVE 2
  43. from, to: one of
  44. #define DATETIME_YEAR 1
  45. #define DATETIME_MONTH 2
  46. #define DATETIME_DAY 3
  47. #define DATETIME_HOUR 4
  48. #define DATETIME_MINUTE 5
  49. #define DATETIME_SECOND 6
  50. The values for the from/to #defines must increase from YEAR to SECOND
  51. In other words YEAR < MONTH < DAY < HOUR < MINUTE < SECOND. The idea
  52. is that the higher elements represent higher precision for a date/time.
  53. For example, having seconds in the time is more precise than if seconds
  54. are not present.
  55. There are some restrictions on legal values for from/to.
  56. 1. from <= to
  57. 2. if the 'mode' is ABSOLUTE, then 'from' must be YEAR
  58. 3. if the 'mode' is RELATIVE, then
  59. 'from' and 'to' in {YEAR,MONTH}
  60. or in
  61. 'from' and 'to' in {DAY,HOUR,MINUTE,SECOND}
  62. year,month,day
  63. hour,minute,second:
  64. These are non-negative values.
  65. For ABSOLUTE types, these must be valid date/time values
  66. year a complete year, all the digits (not just the last 2 digits)
  67. must be positive (since 0 isn't a legal year).
  68. month [1,12]
  69. day [1,n] where n depends on the year/month.
  70. hour [0,23]
  71. minute [0,59]
  72. second [0.0,<60.0]
  73. For RELATIVE types, the value corresponding to 'from' is
  74. unrestricted (except that it can't be negative). The other values
  75. are restricted as follows:
  76. if from==YEAR, month is [0,11]
  77. if from==DAY, hour is [0,23], min is [0,59], sec is [0.0,<60.0]
  78. if from==HOUR, min is [0,59], sec is [0.0,<60.0]
  79. if from==MINUTE, sec is [0.0,<60.0]
  80. fracsec:
  81. This controls the number of decimal places to print after the seconds.
  82. It is only used if the 'to' element is SECOND. It must be non-neagtive.
  83. tz:
  84. The time (hour/minute) in ABSOLUTE types is in local time.
  85. The specification of a timezone (tz) is an (subtractive)
  86. offset to convert from local time to UTC.
  87. To get UTC from localtime: LT - TZ
  88. tz is expressed in minutes from -720 to 780
  89. (720 == 12 hours, 780 minutes == 13 hours).
  90. [See ANSI X3.51-1975, section 2.2.3]
  91. For a timezone to be allowed, the 'to' field must be one of
  92. {MINUTE, SECOND}
  93. positive:
  94. this indicates if the datetime value is to considered
  95. "positive" (!=0) or "negative" (==0)
  96. For mode ABSOLUTE, positive==0 means BC
  97. ----------------------------------------------------
  98. API
  99. (*) Error messages
  100. Guidelines:
  101. All functions that return int status codes should return
  102. 0 (or positive) if OK;
  103. a negative integer if not;
  104. and register the error with a call to datetime_error()
  105. applications can test for error by
  106. if (datetime_function() < 0) {process the error}
  107. int
  108. :+ datetime_error (int code, char *msg)
  109. record 'code' and 'msg' as error code/msg (in static variables)
  110. code==0 will clear the error (ie set msg=NULL)
  111. returns 'code' so that it can be used like:
  112. return datetime_error (-1, "bad date");
  113. char *
  114. :+ datetime_get_error_msg()
  115. returns pointer to static error msg (which is NULL if no error)
  116. int
  117. :+ datetime_get_error_code()
  118. returns error code
  119. void
  120. :+ datetime_clear_error()
  121. clears error code and message
  122. (*) Type:
  123. int
  124. :+ datetime_set_type (DateTime *dt; int mode, from, to, fracsec)
  125. This routine must be called before any use of dt can be made
  126. with other datetime functions
  127. initialize all the elements in dt.
  128. Set all values to zero except
  129. tz (set to illegal value - 99*24)
  130. positive (set to 1 for positive)
  131. Set the type info in dt: mode, from, to, fracsec
  132. validate the mode/from/to/fracsec (according to the rules for the mode)
  133. ie. return the return value from datetime_check_type(dt)
  134. void
  135. :+ datetime_get_type (DateTime *dt; int *mode, *from, *to, *fracsec)
  136. extract the mode, from, to, and fracsec out of dt.
  137. int
  138. :+ datetime_check_type (DateTime *dt)
  139. checks the mode/from/to/fracsec in dt.
  140. returns:
  141. 0: OK
  142. -1: mode is invalid - not one of {ABSOLUTE,RELATIVE}
  143. -2: from is invalid - not one of {YEAR,MONTH,DAY,HOUR,MINUTE,SECOND}
  144. -3: to is invalid - not one of {YEAR,MONTH,DAY,HOUR,MINUTE,SECOND}
  145. -4: from/to are reversed (from>to is illegal)
  146. -5: invalid from/to combination for RELATIVE mode
  147. from in {YEAR,MONTH} but to is not, or
  148. from in {DAY,HOUR,MINUTE,SECOND} but to is not
  149. -6: from is invalid for ABSOLUTE mode (from != YEAR is illegal)
  150. -7: fracsec is negative (only if to==SECOND)
  151. int
  152. :+ datetime_is_valid_type (DateTime *dt)
  153. returns 1 if datetime_check_type() returns 0
  154. 0 if not.
  155. int
  156. :+ datetime_change_from_to (DateTime *dt; int from, to; int round)
  157. change the from/to of the type for dt.
  158. 'dt' must be legal
  159. The 'from/to' must be legal values for the mode of dt;
  160. (if they are not legal, then the original values are preserved,
  161. dt is not changed).
  162. returns 0 OK, -1 invalid 'dt', -2 invalid 'from/to'
  163. round = negative implies floor() [decrease magnitude]
  164. 0 implies normal rounding, [incr/decr magnitude]
  165. positive implies ceil() [increase magnitude]
  166. Rounding up should be implemented using datetime_increment().
  167. If dt.mode is ABSOLUTE, then 'from' must be YEAR.
  168. If dt.from < 'from' (losing "lower" elements), convert the
  169. "lost" values to the equivalent value for the new 'from'
  170. Lost elements are then set to zero.
  171. (This case can only occur for dt.mode relative):
  172. months += lost years * 12 ; years = 0
  173. hours += lost days * 24 ; days = 0
  174. minutes += lost hours * 60 ; hours = 0
  175. seconds += lost minutes * 60.0 ; minutes = 0
  176. If dt.from > 'from' (adding "lower" elements), the new elements
  177. are set to zero.
  178. If dt.to < 'to' (adding "higher" elements), the new elements
  179. are set to zero.
  180. If dt.to > 'to' (losing "higher" elements), the
  181. the new 'to' is adjusted according to the value for 'round'
  182. After rounding the "lost" elements are set to zero.
  183. if 'round' < 0, then no change is made to the lower elements
  184. if 'round' > 0 and if the higher elements are not all zero then
  185. the new 'to' element is incremented by by creating a
  186. relative DateTime 'incr' with from='to' and to='to'
  187. and value 1 then calling datetime_increment(dt,incr)
  188. if round == 0, then if the doubling all higher elements
  189. would cause a carry to occur, then the new 'to'
  190. element is incremented, as follows
  191. create a DateTime will all higher elements
  192. equal to their corresponding elements in 'dt'
  193. and then calling datetime_increment(dt,incr)
  194. int
  195. :+ datetime_is_absolute (DateTime *dt)
  196. Returns
  197. 1 if dt.mode is absolute
  198. 0 if not (even if dt.mode is not defined)
  199. int
  200. :+ datetime_is_relative (DateTime *dt)
  201. Returns
  202. 1 if dt.mode is relative
  203. 0 if not (even if dt.mode is not defined)
  204. (*) Copy
  205. void
  206. :+ datetime_copy (DateTime *dst, *src)
  207. This function copies the 'src' to the 'dst' by
  208. dst "=" src :
  209. dst.from = src.from
  210. dst.to = src.to
  211. ...
  212. (*) Same
  213. int
  214. :+ datetime_is_same (DateTime *dt1, *dt2)
  215. Returns
  216. 1 if dt1 is exactly the same as dt2
  217. 0 if they differ
  218. (*) Ascii
  219. The ascii representation of DateTime is
  220. ABSOLUTE: 15 Jan 1994 [bc] 10:35:23.456 -0500
  221. RELATIVE: [-] 2 years 5 months
  222. [-] 100 days 15 hours 25 minutes 35.34 seconds
  223. The parts can be missing.
  224. ABSOLUTE: 1994 [bc]
  225. Jan 1994 [bc]
  226. 15 jan 1000 [bc]
  227. 15 jan 1994 [bc] 10 [+0000]
  228. 15 jan 1994 [bc] 10:00 [+0100]
  229. 15 jan 1994 [bc] 10:00:23.34 [-0500]
  230. RELATIVE: [-] 2 years
  231. [-] 5 months
  232. [-] 2 years 5 months
  233. [-] 100 days
  234. [-] 15 hours 25 minutes 35.34 seconds
  235. [-] 100 days 25 minutes
  236. [-] 1000 hours 35.34 seconds
  237. etc.
  238. NOTE: values missing between the from/to are assumed to be zero;
  239. when scanning, they can be missing; when formatting they will
  240. appear as 0 (to preserve the from/to):
  241. 1000 hours 0 minutes 35.34 seconds
  242. 0 days 10 hours 0 minutes
  243. NOTE: when scanning the from/to are determined by the fields
  244. present. Compare:
  245. 10 hours 0 minutes 35.34 seconds [from=HOUR,to=SECOND]
  246. and
  247. 0 days 10 hours 0 minutes 35.34 seconds [from=DAY,to=SECOND]
  248. int
  249. :+ datetime_scan (DateTime *dt, char *string)
  250. Convert the ascii string into a DateTime
  251. This determines the mode/from/to based on the string,
  252. inits 'dt' and then sets values in 'dt' based on the
  253. 'string'
  254. Returns 0 if 'string' is legal, -1 if not.
  255. void
  256. :+ datetime_format (DateTime *dt, char *string)
  257. Convert 'dt' to a printable string. 'string' should
  258. be large enough to hold the result, perhaps 80 bytes?
  259. (*) Values
  260. These routines get/set elements of 'dt'. They return
  261. 0 if OK
  262. -1 if the value being gotten or set is not a legal value
  263. -2 if the from/to for 'dt' doesn't include this value
  264. Values don't get set if they are invalid.
  265. int
  266. :+ datetime_check_year (DateTime *dt, int year)
  267. Returns
  268. 0 is legal year for dt
  269. -1 illegal year for this dt
  270. -2 dt has no year component
  271. int
  272. :+ datetime_set_year (DateTime *dt, int year)
  273. if dt.mode = ABSOLUTE, this also sets dt.day = 0
  274. int
  275. :+ datetime_get_year (DateTime *dt, int *year)
  276. int
  277. :+ datetime_check_month (DateTime *dt, int month)
  278. Returns
  279. 0 is legal month for dt
  280. -1 illegal month for this dt
  281. -2 dt has no month component
  282. int
  283. :+ datetime_set_month (DateTime *dt, int month)
  284. if dt.mode = ABSOLUTE, this also sets dt.day = 0
  285. int
  286. :+ datetime_get_month (DateTime *dt, int *month)
  287. int
  288. :+ datetime_check_day (DateTime *dt, int day)
  289. Returns
  290. 0 is legal day for dt
  291. -1 illegal day for this dt
  292. -2 dt has no day component
  293. Note: if dt.mode is ABSOLUTE, then dt.year and dt.month
  294. must also be legal, since the 'day' must be a legal
  295. value for the dt.year/dt.month
  296. int
  297. :+ datetime_set_day (DateTime *dt, int day)
  298. if dt.mode = ABSOLUTE, then
  299. 'day' must be less than or equal to the number of days in
  300. the dt.year,dt.month:
  301. if (day > datetime_days_in_month (dt.year, dt.month))
  302. {error}
  303. This implies that year/month must be set before days for
  304. ABSOLUTE datetimes.
  305. int
  306. :+ datetime_get_day (DateTime *dt, int *day)
  307. int
  308. :+ datetime_check_hour (DateTime *dt, int hour)
  309. int
  310. :+ datetime_set_hour (DateTime *dt, int hour)
  311. int
  312. :+ datetime_get_hour (DateTime *dt, int *hour)
  313. int
  314. :+ datetime_check_minute (DateTime *dt, int minute)
  315. int
  316. :+ datetime_set_minute (DateTime *dt, int minute)
  317. int
  318. :+ datetime_get_minute (DateTime *dt, int *minute)
  319. int
  320. :+ datetime_check_second (DateTime *dt, double second)
  321. int
  322. :+ datetime_set_second (DateTime *dt, double second)
  323. int
  324. :+ datetime_get_second (DateTime *dt, double *second)
  325. int
  326. :+ datetime_check_fracsec (DateTime *dt, int fracsec)
  327. int
  328. :+ datetime_set_fracsec (DateTime *dt, int fracsec)
  329. int
  330. :+ datetime_get_fracsec (DateTime *dt, int *fracsec)
  331. (*) Arithmetic
  332. These functions perform addition/subtraction on datetimes.
  333. int
  334. : datetime_increment (DateTime *src, *incr)
  335. this function changes the 'src' date/time data based on the 'incr'
  336. The type (mode/from/to) of the 'src' can be anything.
  337. The mode of the 'incr' must be RELATIVE,
  338. and the type (mode/from/to) for 'incr' must be a valid increment
  339. for 'src'. See datetime_is_valid_increment(), datetime_check_increment()
  340. returns
  341. 0: OK
  342. -1: 'incr' is invalid increment for 'src'
  343. -2: 'src' is ABSOLUTE, 'incr' is a {DAY-SECOND} interval
  344. and 'src' is a date for which this function
  345. has not been implemented. NOTE: this should only happen
  346. if the total number of days in the 'src' would exceed 28
  347. since this would then cause date arithemtic to kick in
  348. to figure out if these are too many days for the month.
  349. ## BROWN - identify which dates you know how to handle, and which you do not.
  350. For src.mode ABSOLUTE,
  351. positive 'incr' moves into the future,
  352. negative 'incr' moves into the past.
  353. BC implies the year is negative, but all else is positive.
  354. Suppose the date is 10jan100bc.
  355. To add 1 year would decrease the year to 99 (10jan99bc).
  356. To increase the day by 1 would set the day to 11 (11jan100bc).
  357. To increase the month by 1 would change the month from 1 (jan)
  358. to 2 (feb) (10feb100bc)
  359. Also, year==0 is illegal: adding 1 year to 1[bc] gives 1[ad]
  360. For src.mode RELATIVE
  361. Incrementing or decrementing must consider the 'src' and 'incr'
  362. as single values (+ or -) and work with this value.
  363. For example, suppose
  364. A = -4 days, 5 hours, 15 minutes
  365. B = 25 hours
  366. then
  367. A = -(4*24*60 +5*60+15) = -6075
  368. B = (25*60) = 1500
  369. A + B = -4575 = -(3*24*60 + 4*60 + 15)
  370. A = -3 days, 4 hours, 15 minutes
  371. The 'fracsec' in 'src' is preserved.
  372. The 'from/to' of the 'src' is preserved.
  373. A timezone in 'src' is allowed - it's presence is ignored.
  374. NOTE: There is no datetime_decrement()
  375. To decrement, set the 'incr' negative.
  376. void
  377. :+ datetime_set_positive (DateTime *dt)
  378. void
  379. :+ datetime_set_negative (DateTime *dt)
  380. void
  381. :+ datetime_invert_sign (DateTime *dt)
  382. int
  383. :+ datetime_is_positive (DateTime *dt)
  384. these control the "sign" of the datetime value.
  385. int
  386. : datetime_difference (DateTime *a, *b, *result)
  387. This performs the formula: result = a - b;
  388. both a and b must be absolute.
  389. result will be relative
  390. If a is "earlier" than b, then result should be set negative.
  391. b must be no more "precise" than a.
  392. (a copy of b is "extended" to the precision of a)
  393. datetime_copy (tb, b)
  394. datetime_reset_from_to (tb, b.from, a.to, a.fracsec))
  395. If result.to == SECOND, then result.fracsec is a.fracsec
  396. result will have the following from/to based on a.to:
  397. result
  398. a.to from to
  399. YEAR YEAR YEAR
  400. MONTH YEAR MONTH
  401. DAY DAY DAY
  402. HOUR DAY HOUR
  403. MINUTE DAY MINUTE
  404. SECOND DAY SECOND
  405. If either 'a' or 'b' has a timezone, both must have a timezone.
  406. The difference will account for the differences in the time zones.
  407. int
  408. :+ datetime_is_valid_increment (DateTime *src, *incr)
  409. Returns
  410. datetime_check_increment(src, incr) == 0
  411. int
  412. :+ datetime_check_increment (DateTime *src, *incr)
  413. This checks if the type of 'incr' is valid for
  414. incrementing/decrementing 'src'.
  415. Returns:
  416. 1 src is not a legal DateTime, error code/msg
  417. are those set by datetime_is_valid_type()
  418. 2 incr is not a legal DateTime, error code/msg
  419. are those set by datetime_is_valid_type()
  420. -1 incr.mode not relative
  421. -2 incr more precise that src
  422. -3 illegal incr, must be YEAR-MONTH
  423. -4 illegal incr, must be DAY-SECOND
  424. The type (mode/from/to) of the 'src' can be anything.
  425. The incr.mode must be RELATIVE
  426. (return -1 if not)
  427. incr.to is restricted based on the src.to:
  428. incr.to <= src.to (incr not more precise than src)
  429. (return -2 if not)
  430. if src.to is in {YEAR,MONTH} then
  431. incr.to must be in {YEAR,MONTH}
  432. (return -3 if not)
  433. if src.to is in {DAY,HOUR,MINUTE,SECOND} then
  434. incr.to must be in {DAY,HOUR,MINUTE,SECOND}
  435. (return -4 if not)
  436. note: it is ok for incr.from > src.from
  437. (which can only happen for src.mode RELATIVE).
  438. A timezone in 'src' is allowed - it's presence is ignored.
  439. To aid in setting the 'incr' type, the following routine can be used
  440. int
  441. :+ datetime_get_increment_type (DateTime *src; int *mode, *from, *to, *fracsec)
  442. this returns the components of a type (mode/from/to/fracsec) that
  443. can be used to construct a DateTime object that can be used
  444. to increment the 'src'. See datetime_set_increment_type().
  445. returns 0 dt is legal
  446. !=0 why dt is illegal
  447. Implemented as follows:
  448. *mode = RELATIVE
  449. *to = src.to
  450. *fracsec = src.fracsec
  451. if src.mode is ABSOLUTE
  452. if src.to is in {YEAR,MONTH} then
  453. *from = YEAR
  454. if src.to is in {DAY,HOUR,MINUTE,SECOND} then
  455. *from = DAY
  456. if src.mode is RELATIVE, then
  457. *from = src.from
  458. int
  459. :+ datetime_set_increment_type (DateTime *src, *incr)
  460. src must be legal
  461. This is a convience routine which is implemented as follows:
  462. int mode, from ,to;
  463. int fracsec;
  464. if(datetime_get_increment_type (src, &mode, &from, &to, &fracsec))
  465. return datetime_error_cde();
  466. return datetime_set_type (incr, mode, from, to, fracsec);
  467. (*) Misc
  468. int
  469. :+ datetime_days_in_month (int month, year)
  470. int
  471. :+ datetime_is_leap_year (int year)
  472. int
  473. :+ datetime_days_in_year (int year)
  474. (*) Timezone
  475. int
  476. :+ datetime_is_valid_timezone (int minutes)
  477. returns:
  478. 1 OK: -720 <= minutes <= 780 (720 = 12 hours; 780 = 13 hours)
  479. 0 NOT OK
  480. int
  481. :+ datetime_check_timezone (DateTime *dt, int minutes)
  482. 'dt' must be mode ABSOLUTE and dt.to must be one of {MINUTE,SECOND}
  483. minutes must be a valid timezone offset: ie in the range [-720,+780]
  484. return
  485. 0: OK
  486. -1: mode not ABSOLUTE
  487. -2: dt.to not in {MINUTE,SECOND}
  488. -3: minutes not valid - not in the range [-720,+780]
  489. int
  490. :+ datetime_set_timezone (DateTime *dt, int minutes)
  491. if (datetime_check_timezone(dt,minutes)==0)
  492. set dt.tz=minutes
  493. 'dt' must be mode ABSOLUTE and dt.to must be one of {MINUTE,SECOND}
  494. minutes must be a valid timezone offset: ie in the range [-720,+780]
  495. return
  496. 0: OK
  497. -1: mode not ABSOLUTE
  498. -2: dt.to not in {MINUTE,SECOND}
  499. -3: minutes not valid - not in the range [-720,+780]
  500. int
  501. :+ datetime_get_timezone (DateTime *dt, int *minutes)
  502. return
  503. 0: OK - if 'dt' has a timezone and sets 'minutes'
  504. -1: mode not ABSOLUTE
  505. -2: dt.to not in {MINUTE,SECOND}
  506. -3: minutes not valid - not in the range [-720,+780]
  507. void
  508. :+ datetime_unset_timezone (DateTime *dt)
  509. Remove timezone from 'dt'
  510. dt.tz = 99*60 (some illegal value)
  511. int
  512. :+ datetime_change_timezone (DateTime *dt; int minutes)
  513. if dt has a timezone,
  514. increment dt by minutes-dt.tz MINUTES
  515. set dt.tz = minutes
  516. returns 0 OK, datetime_check_timezone(dt) if not,
  517. or -4 if minues invalid
  518. int
  519. :+ datetime_change_to_utc (DateTime *dt)
  520. return datetime_change_timezone (dt, 0);
  521. void
  522. :+ datetime_decompose_timezone (int tz, int *hour, int *minute)
  523. tz = abs(tz)
  524. *hour = tz/60
  525. *minute = tz%60
  526. note: hour,minute are non-negative. Must look at sign of tz
  527. itself to see if the tz is negative offset or not. This routine
  528. would be used to format tz for output. For example if tz=-350
  529. this would be hour=5 minute=50, but negative. Output might econde
  530. this as -0550: printf ("%s%02d%02d", tz<0?"-":"", hour, minute)
  531. (*) A function that returns the timezone for the local system??
  532. int
  533. :+ datetime_get_local_timezone (int *minutes)
  534. returns 0 OK, -1 local timezone info not available
  535. (*) Local time
  536. void
  537. :+ datetime_get_local_time (DateTime *dt)
  538. set mode/from/to ABSOLUTE/YEAR/SECOND
  539. set the local time into 'dt'
  540. does not set timezone.
  541. (*) GRASS will probably have to have a function that returns the
  542. timezone of the database:
  543. ### BROWN
  544. ## so a database only has one timezone? Or can each map have its own?
  545. ### SHAPIRO
  546. ## good question. A location may span more than one time zone. Also timezones
  547. ## are not nice shapes. We probably need a function that returns a timezone
  548. ## for a specified latlon/longitude and/or for a region. How would this
  549. ## function deal with daylight savings time?
  550. ## The timezone(s) might have to be represented as a vector map
  551. ## I suggest we hold off on this and add it later.
  552. G_get_database_timezone (int *tz)
  553. tz in minutes as defined for datetime library
  554. returns
  555. 0 database has no timezone
  556. 1 database has a timezone - returned in tz
  557. -1 error reading timezone file.