|
| 1 | +/* -*-c++-*- |
| 2 | +Copyright (C) 2015 Runtime Revolution Ltd. |
| 3 | +
|
| 4 | +This file is part of LiveCode. |
| 5 | +
|
| 6 | +LiveCode is free software; you can redistribute it and/or modify it under |
| 7 | +the terms of the GNU General Public License v3 as published by the Free |
| 8 | +Software Foundation. |
| 9 | +
|
| 10 | +LiveCode is distributed in the hope that it will be useful, but WITHOUT ANY |
| 11 | +WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 12 | +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 13 | +for more details. |
| 14 | +
|
| 15 | +You should have received a copy of the GNU General Public License |
| 16 | +along with LiveCode. If not see <http://www.gnu.org/licenses/>. */ |
| 17 | + |
| 18 | +#include <foundation.h> |
| 19 | +#include <foundation-auto.h> |
| 20 | + |
| 21 | +#include <time.h> |
| 22 | + |
| 23 | +/* Windows doesn't have localtime_r(), but it does have an equivalent |
| 24 | + * function with the arguments in the opposite order! */ |
| 25 | +#if defined(__WINDOWS__) |
| 26 | +# define localtime_r(s,t) (_localtime_s(t,s)) |
| 27 | +#endif |
| 28 | + |
| 29 | +extern "C" MC_DLLEXPORT void |
| 30 | +MCDateExecGetLocalTime (MCProperListRef & r_datetime) |
| 31 | +{ |
| 32 | + struct tm t_timeinfo; |
| 33 | + time_t t_now; |
| 34 | + |
| 35 | + time (&t_now); |
| 36 | + if (NULL == localtime_r (&t_now, &t_timeinfo)) |
| 37 | + return; |
| 38 | + |
| 39 | + MCAutoNumberRef t_year, t_month, t_day, t_hour, t_minute, t_second; |
| 40 | + if (!(MCNumberCreateWithInteger (t_timeinfo.tm_year, &t_year) && |
| 41 | + MCNumberCreateWithInteger (t_timeinfo.tm_mon, &t_month) && |
| 42 | + MCNumberCreateWithInteger (t_timeinfo.tm_mday, &t_day) && |
| 43 | + MCNumberCreateWithInteger (t_timeinfo.tm_hour, &t_hour) && |
| 44 | + MCNumberCreateWithInteger (t_timeinfo.tm_min, &t_minute) && |
| 45 | + MCNumberCreateWithInteger (t_timeinfo.tm_sec, &t_second))) |
| 46 | + return; |
| 47 | + |
| 48 | + const MCValueRef t_elements[] = {*t_year, *t_month, *t_day, |
| 49 | + *t_hour, *t_minute, *t_second}; |
| 50 | + |
| 51 | + /* UNCHECKED */ MCProperListCreate (t_elements, 6, r_datetime); |
| 52 | +} |
0 commit comments