sl@0: // Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // TIME.CPP sl@0: // Mapping between EPOC32 time and libc time sl@0: // The basic philosophy is to work in time_t units (TInt) which sl@0: // will be essentially TTimeIntervalSeconds from the start of Unix time. sl@0: // To stay compliant with the C-Standard (with reference to C99 draft), we sl@0: // set the meaning of time_t to be Universal time. sl@0: // sl@0: // sl@0: sl@0: #include sl@0: #include // struct timeval, timezone sl@0: sl@0: #define UNIX_BASE TTime(MAKE_TINT64(0x00dcddb3,0x0f2f8000)) // 00:00, Jan 1st 1970 sl@0: sl@0: // external interface for the C library sl@0: sl@0: extern "C" { sl@0: sl@0: /* sl@0: Intended Usage: The gettimeofday function obtains the current UTC time, which is sl@0: expressed as seconds and microseconds since 00:00:00 Coordinated Universal Time (UTC), sl@0: January 1, 1970, and stores it in a timeval structure. sl@0: Please note that tz_minuteswest includes daytime saving. The struct member tz_dsttime is no sl@0: longer supported by Symbian OS and therefore set to Zero. sl@0: sl@0: */ sl@0: EXPORT_C sl@0: int gettimeofday (struct timeval *tp, struct timezone *tzp) sl@0: { sl@0: if (tp) sl@0: { sl@0: TTime t; sl@0: t.UniversalTime(); sl@0: sl@0: TTimeIntervalSeconds sec; sl@0: TInt err = t.SecondsFrom(UNIX_BASE, sec); sl@0: if (err) sl@0: return -1; sl@0: else sl@0: tp->tv_sec = sec.Int(); sl@0: t -= sec; sl@0: TTimeIntervalMicroSeconds usec = t.MicroSecondsFrom(UNIX_BASE); sl@0: TInt64 hackyfix = usec.Int64(); // because GetTInt() isn't declared const sl@0: tp->tv_usec = I64INT(hackyfix); sl@0: } sl@0: if (tzp) sl@0: { sl@0: tzp->tz_minuteswest = (User::UTCOffset().Int())/60; sl@0: tzp->tz_dsttime = 0; sl@0: } sl@0: return 0; sl@0: } sl@0: sl@0: } // extern "C"