openbase 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +50 -0
- data/License.txt +20 -0
- data/Manifest.txt +53 -0
- data/README.txt +35 -0
- data/Rakefile +126 -0
- data/examples/example.rb +37 -0
- data/ext/CommAPI.c +643 -0
- data/ext/Headers/CommAPI.h +1 -0
- data/ext/Headers/NetClient.h +42 -0
- data/ext/Headers/NetClientLib.h +41 -0
- data/ext/Headers/OB_Memory.h +69 -0
- data/ext/Headers/OpenBaseAdmin.h +227 -0
- data/ext/Headers/OpenBaseConnection.h +337 -0
- data/ext/Headers/OpenBaseEncoding.h +302 -0
- data/ext/Headers/OpenBasePrepare.h +1 -0
- data/ext/Headers/OpenBaseSupport.h +1 -0
- data/ext/Headers/Platform_Carbon_Header.h +5 -0
- data/ext/Headers/Platform_Classic_Header.h +6 -0
- data/ext/Headers/Platform_Linux.h +4 -0
- data/ext/Headers/Platform_Mach_Header.h +4 -0
- data/ext/Headers/Platform_Windows.h +3 -0
- data/ext/Headers/conversion.h +1 -0
- data/ext/Headers/datetime.h +26 -0
- data/ext/Headers/longlong.h +46 -0
- data/ext/Headers/platform.h +67 -0
- data/ext/Headers/stringConversion.h +15 -0
- data/ext/NetClient.c +888 -0
- data/ext/OpenBaseAdmin.c +1884 -0
- data/ext/OpenBaseConnection.c +1841 -0
- data/ext/OpenBaseEncoding.c +993 -0
- data/ext/OpenBaseEncoding_DOS.c +1 -0
- data/ext/OpenBaseEncoding_ISO8859.c +1 -0
- data/ext/OpenBaseEncoding_MacOS.c +1 -0
- data/ext/OpenBaseEncoding_Windows.c +1150 -0
- data/ext/OpenBasePrepare.c +1 -0
- data/ext/OpenBaseSupport.c +1 -0
- data/ext/conversion.c +1 -0
- data/ext/datetime.c +816 -0
- data/ext/depend +1 -0
- data/ext/extconf.rb +10 -0
- data/ext/longlong.c +1 -0
- data/ext/openbase.c +980 -0
- data/ext/stringConversion.c +169 -0
- data/lib/ruby-openbase/version.rb +9 -0
- data/scripts/txt2html +67 -0
- data/setup.rb +1585 -0
- data/test/test_helper.rb +2 -0
- data/test/test_openbase.rb +241 -0
- data/website/index.html +114 -0
- data/website/index.txt +59 -0
- data/website/javascripts/rounded_corners_lite.inc.js +285 -0
- data/website/stylesheets/screen.css +133 -0
- data/website/template.rhtml +47 -0
- metadata +105 -0
@@ -0,0 +1 @@
|
|
1
|
+
// ------------------------------------------------------------------------------
|
2
|
int paramCount = 0;
|
1
3
|
int position = 0;
|
2
4
|
char *tostring;
|
3
5
|
int tosize;
|
4
6
|
int isDone = 0;
|
5
7
|
int ct;
|
6
8
|
for (ct = 0; conn->preparedSQL[ct] != NULL; ct++)
|
7
9
|
{
|
8
10
|
// free(conn->preparedSQL[ct]);
|
9
11
|
ob_free(conn->preparedSQL[ct]);
|
10
12
|
conn->preparedSQL[ct] = NULL;
|
11
13
|
}
|
12
14
|
while (1)
|
13
15
|
{
|
14
16
|
// tostring = (char *)malloc(100);
|
15
17
|
tostring = (char *)ob_malloc(100);
|
16
18
|
tosize = 100;
|
17
19
|
// position = position + copyToIndex( &tostring, &tosize, position,
|
18
20
|
// sqlstring, '?', &isDone) + 1;
|
19
21
|
position = position + copyToIndex_smart( &tostring, &tosize, position,
|
20
22
|
sqlstring, '?', &isDone) + 1;
|
21
23
|
conn->preparedSQL[paramCount] = tostring;
|
22
24
|
if (isDone) break;
|
23
25
|
paramCount = paramCount + 1;
|
24
26
|
conn->preparedSQL[paramCount+1] = NULL;
|
25
27
|
conn->numberOfPreparedValues = paramCount;
|
26
28
|
conn->prepareValuePosition= 0;
|
27
29
|
return paramCount;
|
28
30
|
return -1;
|
29
31
|
// free(conn->preparedSQL[ct]);
|
30
32
|
ob_free(conn->preparedSQL[ct]);
|
31
33
|
conn->preparedSQL[ct] = NULL;
|
32
34
|
// tostring = (char *)malloc(100);
|
33
35
|
tostring = (char *)ob_malloc(100);
|
34
36
|
tosize = 100;
|
35
37
|
position = position + copyToIndex(&tostring, &tosize, position, sqlstring, '?', &isDone) + 1;
|
36
38
|
conn->preparedSQL[paramCount] = tostring;
|
37
39
|
if (isDone) break;
|
38
40
|
paramCount = paramCount + 1;
|
39
41
|
|
40
42
|
//printf("ob_preparedValue = <%s> <%s>\n", conn->preparedSQL[conn->prepareValuePosition], sqlValue);
|
41
43
|
|
42
44
|
ob_makeCommand(conn, conn->preparedSQL[conn->prepareValuePosition]);
|
43
45
|
ob_makeCommand(conn, sqlValue);
|
44
46
|
conn->prepareValuePosition = conn->prepareValuePosition + 1;
|
45
47
|
return conn->prepareValuePosition;
|
46
48
|
return conn->numberOfPreparedValues;
|
47
49
|
if (conn->prepareValuePosition != conn->numberOfPreparedValues) {
|
48
50
|
return -1;
|
49
51
|
}
|
50
52
|
//printf("ob_preparedExecute = <%s> \n", conn->preparedSQL[conn->prepareValuePosition]);
|
51
53
|
ob_makeCommand(conn, conn->preparedSQL[conn->prepareValuePosition]);
|
52
54
|
if(!ob_executeCommand(conn)) {
|
53
55
|
return -1;
|
54
56
|
}
|
55
57
|
//conn->prepareValuePosition = 0;
|
56
58
|
return ob_rowsAffected(conn);
|
@@ -0,0 +1 @@
|
|
1
|
+
// ------------------------------------------------------------------------------
|
2
|
int ct = 0;
|
1
3
|
char *deststr, *sourcestr;
|
2
4
|
if (!array[0] || (*maxinit == 0)) {
|
3
5
|
array[0] = (char *)ob_malloc(copyIntoArray_ITEM_SIZE);
|
4
6
|
if (*maxinit == 0) *maxinit = 1;
|
5
7
|
}
|
6
8
|
//printf("copyIntoArray -> %s\n", values);
|
7
9
|
|
8
10
|
deststr = array[0];
|
9
11
|
sourcestr = values;
|
10
12
|
while (*sourcestr!='\0') {
|
11
13
|
if (*sourcestr == '|') {
|
12
14
|
*deststr = '\0';
|
13
15
|
ct = ct + 1;
|
14
16
|
if (!array[ct] || (*maxinit <= ct)) {
|
15
17
|
array[ct] = (char *)ob_malloc(copyIntoArray_ITEM_SIZE);
|
16
18
|
if (*maxinit <= ct) *maxinit = *maxinit + 1;
|
17
19
|
}
|
18
20
|
deststr = array[ct];
|
19
21
|
} else {
|
20
22
|
*deststr = *sourcestr; deststr++;
|
21
23
|
}
|
22
24
|
sourcestr = sourcestr + 1;
|
23
25
|
}
|
24
26
|
*deststr = '\0';
|
25
27
|
ct = ct + 1;
|
26
28
|
return ct;
|
27
29
|
int ct = 0;
|
28
30
|
char *deststr, *sourcestr;
|
29
31
|
if (!array[0])
|
30
32
|
{
|
31
33
|
// array[0] = (char *)malloc(64);
|
32
34
|
array[0] = (char *)ob_malloc(64);
|
33
35
|
}
|
34
36
|
//printf("copyIntoArray -> %s\n", values);
|
35
37
|
|
36
38
|
deststr = array[0];
|
37
39
|
sourcestr = values;
|
38
40
|
while (*sourcestr!='\0') {
|
39
41
|
if (*sourcestr == '|') {
|
40
42
|
*deststr = '\0';
|
41
43
|
ct = ct + 1;
|
42
44
|
if (!array[ct]) {
|
43
45
|
// array[ct] = (char *)malloc(64);
|
44
46
|
array[ct] = (char *)ob_malloc(64);
|
45
47
|
}
|
46
48
|
deststr = array[ct];
|
47
49
|
} else {
|
48
50
|
*deststr = *sourcestr; deststr++;
|
49
51
|
}
|
50
52
|
sourcestr = sourcestr + 1;
|
51
53
|
}
|
52
54
|
*deststr = '\0';
|
53
55
|
ct = ct + 1;
|
54
56
|
return ct;
|
55
57
|
int ct = 0;
|
56
58
|
char *strdest;
|
57
59
|
int newlength;
|
58
60
|
newlength = 0;
|
59
61
|
strdest = (char*)*tostring + position;
|
60
62
|
while (ct < length) {
|
61
63
|
if (*str == '\0')
|
62
64
|
{
|
63
65
|
*strdest = '\\';
|
64
66
|
*(strdest+1) = '0';
|
65
67
|
strdest += 2;
|
66
68
|
newlength += 2;
|
67
69
|
}
|
68
70
|
else
|
69
71
|
{
|
70
72
|
if ((newlength + position) > (*tosize - 5)) {
|
71
73
|
char *temp = NULL;
|
72
74
|
|
73
75
|
*tosize = *tosize * 2;
|
74
76
|
// reallocate the buffer
|
75
77
|
// temp = (char *)malloc(*tosize);
|
76
78
|
temp = (char *)ob_malloc(*tosize);
|
77
79
|
copyBytes((char *) temp, (char*) *tostring, (newlength + position));
|
78
80
|
// free(*tostring);
|
79
81
|
ob_free(*tostring);
|
80
82
|
*tostring = (unsigned char *)temp;
|
81
83
|
|
82
84
|
// setup new strdest
|
83
85
|
strdest = (char*)*tostring + newlength + position;
|
84
86
|
}
|
85
87
|
ct++; str++;
|
86
88
|
}
|
87
89
|
*strdest = '\0';
|
88
90
|
return newlength;
|
89
91
|
int ct = 0;
|
90
92
|
char *strdest;
|
91
93
|
int newlength;
|
92
94
|
newlength = 0;
|
93
95
|
*isDone = 0;
|
94
96
|
strdest = *tostring;
|
95
97
|
str = str + position;
|
96
98
|
while (tochar != *str) {
|
97
99
|
if (*str == '\0') {
|
98
100
|
*isDone = 1;
|
99
101
|
break;
|
100
102
|
}
|
101
103
|
*strdest = *str; strdest++; newlength++;
|
102
104
|
if (newlength > (*tosize - 5)) {
|
103
105
|
char *temp = NULL;
|
104
106
|
*tosize = *tosize * 2;
|
105
107
|
// reallocate the buffer
|
106
108
|
// temp = (char *)malloc(*tosize);
|
107
109
|
temp = (char *)ob_malloc(*tosize);
|
108
110
|
copyBytes((char *) temp, (char*) *tostring, newlength);
|
109
111
|
// free(*tostring);
|
110
112
|
ob_free(*tostring);
|
111
113
|
*tostring = (char *)temp;
|
112
114
|
strdest = *tostring + newlength;
|
113
115
|
}
|
114
116
|
ct++; str++;
|
115
117
|
}
|
116
118
|
*strdest = '\0';
|
117
119
|
return newlength;
|
118
120
|
int ct = 0;
|
119
121
|
char *strdest;
|
120
122
|
int newlength;
|
121
123
|
int state = kState_Outside;
|
122
124
|
newlength = 0;
|
123
125
|
*isDone = 0;
|
124
126
|
strdest = *tostring;
|
125
127
|
str = str + position;
|
126
128
|
|
127
129
|
while (state != kState_Found)
|
128
130
|
{
|
129
131
|
if (*str == '\0')
|
130
132
|
{
|
131
133
|
*isDone = 1;
|
132
134
|
break;
|
133
135
|
}
|
134
136
|
|
135
137
|
switch (state)
|
136
138
|
{
|
137
139
|
case kState_Outside:
|
138
140
|
if (*str == '\'') state = kState_Inside;
|
139
141
|
else if (*str == tochar) state = kState_Found;
|
140
142
|
else state = kState_Outside;
|
141
143
|
break;
|
142
144
|
|
143
145
|
case kState_Inside:
|
144
146
|
if (*str == '\'') state = kState_InsideQuote;
|
145
147
|
else if (*str == '\\') state = kState_InsideBackslash;
|
146
148
|
else state = kState_Inside;
|
147
149
|
break;
|
148
150
|
|
149
151
|
case kState_InsideBackslash:
|
150
152
|
state = kState_Inside;
|
151
153
|
break;
|
152
154
|
|
153
155
|
case kState_InsideQuote:
|
154
156
|
if (*str == '\'') state = kState_Inside;
|
155
157
|
else state = kState_Outside;
|
156
158
|
break;
|
157
159
|
}
|
158
160
|
|
159
161
|
if (state != kState_Found)
|
160
162
|
{
|
161
163
|
}
|
162
164
|
}
|
163
165
|
|
164
166
|
/*
|
165
167
|
while (tochar != *str) {
|
166
168
|
if (*str == '\0') {
|
167
169
|
*isDone = 1;
|
168
170
|
break;
|
169
171
|
}
|
170
172
|
*strdest = *str; strdest++; newlength++;
|
171
173
|
if (newlength > (*tosize - 5)) {
|
172
174
|
char *temp = NULL;
|
173
175
|
*tosize = *tosize * 2;
|
174
176
|
// reallocate the buffer
|
175
177
|
// temp = (char *)malloc(*tosize);
|
176
178
|
temp = (char *)ob_malloc(*tosize);
|
177
179
|
copyBytes((char *) temp, (char*) *tostring, newlength);
|
178
180
|
// free(*tostring);
|
179
181
|
ob_free(*tostring);
|
180
182
|
*tostring = (char *)temp;
|
181
183
|
strdest = *tostring + newlength;
|
182
184
|
}
|
183
185
|
ct++; str++;
|
184
186
|
}
|
185
187
|
*/
|
186
188
|
|
187
189
|
*strdest = '\0';
|
188
190
|
return newlength;
|
189
191
|
int ct;
|
190
192
|
|
191
193
|
for (ct = 0; ct < size; ct++) {
|
192
194
|
*destination = *source;
|
193
195
|
destination++; source++;
|
194
196
|
}
|
195
197
|
return 1;
|
data/ext/conversion.c
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
// ------------------------------------------------------------------------------
|
2
|
int mm,hh;
|
1
3
|
char am_pm[5];
|
2
4
|
if (str[0]=='\0') {
|
3
5
|
return str;
|
4
6
|
}
|
5
7
|
hh=atoi(&str[1]);
|
6
8
|
mm=atoi(&str[4]);
|
7
9
|
switch(formatType) {
|
8
10
|
case '1':
|
9
11
|
sprintf(str,"%02d:%02d",hh,mm);
|
10
12
|
break;
|
11
13
|
default:
|
12
14
|
if ((hh>11) && (hh<24)) {
|
13
15
|
if (hh>12) hh=hh-12;
|
14
16
|
strcpy(am_pm,"pm");
|
15
17
|
} else {
|
16
18
|
strcpy(am_pm,"am");
|
17
19
|
if (hh==0) hh=12;
|
18
20
|
}
|
19
21
|
sprintf(str,"%d:%02d %s",hh,mm,am_pm);
|
20
22
|
break;
|
21
23
|
}
|
22
24
|
return str;
|
23
25
|
int mm,dd,yy;
|
24
26
|
char amonth[10];
|
25
27
|
if (strcmp(str,"")==0) return str;
|
26
28
|
if (str[0]!='@') return str;
|
27
29
|
yy=atoi(&str[1]);
|
28
30
|
mm=atoi(&str[6]);
|
29
31
|
dd=atoi(&str[9]);
|
30
32
|
switch(formatType) {
|
31
33
|
case 2:
|
32
34
|
sprintf(str,"%02d-%02d-%4d", mm, dd, yy);
|
33
35
|
break;
|
34
36
|
case 3:
|
35
37
|
sprintf(str,"%02d/%02d/%4d", mm, dd, yy);
|
36
38
|
break;
|
37
39
|
case 4:
|
38
40
|
sprintf(str,"%d.%d.%4d", dd, mm, yy);
|
39
41
|
break;
|
40
42
|
default:
|
41
43
|
switch(mm)
|
42
44
|
{
|
43
45
|
case 1:
|
44
46
|
strcpy(amonth,"Jan");
|
45
47
|
break;
|
46
48
|
case 2:
|
47
49
|
strcpy(amonth,"Feb");
|
48
50
|
break;
|
49
51
|
case 3:
|
50
52
|
strcpy(amonth,"Mar");
|
51
53
|
break;
|
52
54
|
case 4:
|
53
55
|
strcpy(amonth,"Apr");
|
54
56
|
break;
|
55
57
|
case 5:
|
56
58
|
strcpy(amonth,"May");
|
57
59
|
break;
|
58
60
|
case 6:
|
59
61
|
strcpy(amonth,"Jun");
|
60
62
|
break;
|
61
63
|
case 7:
|
62
64
|
strcpy(amonth,"Jul");
|
63
65
|
break;
|
64
66
|
case 8:
|
65
67
|
strcpy(amonth,"Aug");
|
66
68
|
break;
|
67
69
|
case 9:
|
68
70
|
strcpy(amonth,"Sep");
|
69
71
|
break;
|
70
72
|
case 10:
|
71
73
|
strcpy(amonth,"Oct");
|
72
74
|
break;
|
73
75
|
case 11:
|
74
76
|
strcpy(amonth,"Nov");
|
75
77
|
break;
|
76
78
|
case 12:
|
77
79
|
strcpy(amonth,"Dec");
|
78
80
|
break;
|
79
81
|
}
|
80
82
|
if (formatType == 1) {
|
81
83
|
sprintf(str,"%d %s %d",dd,amonth,yy);
|
82
84
|
} else {
|
83
85
|
sprintf(str,"%s %d, %d",amonth,dd,yy);
|
84
86
|
}
|
85
87
|
break;
|
86
88
|
}
|
87
89
|
return str;
|
88
90
|
if (ioDateTime != NULL)
|
89
91
|
{
|
90
92
|
if ((ns_date_time_ll_string != NULL) && (date_time_string != NULL))
|
91
93
|
{
|
92
94
|
}
|
93
95
|
|
94
96
|
struct tm* utc;
|
95
97
|
time_t cur_t;
|
96
98
|
time_t utc_t;
|
97
99
|
// offset to gmt
|
98
100
|
cur_t = time(NULL);
|
99
101
|
utc = gmtime(&cur_t);
|
100
102
|
utc_t = mktime(utc);
|
101
103
|
result = (long) difftime(cur_t, utc_t);
|
102
104
|
if ((utc != NULL) && (utc->tm_isdst > 0))
|
103
105
|
{
|
104
106
|
result += 60 * 60;
|
105
107
|
}
|
data/ext/datetime.c
ADDED
@@ -0,0 +1,816 @@
|
|
1
|
+
// ------------------------------------------------------------------------------
|
2
|
+
//
|
3
|
+
// Copyright (c) 1996-2006 OpenBase International Ltd.
|
4
|
+
// All rights reserved.
|
5
|
+
//
|
6
|
+
// ------------------------------------------------------------------------------
|
7
|
+
#include "platform.h"
|
8
|
+
|
9
|
+
#include <stdio.h>
|
10
|
+
#include <math.h>
|
11
|
+
#include <stdlib.h>
|
12
|
+
#include <string.h>
|
13
|
+
|
14
|
+
#ifdef WINNT
|
15
|
+
#include <windows.h>
|
16
|
+
#include <time.h>
|
17
|
+
#endif
|
18
|
+
|
19
|
+
#if MACOSX_CARBON
|
20
|
+
#include <time.h>
|
21
|
+
#include <DateTimeUtils.h>
|
22
|
+
#include <UTCUtils.h>
|
23
|
+
#endif
|
24
|
+
|
25
|
+
#if MACOSX_UNIX || WINNT || LINUX || SOLARIS || RHAPSODY
|
26
|
+
#include <sys/time.h>
|
27
|
+
#endif
|
28
|
+
|
29
|
+
#include "datetime.h"
|
30
|
+
|
31
|
+
/*
|
32
|
+
// Not used, but interesting nonetheless
|
33
|
+
#ifdef WINNT
|
34
|
+
#define NSTimeIntervalSince1601 12622780800.0
|
35
|
+
|
36
|
+
int gettimeofday (struct timeval *tvp, struct timezone *tzp)
|
37
|
+
{
|
38
|
+
if (tzp) {
|
39
|
+
TIME_ZONE_INFORMATION tzinfo;
|
40
|
+
DWORD tzresult = GetTimeZoneInformation(&tzinfo);
|
41
|
+
if (0xFFFFFFFF == tzresult)
|
42
|
+
return -1;
|
43
|
+
tzp->tz_minuteswest = tzinfo.Bias;
|
44
|
+
if (0 != tzinfo.StandardDate.wMonth)
|
45
|
+
tzp->tz_minuteswest += tzinfo.StandardBias;
|
46
|
+
tzp->tz_dsttime = (tzresult == TIME_ZONE_ID_DAYLIGHT);
|
47
|
+
}
|
48
|
+
if (tvp) {
|
49
|
+
FILETIME ft;
|
50
|
+
double ti;
|
51
|
+
GetSystemTimeAsFileTime(&ft);
|
52
|
+
ti = (double)ft.dwHighDateTime * 4294967296.0 +
|
53
|
+
(double)ft.dwLowDateTime;
|
54
|
+
ti -= 116444736000000000.0; // 100-nanosecond units
|
55
|
+
//between 1601 and 1970
|
56
|
+
tvp->tv_sec = (long)(ti / 10000000.0);
|
57
|
+
tvp->tv_usec = (long)((ti - (tvp->tv_sec * 10000000.0)) / 10.0);
|
58
|
+
}
|
59
|
+
return 0;
|
60
|
+
}
|
61
|
+
#endif
|
62
|
+
*/
|
63
|
+
|
64
|
+
// local prototypes
|
65
|
+
static void initGMTOffset() ;
|
66
|
+
static short isDSTInEffectOnDate(int year, int mon, int day, int hour, int minute, int seconds) ;
|
67
|
+
static double yearToseconds(long y) ;
|
68
|
+
static int isLeapYear(long year) ;
|
69
|
+
static double monthToSeconds(int m, int isLeapYear) ;
|
70
|
+
static double daysToSeconds(long d) ;
|
71
|
+
static double hoursToSeconds(long h) ;
|
72
|
+
static double minutesToSeconds(long m) ;
|
73
|
+
static long secondsToMin(double *s) ;
|
74
|
+
static long secondsToHours(double *s) ;
|
75
|
+
static long secondsToDays(double *s) ;
|
76
|
+
static long secondsToMonth(double *s, int isLeapYear) ;
|
77
|
+
static long secondsToYear(double *s) ;
|
78
|
+
|
79
|
+
static char gmtstring[30];
|
80
|
+
static char gmtstring_DST[30];
|
81
|
+
static long gmtoffset = 0 ;
|
82
|
+
static long gmtoffset_DST = 0 ;
|
83
|
+
static short gmtinitFlag = 0 ;
|
84
|
+
|
85
|
+
// ------------------------------------------------------------------------------------------
|
86
|
+
static void initGMTOffset()
|
87
|
+
{
|
88
|
+
|
89
|
+
long currentGMTOffset;
|
90
|
+
long newGMTOffset ;
|
91
|
+
|
92
|
+
#ifdef __MWERKS__
|
93
|
+
|
94
|
+
#if MACOS_CLASSIC
|
95
|
+
#warning COMPILING FOR CLASSIC !!!!!
|
96
|
+
return 0
|
97
|
+
|
98
|
+
#elif MACOSX_CARBON
|
99
|
+
|
100
|
+
// start from Jan 1 , 2000 and get the two offsets for DST and not
|
101
|
+
// if GMToffset < 0 then they are WEST of GMT (and therefore behind hours, so DST should be > GMT)
|
102
|
+
// if GMToffset > 0 then they are EAST of GMT (and therefore ahead hours, so DST should be < GMT)
|
103
|
+
|
104
|
+
unsigned long secs ;
|
105
|
+
unsigned long UTCsecs ;
|
106
|
+
short ahead = 0 ;
|
107
|
+
|
108
|
+
GetDateTime(&secs) ; // the offset for today is .....
|
109
|
+
ConvertLocalTimeToUTC(secs, &UTCsecs ) ;
|
110
|
+
|
111
|
+
currentGMTOffset = secs - UTCsecs ; // note that this will tell us whether we are ahead or behind UTC
|
112
|
+
|
113
|
+
gmtoffset = currentGMTOffset ;
|
114
|
+
gmtoffset_DST = currentGMTOffset ;
|
115
|
+
|
116
|
+
// now find a day in the next year where the offset varies
|
117
|
+
for ( int j = 0 ; j < 365 ; j++ )
|
118
|
+
{
|
119
|
+
ConvertLocalTimeToUTC(secs, &UTCsecs ) ;
|
120
|
+
newGMTOffset = secs - UTCsecs ; // note this is in SECONDS !
|
121
|
+
if ( newGMTOffset == currentGMTOffset )
|
122
|
+
secs = secs + 86400 ;
|
123
|
+
else
|
124
|
+
{
|
125
|
+
gmtoffset = currentGMTOffset ;
|
126
|
+
if ( newGMTOffset < gmtoffset ) gmtoffset = newGMTOffset ;
|
127
|
+
|
128
|
+
gmtoffset_DST = currentGMTOffset ;
|
129
|
+
if ( newGMTOffset > gmtoffset_DST ) gmtoffset_DST = newGMTOffset ;
|
130
|
+
|
131
|
+
break ;
|
132
|
+
}
|
133
|
+
}
|
134
|
+
#endif
|
135
|
+
|
136
|
+
#else
|
137
|
+
|
138
|
+
struct timeval tp;
|
139
|
+
struct timezone tz;
|
140
|
+
time_t todaySeconds ;
|
141
|
+
struct tm *local_tm ;
|
142
|
+
int j ;
|
143
|
+
|
144
|
+
gettimeofday(&tp, &tz); /// get todays gmt offset
|
145
|
+
|
146
|
+
currentGMTOffset = (tz.tz_minuteswest * -1) * 60L ; // offset in secs
|
147
|
+
|
148
|
+
// set the normal and DST version of the offset to the same value
|
149
|
+
gmtoffset = currentGMTOffset ;
|
150
|
+
gmtoffset_DST = currentGMTOffset ;
|
151
|
+
|
152
|
+
todaySeconds = tp.tv_sec ;
|
153
|
+
|
154
|
+
// now find a day in the next year where the offset varies if there is one to
|
155
|
+
// figure out hte DST offset (if it exists) .... it may not
|
156
|
+
for ( j = 0 ; j < 365 ; j++ )
|
157
|
+
{
|
158
|
+
local_tm = localtime(&todaySeconds) ;
|
159
|
+
newGMTOffset = local_tm->tm_gmtoff ;
|
160
|
+
|
161
|
+
// if the nw offset is different than the one we found at the outset it's either the
|
162
|
+
// first one is DST and this is the non-DST version
|
163
|
+
// or the first one is the non-DST version and this is the DST version
|
164
|
+
// so decide which and set accordingly
|
165
|
+
if ( newGMTOffset == currentGMTOffset )
|
166
|
+
todaySeconds = todaySeconds + 86400 ;
|
167
|
+
else
|
168
|
+
{
|
169
|
+
if (local_tm->tm_isdst)
|
170
|
+
gmtoffset_DST = newGMTOffset ;
|
171
|
+
else
|
172
|
+
gmtoffset = newGMTOffset ;
|
173
|
+
|
174
|
+
break ;
|
175
|
+
}
|
176
|
+
}
|
177
|
+
|
178
|
+
#endif
|
179
|
+
|
180
|
+
long gmthours = gmtoffset / 3600L ;
|
181
|
+
long gmtminutes = (gmtoffset / 60L) - (gmthours * 60L);
|
182
|
+
|
183
|
+
// CREATE GMT OFFSET
|
184
|
+
if (gmtoffset >= 0)
|
185
|
+
{
|
186
|
+
if ( gmthours >= 10 )
|
187
|
+
sprintf(gmtstring,"+%02d%02d", gmthours, gmtminutes) ;
|
188
|
+
else
|
189
|
+
sprintf(gmtstring,"+%01d%02d", gmthours, gmtminutes);
|
190
|
+
}
|
191
|
+
else
|
192
|
+
{
|
193
|
+
if ( abs(gmthours) >= 10 )
|
194
|
+
sprintf(gmtstring,"-%02d%02d", abs(gmthours), abs(gmtminutes)) ;
|
195
|
+
else
|
196
|
+
sprintf(gmtstring,"-%01d%02d", abs(gmthours), abs(gmtminutes));
|
197
|
+
}
|
198
|
+
|
199
|
+
|
200
|
+
// CREATE GMT OFFSET for DST
|
201
|
+
gmthours = gmtoffset_DST / 3600L ;
|
202
|
+
gmtminutes = (gmtoffset_DST / 60L) - (gmthours * 60L);
|
203
|
+
|
204
|
+
if (gmtoffset_DST >= 0)
|
205
|
+
{
|
206
|
+
if ( gmthours >= 10 )
|
207
|
+
sprintf(gmtstring_DST,"+%02d%02d", gmthours, gmtminutes) ;
|
208
|
+
else
|
209
|
+
sprintf(gmtstring_DST,"+%01d%02d", gmthours, gmtminutes);
|
210
|
+
}
|
211
|
+
else
|
212
|
+
{
|
213
|
+
if ( abs(gmthours) >= 10 )
|
214
|
+
sprintf(gmtstring_DST,"-%02d%02d", abs(gmthours), abs(gmtminutes)) ;
|
215
|
+
else
|
216
|
+
sprintf(gmtstring_DST,"-%01d%02d", abs(gmthours), abs(gmtminutes));
|
217
|
+
}
|
218
|
+
|
219
|
+
|
220
|
+
}
|
221
|
+
|
222
|
+
// ------------------------------------------------------------------------------------------
|
223
|
+
void initDateTime()
|
224
|
+
{
|
225
|
+
|
226
|
+
if (!gmtinitFlag)
|
227
|
+
{
|
228
|
+
|
229
|
+
initGMTOffset() ;
|
230
|
+
|
231
|
+
gmtinitFlag = 1;
|
232
|
+
return;
|
233
|
+
}
|
234
|
+
}
|
235
|
+
|
236
|
+
// ------------------------------------------------------------------------------------------
|
237
|
+
static short isDSTInEffectOnDate(int year, int mon, int day, int hour, int minute, int seconds)
|
238
|
+
{
|
239
|
+
// time given is UTC TIME !!!!!
|
240
|
+
#ifdef __MWERKS__
|
241
|
+
#if TARGET_API_MAC_OS8
|
242
|
+
#pragma unused ( year, mon, day, hour, minute, seconds)
|
243
|
+
|
244
|
+
#warning COMPILING FOR CLASSIC !!!!!
|
245
|
+
|
246
|
+
return 0 ;
|
247
|
+
|
248
|
+
#elif TARGET_API_MAC_CARBON
|
249
|
+
|
250
|
+
DateTimeRec d ;
|
251
|
+
unsigned long secs ;
|
252
|
+
unsigned long UTCsecs ;
|
253
|
+
|
254
|
+
long GMTOffset;
|
255
|
+
|
256
|
+
d.year = year ;
|
257
|
+
d.month = mon ;
|
258
|
+
d.day = day ;
|
259
|
+
d.hour = hour ;
|
260
|
+
d.minute = minute ;
|
261
|
+
d.second = seconds ;
|
262
|
+
|
263
|
+
DateToSeconds (&d, &UTCsecs) ; //treats the date as UTC
|
264
|
+
ConvertUTCToLocalTime(UTCsecs, &secs ) ; // convert to local time
|
265
|
+
SecondsToDate(secs, &d) ;
|
266
|
+
|
267
|
+
GMTOffset = secs - UTCsecs ; // note that this will tell us whether we are ahead or behind UTC
|
268
|
+
|
269
|
+
// if the offset leads us to believe this IS a dst date
|
270
|
+
if (GMTOffset == gmtoffset_DST)
|
271
|
+
{
|
272
|
+
// we need to check and see if this place observes daylight time
|
273
|
+
// if normal and dst are the same this place does NOT observe daylight time
|
274
|
+
if ( gmtoffset == gmtoffset_DST )
|
275
|
+
return 0 ;
|
276
|
+
else
|
277
|
+
return 1 ;
|
278
|
+
}
|
279
|
+
else
|
280
|
+
return 0 ;
|
281
|
+
#else // WIN32 in CodeWarrior !!!!!
|
282
|
+
#pragma unused ( year, mon, day, hour, minute, seconds)
|
283
|
+
|
284
|
+
return 0 ;
|
285
|
+
#endif
|
286
|
+
|
287
|
+
#else
|
288
|
+
|
289
|
+
// we're given UTC and need to deal with it as such
|
290
|
+
struct tm time_str;
|
291
|
+
time_t gmtsecs ;
|
292
|
+
time_t localsecs ;
|
293
|
+
struct tm *localtime_str ;
|
294
|
+
|
295
|
+
time_str.tm_year = (year - 1900);
|
296
|
+
time_str.tm_mon = (mon - 1);
|
297
|
+
time_str.tm_mday = day;
|
298
|
+
time_str.tm_hour = hour;
|
299
|
+
time_str.tm_min = minute;
|
300
|
+
time_str.tm_sec = seconds;
|
301
|
+
time_str.tm_isdst = -1;
|
302
|
+
|
303
|
+
gmtsecs = timegm(&time_str) ; // make the UTC representation of the time
|
304
|
+
localtime_str = localtime(&gmtsecs) ; // convert that to local time
|
305
|
+
localsecs = mktime(localtime_str) ; // and get the broken down version so we can see if DST is enabled
|
306
|
+
|
307
|
+
if (localtime_str->tm_isdst > 0 )
|
308
|
+
return 1 ;
|
309
|
+
else
|
310
|
+
return 0 ;
|
311
|
+
|
312
|
+
#endif
|
313
|
+
}
|
314
|
+
|
315
|
+
// ------------------------------------------------------------------------------------------
|
316
|
+
static double yearToseconds(long y)
|
317
|
+
{
|
318
|
+
double seconds;
|
319
|
+
|
320
|
+
double leapdays = 0.0;
|
321
|
+
double leapcenturies = 0.0;
|
322
|
+
double centuries = 0.0;
|
323
|
+
double yearoffset = 0.0;
|
324
|
+
|
325
|
+
|
326
|
+
if (y < 2001) {
|
327
|
+
yearoffset = y - 2000;
|
328
|
+
} else {
|
329
|
+
yearoffset = y - 2001;
|
330
|
+
}
|
331
|
+
|
332
|
+
// first calculate centuries
|
333
|
+
// extra day every 400 years
|
334
|
+
if ((yearoffset >= 100.0) || (yearoffset <= -100.0)) {
|
335
|
+
centuries = yearoffset / 100.0;
|
336
|
+
modf(centuries,¢uries);
|
337
|
+
|
338
|
+
// calculate the leap years for the centuries
|
339
|
+
leapcenturies = centuries / 4.0;
|
340
|
+
modf(leapcenturies,&leapcenturies);
|
341
|
+
|
342
|
+
centuries = centuries - leapcenturies;
|
343
|
+
|
344
|
+
yearoffset = yearoffset - ((centuries + leapcenturies) * 100);
|
345
|
+
}
|
346
|
+
|
347
|
+
if (yearoffset != 0.0) {
|
348
|
+
leapdays = yearoffset / 4.0;
|
349
|
+
modf(leapdays,&leapdays);
|
350
|
+
}
|
351
|
+
|
352
|
+
leapdays = leapdays + (centuries * 24) + (leapcenturies * 25);
|
353
|
+
|
354
|
+
if (y < 2001) {
|
355
|
+
leapdays = leapdays - 1.0;
|
356
|
+
}
|
357
|
+
|
358
|
+
yearoffset = y - 2001;
|
359
|
+
|
360
|
+
seconds = (double)((yearoffset * 365.0) + (double)leapdays) * 24.0 * 60.0 * 60.0;
|
361
|
+
|
362
|
+
return seconds;
|
363
|
+
}
|
364
|
+
|
365
|
+
// ------------------------------------------------------------------------------------------
|
366
|
+
static int isLeapYear(long year)
|
367
|
+
{
|
368
|
+
long hold;
|
369
|
+
long yearoffset;
|
370
|
+
|
371
|
+
yearoffset = year - 2000;
|
372
|
+
|
373
|
+
if (yearoffset == 0)
|
374
|
+
return 1;
|
375
|
+
|
376
|
+
|
377
|
+
// find century leap year
|
378
|
+
hold = yearoffset / 100;
|
379
|
+
hold = hold * 100;
|
380
|
+
if (hold == yearoffset)
|
381
|
+
{
|
382
|
+
hold = yearoffset / 400;
|
383
|
+
hold = hold * 400;
|
384
|
+
if (hold == yearoffset)
|
385
|
+
{
|
386
|
+
return 1;
|
387
|
+
}
|
388
|
+
return 0;
|
389
|
+
}
|
390
|
+
|
391
|
+
// if the year is not a century boundary
|
392
|
+
|
393
|
+
hold = yearoffset / 4;
|
394
|
+
hold = hold * 4;
|
395
|
+
if (hold == yearoffset)
|
396
|
+
{
|
397
|
+
return 1;
|
398
|
+
}
|
399
|
+
return 0;
|
400
|
+
}
|
401
|
+
|
402
|
+
// ------------------------------------------------------------------------------------------
|
403
|
+
static double monthToSeconds(int m, int isLeapYear)
|
404
|
+
{
|
405
|
+
switch(m) {
|
406
|
+
case 1:
|
407
|
+
return 0;
|
408
|
+
case 2:
|
409
|
+
return 31 * 24 * 60 * 60;
|
410
|
+
case 3:
|
411
|
+
return (59 + isLeapYear) * 24 * 60 * 60;
|
412
|
+
case 4:
|
413
|
+
return (90 + isLeapYear) * 24 * 60 * 60;
|
414
|
+
case 5:
|
415
|
+
return (120 + isLeapYear) * 24 * 60 * 60;
|
416
|
+
case 6:
|
417
|
+
return (151 + isLeapYear) * 24 * 60 * 60;
|
418
|
+
case 7:
|
419
|
+
return (181 + isLeapYear) * 24 * 60 * 60;
|
420
|
+
case 8:
|
421
|
+
return (212 + isLeapYear) * 24 * 60 * 60;
|
422
|
+
case 9:
|
423
|
+
return (243 + isLeapYear) * 24 * 60 * 60;
|
424
|
+
case 10:
|
425
|
+
return (273 + isLeapYear) * 24 * 60 * 60;
|
426
|
+
case 11:
|
427
|
+
return (304 + isLeapYear) * 24 * 60 * 60;
|
428
|
+
case 12:
|
429
|
+
return (334 + isLeapYear) * 24 * 60 * 60;
|
430
|
+
}
|
431
|
+
return 0;
|
432
|
+
}
|
433
|
+
|
434
|
+
|
435
|
+
// ------------------------------------------------------------------------------------------
|
436
|
+
static double daysToSeconds(long d)
|
437
|
+
{
|
438
|
+
return (double)(d - 1) * 24.0 * 60.0 * 60.0;
|
439
|
+
}
|
440
|
+
|
441
|
+
|
442
|
+
// ------------------------------------------------------------------------------------------
|
443
|
+
static double hoursToSeconds(long h)
|
444
|
+
{
|
445
|
+
return (double)h * 60.0 * 60.0;
|
446
|
+
}
|
447
|
+
|
448
|
+
// ------------------------------------------------------------------------------------------
|
449
|
+
static double minutesToSeconds(long m)
|
450
|
+
{
|
451
|
+
return (double)m * 60;
|
452
|
+
}
|
453
|
+
|
454
|
+
// ------------------------------------------------------------------------------------------
|
455
|
+
static long secondsToMin(double *s)
|
456
|
+
{
|
457
|
+
double hold;
|
458
|
+
|
459
|
+
hold = *s / 60.0;
|
460
|
+
modf(hold,&hold);
|
461
|
+
|
462
|
+
*s = *s - (hold * 60);
|
463
|
+
return (int)hold;
|
464
|
+
}
|
465
|
+
|
466
|
+
// ------------------------------------------------------------------------------------------
|
467
|
+
static long secondsToHours(double *s)
|
468
|
+
{
|
469
|
+
double hold;
|
470
|
+
|
471
|
+
hold = *s / (60.0 * 60.0);
|
472
|
+
modf(hold,&hold);
|
473
|
+
|
474
|
+
*s = *s - (hold * (60.0 * 60.0));
|
475
|
+
return (int)hold;
|
476
|
+
}
|
477
|
+
|
478
|
+
// ------------------------------------------------------------------------------------------
|
479
|
+
static long secondsToDays(double *s)
|
480
|
+
{
|
481
|
+
double hold;
|
482
|
+
|
483
|
+
hold = *s / (24.0 * 60.0 * 60.0);
|
484
|
+
modf(hold,&hold);
|
485
|
+
|
486
|
+
*s = *s - (hold * (24.0 * 60.0 * 60.0));
|
487
|
+
hold = hold + 1;
|
488
|
+
return (int)hold;
|
489
|
+
}
|
490
|
+
|
491
|
+
// ------------------------------------------------------------------------------------------
|
492
|
+
static long secondsToMonth(double *s, int isLeapYear)
|
493
|
+
{
|
494
|
+
long hold = 0;
|
495
|
+
double holddouble;
|
496
|
+
|
497
|
+
holddouble = *s / (24.0 * 60.0 * 60.0);
|
498
|
+
modf(holddouble,&holddouble);
|
499
|
+
|
500
|
+
hold = (int)holddouble;
|
501
|
+
|
502
|
+
// Jan
|
503
|
+
if (hold < 31.0)
|
504
|
+
{
|
505
|
+
return 1;
|
506
|
+
}
|
507
|
+
|
508
|
+
// Feb
|
509
|
+
if (hold < (59 + isLeapYear))
|
510
|
+
{
|
511
|
+
*s = *s - (31.0 * (24.0 * 60.0 * 60.0));
|
512
|
+
return 2;
|
513
|
+
}
|
514
|
+
|
515
|
+
// Mar
|
516
|
+
if (hold < (90 + isLeapYear))
|
517
|
+
{
|
518
|
+
*s = *s - ((59.0 + isLeapYear) * (24.0 * 60.0 * 60.0));
|
519
|
+
return 3;
|
520
|
+
}
|
521
|
+
// Apr
|
522
|
+
if (hold < (120 + isLeapYear))
|
523
|
+
{
|
524
|
+
*s = *s - ((90.0 + isLeapYear) * (24.0 * 60.0 * 60.0));
|
525
|
+
return 4;
|
526
|
+
}
|
527
|
+
// May
|
528
|
+
if (hold < (151 + isLeapYear))
|
529
|
+
{
|
530
|
+
*s = *s - ((120.0 + isLeapYear) * (24.0 * 60.0 * 60.0));
|
531
|
+
return 5;
|
532
|
+
}
|
533
|
+
// June
|
534
|
+
if (hold < (181 + isLeapYear))
|
535
|
+
{
|
536
|
+
*s = *s - ((151.0 + isLeapYear) * (24.0 * 60.0 * 60.0));
|
537
|
+
return 6;
|
538
|
+
}
|
539
|
+
// July
|
540
|
+
if (hold < (212 + isLeapYear))
|
541
|
+
{
|
542
|
+
*s = *s - ((181.0 + isLeapYear) * (24.0 * 60.0 * 60.0));
|
543
|
+
return 7;
|
544
|
+
}
|
545
|
+
|
546
|
+
// Aug
|
547
|
+
if (hold < (243 + isLeapYear))
|
548
|
+
{
|
549
|
+
*s = *s - ((212.0 + isLeapYear) * (24.0 * 60.0 * 60.0));
|
550
|
+
return 8;
|
551
|
+
}
|
552
|
+
|
553
|
+
// Sept
|
554
|
+
if (hold < (273 + isLeapYear))
|
555
|
+
{
|
556
|
+
*s = *s - ((243.0 + isLeapYear) * (24.0 * 60.0 * 60.0));
|
557
|
+
return 9;
|
558
|
+
}
|
559
|
+
|
560
|
+
// Oct
|
561
|
+
if (hold < (304 + isLeapYear))
|
562
|
+
{
|
563
|
+
*s = *s - ((273.0 + isLeapYear) * (24.0 * 60.0 * 60.0));
|
564
|
+
return 10;
|
565
|
+
}
|
566
|
+
|
567
|
+
// Nov
|
568
|
+
if (hold < (334 + isLeapYear))
|
569
|
+
{
|
570
|
+
*s = *s - ((304.0 + isLeapYear) * (24.0 * 60.0 * 60.0));
|
571
|
+
return 11;
|
572
|
+
}
|
573
|
+
|
574
|
+
// Dec
|
575
|
+
if (hold < (365 + isLeapYear))
|
576
|
+
{
|
577
|
+
*s = *s - ((334.0 + isLeapYear) * (24.0 * 60.0 * 60.0));
|
578
|
+
return 12;
|
579
|
+
}
|
580
|
+
|
581
|
+
return 0;
|
582
|
+
}
|
583
|
+
|
584
|
+
// ------------------------------------------------------------------------------------------
|
585
|
+
static long secondsToYear(double *s)
|
586
|
+
{
|
587
|
+
long year;
|
588
|
+
double days;
|
589
|
+
|
590
|
+
double leapcenturies = 0.0;
|
591
|
+
double centuries = 0.0;
|
592
|
+
double leapyears = 0.0;
|
593
|
+
double years = 0.0;
|
594
|
+
double leapdays = 0.0;
|
595
|
+
|
596
|
+
days = *s / (24.0 * 60.0 * 60.0);
|
597
|
+
modf(days,&days);
|
598
|
+
|
599
|
+
// (days + (leapdays * 366))
|
600
|
+
|
601
|
+
if (*s < 0.0)
|
602
|
+
{
|
603
|
+
leapdays = -1.0;
|
604
|
+
days = days + 1;
|
605
|
+
|
606
|
+
if (days != 0.0)
|
607
|
+
{
|
608
|
+
leapcenturies = days / ((((100 * 365) + 24) * 4) + 1);
|
609
|
+
modf(leapcenturies,&leapcenturies);
|
610
|
+
days = days - leapcenturies * ((((100 * 365) + 24) * 4) + 1);
|
611
|
+
}
|
612
|
+
|
613
|
+
if (days != 0.0)
|
614
|
+
{
|
615
|
+
centuries = days / ((100 * 365) + 24);
|
616
|
+
modf(centuries,¢uries);
|
617
|
+
days = days - centuries * ((100 * 365) + 24);
|
618
|
+
}
|
619
|
+
|
620
|
+
if (days != 0.0)
|
621
|
+
{
|
622
|
+
leapyears = days / ((4 * 365) + 1);
|
623
|
+
modf(leapyears,&leapyears);
|
624
|
+
days = days - leapyears * ((4 * 365) + 1);
|
625
|
+
}
|
626
|
+
|
627
|
+
if (days != 0.0)
|
628
|
+
{
|
629
|
+
years = days / 365.0;
|
630
|
+
modf(years,&years);
|
631
|
+
days = days - (years * 365.0);
|
632
|
+
}
|
633
|
+
years = years - 1;
|
634
|
+
|
635
|
+
year = 2001 + (leapcenturies * 400) + (centuries * 100) + (leapyears * 4) + years;
|
636
|
+
|
637
|
+
}
|
638
|
+
else
|
639
|
+
{
|
640
|
+
if (days != 0.0)
|
641
|
+
{
|
642
|
+
leapcenturies = days / ((((100 * 365) + 24) * 4) + 1);
|
643
|
+
modf(leapcenturies,&leapcenturies);
|
644
|
+
days = days - leapcenturies * ((((100 * 365) + 24) * 4) + 1);
|
645
|
+
}
|
646
|
+
|
647
|
+
if (days != 0.0)
|
648
|
+
{
|
649
|
+
centuries = days / ((100 * 365) + 24);
|
650
|
+
modf(centuries,¢uries);
|
651
|
+
days = days - centuries * ((100 * 365) + 24);
|
652
|
+
}
|
653
|
+
|
654
|
+
if (days != 0.0)
|
655
|
+
{
|
656
|
+
leapyears = days / ((4 * 365) + 1);
|
657
|
+
modf(leapyears,&leapyears);
|
658
|
+
days = days - leapyears * ((4 * 365) + 1);
|
659
|
+
}
|
660
|
+
|
661
|
+
if (days != 0.0)
|
662
|
+
{
|
663
|
+
years = days / 365.0;
|
664
|
+
modf(years,&years);
|
665
|
+
days = days - (years * 365.0);
|
666
|
+
}
|
667
|
+
|
668
|
+
year = 2001 + (leapcenturies * 400) + (centuries * 100) + (leapyears * 4) + years;
|
669
|
+
|
670
|
+
if ((year != 2001) && isLeapYear(year - 1) && days == 0.0)
|
671
|
+
{
|
672
|
+
if (years == 4)
|
673
|
+
year = year - 1;
|
674
|
+
if (centuries == 4)
|
675
|
+
year = year - 1;
|
676
|
+
}
|
677
|
+
}
|
678
|
+
|
679
|
+
|
680
|
+
//if (year > 2001 && (isLeapYear(year -1))) {
|
681
|
+
// year = year - 1;
|
682
|
+
//}
|
683
|
+
|
684
|
+
*s = *s - yearToseconds(year);
|
685
|
+
|
686
|
+
return year;
|
687
|
+
}
|
688
|
+
|
689
|
+
|
690
|
+
// ------------------------------------------------------------------------------------------
|
691
|
+
char *OB_formatDate(double datevalue, char *buffer)
|
692
|
+
{
|
693
|
+
// the date time value given is GMT based ...
|
694
|
+
double localdatevalue = datevalue ;
|
695
|
+
long year;
|
696
|
+
long month;
|
697
|
+
long day;
|
698
|
+
long hour;
|
699
|
+
long minutes;
|
700
|
+
long second;
|
701
|
+
long daylight_savings_flag = 0;
|
702
|
+
|
703
|
+
year = secondsToYear(&localdatevalue);
|
704
|
+
month = secondsToMonth(&localdatevalue, isLeapYear(year));
|
705
|
+
day = secondsToDays(&localdatevalue);
|
706
|
+
hour = secondsToHours(&localdatevalue);
|
707
|
+
minutes = secondsToMin(&localdatevalue);
|
708
|
+
second = localdatevalue;
|
709
|
+
|
710
|
+
// split the date up into it's components (STILL GMT relative)
|
711
|
+
// and see if the time zone we are in was in DST for this time
|
712
|
+
daylight_savings_flag = isDSTInEffectOnDate( year, month, day, hour, minutes, second ) ;
|
713
|
+
|
714
|
+
// if so we adjust the time by the appropriate gmt offset (which we calculated before)
|
715
|
+
if (daylight_savings_flag)
|
716
|
+
{
|
717
|
+
localdatevalue = datevalue + gmtoffset_DST ;
|
718
|
+
}
|
719
|
+
else
|
720
|
+
{
|
721
|
+
localdatevalue = datevalue + gmtoffset;
|
722
|
+
}
|
723
|
+
|
724
|
+
// and split the time up to be timezone relative
|
725
|
+
year = secondsToYear(&localdatevalue);
|
726
|
+
month = secondsToMonth(&localdatevalue, isLeapYear(year));
|
727
|
+
day = secondsToDays(&localdatevalue);
|
728
|
+
hour = secondsToHours(&localdatevalue);
|
729
|
+
minutes = secondsToMin(&localdatevalue);
|
730
|
+
second = localdatevalue;
|
731
|
+
|
732
|
+
// and format it appropriately
|
733
|
+
if (daylight_savings_flag)
|
734
|
+
{
|
735
|
+
sprintf(buffer, "%04d-%02d-%02d %02d:%02d:%02d %s", year, month, day, hour, minutes, second, gmtstring_DST);
|
736
|
+
}
|
737
|
+
else
|
738
|
+
{
|
739
|
+
sprintf(buffer, "%04d-%02d-%02d %02d:%02d:%02d %s", year, month, day, hour, minutes, second, gmtstring);
|
740
|
+
}
|
741
|
+
|
742
|
+
return buffer;
|
743
|
+
}
|
744
|
+
|
745
|
+
// ------------------------------------------------------------------------------------------
|
746
|
+
double dateToFloat(char *buffer)
|
747
|
+
{
|
748
|
+
long year = 2001;
|
749
|
+
long month = 1;
|
750
|
+
long day = 1;
|
751
|
+
long hour = 12;
|
752
|
+
long minutes = 0;
|
753
|
+
long second = 0;
|
754
|
+
long gmtadjust = gmtoffset;
|
755
|
+
long len;
|
756
|
+
|
757
|
+
len = strlen(buffer);
|
758
|
+
|
759
|
+
year = atoi(buffer);
|
760
|
+
if (len > 5)
|
761
|
+
{
|
762
|
+
month = atoi(&buffer[5]);
|
763
|
+
}
|
764
|
+
if (len > 8)
|
765
|
+
{
|
766
|
+
day = atoi(&buffer[8]);
|
767
|
+
}
|
768
|
+
if (len > 11)
|
769
|
+
{
|
770
|
+
hour = atoi(&buffer[11]);
|
771
|
+
}
|
772
|
+
if (len > 14)
|
773
|
+
{
|
774
|
+
minutes = atoi(&buffer[14]);
|
775
|
+
}
|
776
|
+
if (len > 17)
|
777
|
+
{
|
778
|
+
second = atoi(&buffer[17]);
|
779
|
+
}
|
780
|
+
if (len > 20)
|
781
|
+
{
|
782
|
+
long gmt_hours;
|
783
|
+
long gmt_minutes;
|
784
|
+
|
785
|
+
gmtadjust = atoi(&buffer[20]);
|
786
|
+
|
787
|
+
gmt_hours = gmtadjust / 100;
|
788
|
+
gmt_minutes = gmtadjust - (gmt_hours * 100);
|
789
|
+
|
790
|
+
gmtadjust = (gmt_hours * 3600) + (gmt_minutes * 60);
|
791
|
+
}
|
792
|
+
else
|
793
|
+
{
|
794
|
+
// find out what the GMT is for this time and set it.
|
795
|
+
struct tm time_str;
|
796
|
+
|
797
|
+
time_str.tm_year = (year - 1900);
|
798
|
+
time_str.tm_mon = (month - 1);
|
799
|
+
time_str.tm_mday = day;
|
800
|
+
time_str.tm_hour = hour;
|
801
|
+
time_str.tm_min = minutes;
|
802
|
+
time_str.tm_sec = second;
|
803
|
+
time_str.tm_isdst = -1;
|
804
|
+
mktime(&time_str);
|
805
|
+
if ((time_str.tm_isdst == 1) && (hour > 0)) {
|
806
|
+
gmtadjust = (gmtoffset_DST * 60);
|
807
|
+
} else {
|
808
|
+
gmtadjust = (gmtoffset * 60);
|
809
|
+
}
|
810
|
+
}
|
811
|
+
|
812
|
+
return (yearToseconds(year) + monthToSeconds(month, isLeapYear(year)) +
|
813
|
+
daysToSeconds(day) + hoursToSeconds(hour) + minutesToSeconds(minutes) +
|
814
|
+
second - gmtadjust);
|
815
|
+
}
|
816
|
+
|