GRASS Programmer's Manual
6.4.2(2012)
Main Page
Related Pages
Namespaces
Data Structures
Files
File List
Globals
All
Data Structures
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Macros
Pages
local.c
Go to the documentation of this file.
1
/*
2
* Copyright (C) 1995. Bill Brown <brown@gis.uiuc.edu> & Michael Shapiro
3
*
4
* This program is free software under the GPL (>=v2)
5
* Read the file GPL.TXT coming with GRASS for details.
6
*/
7
#include <time.h>
8
#include <grass/datetime.h>
9
10
extern
struct
tm *
localtime
();
11
extern
struct
tm *
gmtime
();
12
13
/*
14
** NOTE: the extern variable "timezone" seems to be treated
15
** differently by different OS, and the tm_zone element of struct tm
16
** is missing in some OS (IRIX), so we're converting localtime() and
17
** gmtime() structures to datetimes, then doing a difference to get the
18
** timezone offset. -Bill Brown 5/31/95
19
*/
20
21
33
int
datetime_get_local_timezone
(
int
*minutes)
34
{
35
struct
tm *local, *gm;
36
time_t clock;
37
DateTime dtl, dtg, dtdiff;
38
39
time(&clock);
40
41
local =
localtime
(&clock);
42
43
datetime_set_type
(&dtl, DATETIME_ABSOLUTE, DATETIME_YEAR, DATETIME_SECOND,
44
0);
45
46
/* now put current {year,month,day,hour,minute,second} into local */
47
datetime_set_year
(&dtl, (
int
)local->tm_year + 1900);
48
datetime_set_month
(&dtl, (
int
)local->tm_mon + 1);
49
datetime_set_day
(&dtl, (
int
)local->tm_mday);
50
datetime_set_hour
(&dtl, (
int
)local->tm_hour);
51
datetime_set_minute
(&dtl, (
int
)local->tm_min);
52
datetime_set_second
(&dtl, (
double
)local->tm_sec);
53
54
gm =
gmtime
(&clock);
55
56
datetime_set_type
(&dtg, DATETIME_ABSOLUTE, DATETIME_YEAR, DATETIME_SECOND,
57
0);
58
59
/* now put current {year,month,day,hour,minute,second} into gmt */
60
datetime_set_year
(&dtg, (
int
)gm->tm_year + 1900);
61
datetime_set_month
(&dtg, (
int
)gm->tm_mon + 1);
62
datetime_set_day
(&dtg, (
int
)gm->tm_mday);
63
datetime_set_hour
(&dtg, (
int
)gm->tm_hour);
64
datetime_set_minute
(&dtg, (
int
)gm->tm_min);
65
datetime_set_second
(&dtg, (
double
)gm->tm_sec);
66
67
datetime_set_type
(&dtdiff, DATETIME_RELATIVE,
68
DATETIME_DAY, DATETIME_SECOND, 0);
69
datetime_difference
(&dtl, &dtg, &dtdiff);
70
datetime_change_from_to
(&dtdiff, DATETIME_MINUTE, DATETIME_MINUTE, 0);
71
72
*minutes = dtdiff.positive ? dtdiff.minute : -dtdiff.minute;
73
return
0;
74
}
75
76
87
void
datetime_get_local_time
(DateTime * dt)
88
{
89
time_t clock;
90
struct
tm *local;
91
92
/* first set dt to absolute full date */
93
datetime_set_type
(dt, DATETIME_ABSOLUTE, DATETIME_YEAR, DATETIME_SECOND,
94
0);
95
96
/* get the current date/time */
97
time(&clock);
98
local =
localtime
(&clock);
99
100
/* now put current {year,month,day,hour,minute,second} into dt */
101
datetime_set_year
(dt, (
int
)local->tm_year + 1900);
102
datetime_set_month
(dt, (
int
)local->tm_mon + 1);
103
datetime_set_day
(dt, (
int
)local->tm_mday);
104
datetime_set_hour
(dt, (
int
)local->tm_hour);
105
datetime_set_minute
(dt, (
int
)local->tm_min);
106
datetime_set_second
(dt, (
double
)local->tm_sec);
107
}
lib
datetime
local.c
Generated on Sun Sep 9 2012 18:55:33 for GRASS Programmer's Manual by
1.8.1.2