ICU-9051 timezone offset fix on iOS

X-SVN-Rev: 34248
This commit is contained in:
Jungshik Shin 2013-09-09 17:58:59 +00:00
parent 5cf1e499d1
commit aa9214a168
2 changed files with 13 additions and 8 deletions

View File

@ -639,27 +639,30 @@ uprv_timezone()
#else
time_t t, t1, t2;
struct tm tmrec;
UBool dst_checked;
int32_t tdiff = 0;
time(&t);
uprv_memcpy( &tmrec, localtime(&t), sizeof(tmrec) );
dst_checked = (tmrec.tm_isdst != 0); /* daylight savings time is checked*/
#if U_PLATFORM != U_PF_IPHONE
UBool dst_checked = (tmrec.tm_isdst != 0); /* daylight savings time is checked*/
#endif
t1 = mktime(&tmrec); /* local time in seconds*/
uprv_memcpy( &tmrec, gmtime(&t), sizeof(tmrec) );
t2 = mktime(&tmrec); /* GMT (or UTC) in seconds*/
tdiff = t2 - t1;
#if U_PLATFORM != U_PF_IPHONE
/* imitate NT behaviour, which returns same timezone offset to GMT for
winter and summer.
This does not work on all platforms. For instance, on glibc on Linux
and on Mac OS 10.5, tdiff calculated above remains the same
regardless of whether DST is in effect or not. However, U_TIMEZONE
is defined on those platforms and this code is not reached so that
we can leave this alone. If there's a platform behaving
like glibc that uses this code, we need to add platform-dependent
preprocessor here. */
regardless of whether DST is in effect or not. iOS is another
platform where this does not work. Linux + glibc and Mac OS 10.5
have U_TIMEZONE defined so that this code is not reached.
*/
if (dst_checked)
tdiff += 3600;
#endif
return tdiff;
#endif
}
@ -672,7 +675,7 @@ uprv_timezone()
extern U_IMPORT char *U_TZNAME[];
#endif
#if !UCONFIG_NO_FILE_IO && (U_PLATFORM_IS_DARWIN_BASED || U_PLATFORM_IS_LINUX_BASED || U_PLATFORM == U_PF_BSD || U_PLATFORM == U_PF_SOLARIS)
#if !UCONFIG_NO_FILE_IO && ((U_PLATFORM_IS_DARWIN_BASED && (U_PLATFORM != U_PF_IPHONE)) || U_PLATFORM_IS_LINUX_BASED || U_PLATFORM == U_PF_BSD || U_PLATFORM == U_PF_SOLARIS)
/* These platforms are likely to use Olson timezone IDs. */
#define CHECK_LOCALTIME_LINK 1
#if U_PLATFORM_IS_DARWIN_BASED

View File

@ -126,6 +126,8 @@ typedef size_t uintptr_t;
/* not defined */
#elif U_PLATFORM == U_PF_OS400
/* not defined */
#elif U_PLATFORM == U_PF_IPHONE
/* not defined */
#else
# define U_TIMEZONE timezone
#endif