@@ -26,43 +26,97 @@ along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
2626# include < windows.h>
2727#endif
2828
29- /* Windows doesn't have localtime_r(), but it does have an equivalent
30- * function with the arguments in the opposite order! */
3129#if defined(__WINDOWS__)
32- // AL-2015-0728: [[ Bug 15410 ]] Windows localtime_s returns an errno_t
33- // so do a bit of gymnastics to make the signature correct.
34- inline struct tm * localtime_r ( const time_t *p_time, struct tm *r_timeinfo )
30+ static bool
31+ MCDateGetLocalTimeInfo ( struct tm & r_timeinfo,
32+ long & r_timezone )
3533{
36- if (localtime_s (r_timeinfo, p_time) == 0 )
37- return r_timeinfo;
38-
39- return NULL ;
34+ _get_timezone (&t_timezone);
35+
36+ time_t t_now;
37+ time (&t_now);
38+
39+ /* Windows doesn't have localtime_r(), but it does have an equivalent
40+ * function with the arguments in the opposite order! */
41+ if (0 != localtime_s (&r_timeinfo, &t_time))
42+ {
43+ return false ;
44+ }
45+
46+ return true ;
47+ }
48+
49+ #elif defined(__MAC__) || defined(__IOS__)
50+ static bool
51+ MCDateGetLocalTimeInfo (struct tm & r_timeinfo,
52+ long & r_timezone)
53+ {
54+ time_t t_now;
55+ time (&t_now);
56+
57+ if (NULL == localtime_r (&t_now, &r_timeinfo))
58+ {
59+ return false ;
60+ }
61+
62+ r_timezone = r_timeinfo.tm_gmtoff ;
63+
64+ return true ;
4065}
66+
67+ #elif defined(__LINUX__) || defined(__ANDROID__) || defined(__EMSCRIPTEN__)
68+ static bool
69+ MCDateGetLocalTimeInfo (struct tm & r_timeinfo,
70+ long & r_timezone)
71+ {
72+ time_t t_now;
73+ time (&t_now);
74+
75+ if (NULL == localtime_r (&t_now, &r_timeinfo))
76+ {
77+ return false ;
78+ }
79+
80+ /* FIXME This may be expensive, but is probably required if
81+ * MCDateGetLocalTimeInfo() is to behave properly over summer time
82+ * changes. */
83+ tzset ();
84+ r_timezone = timezone;
85+
86+ return true ;
87+ }
88+
89+ #else
90+ # error "MCDateGetLocalTimeInfo() not implemented for this platform"
4191#endif
4292
4393extern " C" MC_DLLEXPORT_DEF void
4494MCDateExecGetLocalDate (MCProperListRef & r_datetime)
4595{
4696 struct tm t_timeinfo;
47- time_t t_now ;
97+ long t_timezone ;
4898
49- time (&t_now);
50- if ( NULL == localtime_r (&t_now, &t_timeinfo))
99+ if (! MCDateGetLocalTimeInfo (t_timeinfo, t_timezone))
100+ {
51101 return ;
102+ }
52103
53- MCAutoNumberRef t_year, t_month, t_day, t_hour, t_minute, t_second;
104+ MCAutoNumberRef t_year, t_month, t_day, t_hour, t_minute, t_second,
105+ t_gmtoff;
54106 if (!(MCNumberCreateWithInteger (t_timeinfo.tm_year , &t_year) &&
55107 MCNumberCreateWithInteger (t_timeinfo.tm_mon , &t_month) &&
56108 MCNumberCreateWithInteger (t_timeinfo.tm_mday , &t_day) &&
57109 MCNumberCreateWithInteger (t_timeinfo.tm_hour , &t_hour) &&
58110 MCNumberCreateWithInteger (t_timeinfo.tm_min , &t_minute) &&
59- MCNumberCreateWithInteger (t_timeinfo.tm_sec , &t_second)))
111+ MCNumberCreateWithInteger (t_timeinfo.tm_sec , &t_second) &&
112+ MCNumberCreateWithInteger (t_timezone, &t_gmtoff)))
60113 return ;
61114
62115 const MCValueRef t_elements[] = {*t_year, *t_month, *t_day,
63- *t_hour, *t_minute, *t_second};
116+ *t_hour, *t_minute, *t_second,
117+ *t_gmtoff};
64118
65- if (!MCProperListCreate (t_elements, 6 , r_datetime))
119+ if (!MCProperListCreate (t_elements, 7 , r_datetime))
66120 return ;
67121}
68122
0 commit comments