]> git.saurik.com Git - wxWidgets.git/blame - src/palmos/stdall.c
PalmOS compilation fixes (wx-trunk-out.diff part of patch 1894861)
[wxWidgets.git] / src / palmos / stdall.c
CommitLineData
e2fc40b4
VZ
1
2#include <Preferences.h> // Core/System/
3#include <DateTime.h> //Core/System/, DateToAscii() etc.
4#include <TimeMgr.h> //Core/System/, TimGetTicks()
5
6#include "wx/defs.h"
7
8#if __WXPALMOS6__
9void
10exit (int exitno)
11{
12}
13
14#else
15
16#define SEC_1904_1970 2082844800LU//0x7C25B080 // 0x7C25B080 == 2082844800LU
17
18time_t
19time (time_t *T)
20{
21 UInt32 sec;
22 // UInt32 TimGetSeconds(void); // seconds since 1/1/1904
23 // void TimSetSeconds (UInt32 seconds); // seconds since 1/1/1904
24 // UInt32 TimGetTicks(void); // ticks since power on
25 sec = TimGetSeconds ();
26 if (T) {
27 *T = sec - SEC_1904_1970;
28 }
29 return (sec - SEC_1904_1970);
30}
31
32static struct tm *
33palmtimet2unixtm (const time_t t, struct tm *ptm)
34{
35 DateTimeType dt;
36 memset (&dt, 0, sizeof (dt));
37 memset (ptm, 0, sizeof (*ptm));
38 TimSecondsToDateTime (t, &dt);
39 ptm->tm_sec = dt.second;
40 ptm->tm_min = dt.minute;
41 ptm->tm_hour = dt.hour;
42 ptm->tm_mday = dt.day;
43 ptm->tm_mon = dt.month;
44 ptm->tm_year = dt.year;
45 ptm->tm_wday = dt.weekDay;
46
47 //ptm->tm_wday = DayOfWeek (dt.month, dt.day, dt.year);
48 //ptm->tm_mday = DayOfMonth (dt.month, dt.day, dt.year);
49 return ptm;
50}
51
52struct tm *
53gmtime_r (const time_t *pt, struct tm *ptm)
54{
55 UInt32 utcTime;
56 Int16 timeZone = PrefGetPreference(prefTimeZone);
57 Int16 daylightSavingAdjustment = PrefGetPreference(prefDaylightSavingAdjustment);
58
59 if ((NULL == pt) || (NULL == ptm)) {
60 return NULL;
61 }
62 utcTime = TimTimeZoneToUTC (*pt + SEC_1904_1970, timeZone, daylightSavingAdjustment);
63 palmtimet2unixtm (utcTime, ptm);
64 return ptm;
65}
66
67struct tm *
68localtime_r (const time_t *pt, struct tm *ptm)
69{
70 UInt32 utcTime;
71 Int16 timeZone = PrefGetPreference(prefTimeZone);
72 Int16 daylightSavingAdjustment = PrefGetPreference(prefDaylightSavingAdjustment);
73 if ((NULL == pt) || (NULL == ptm)) {
74 return NULL;
75 }
76 utcTime = TimUTCToTimeZone (*pt + SEC_1904_1970, timeZone, daylightSavingAdjustment);
77 palmtimet2unixtm (utcTime, ptm);
78 return ptm;
79}
80/*
81static struct tm g_gmtime_info;
82
83struct tm *
84gmtime (const time_t *CLOCK)
85{
86 if (NULL == CLOCK) {
87 return NULL;
88 }
89 if (NULL == gmtime_r (CLOCK, &g_gmtime_info)) {
90 return NULL;
91 }
92 return &g_gmtime_info;
93}
94*/
95static struct tm g_localtime_info;
96
97struct tm *
98localtime (const time_t *CLOCK)
99{
100 if (NULL == CLOCK) {
101 return NULL;
102 }
103 if (NULL == localtime_r (CLOCK, &g_localtime_info)) {
104 return NULL;
105 }
106 return &g_localtime_info;
107}
108
109static char * g_strftime_wdayconv[][2] = {
110 {"Sun", "Sunday"},
111 {"Mon", "Monday"},
112 {"Tue", "Tuesday"},
113 {"Wed", "Wednesday"},
114 {"Thu", "Thursday"},
115 {"Fri", "Friday"},
116 {"Sat", "Saturday"},
117};
118
119static char * g_strftime_monconv[][2] = {
120 {"Jan", "January"},
121 {"Feb", "Febuary"},
122 {"Mar", "March"},
123 {"Apr", "April"},
124 {"May", "May"},
125 {"Jun", "June"},
126 {"Jul", "July"},
127 {"Aug", "August"},
128 {"Sep", "September"},
129 {"Oct", "October"},
130 {"Nov", "November"},
131 {"Dec", "December"},
132};
133#define SFCONV_ABBR 0
134#define SFCONV_FULL 1
135
136size_t
137strftime (char *buf, size_t sz_buf, const char *fmt, const struct tm *ptm)
138{
139 char *p;
140 char *pret;
141 if ((timeStringLength > sz_buf) || (strlen (fmt) < 1)) {
142 return 0;
143 }
144 memset (buf, 0, sz_buf);
145 p = fmt;
146 pret = buf;
147 for (; *p != '\0';) {
148 if ('%' == *p) {
149 p ++;
150 if (*p == '\0') {
151 break;
152 }
153