1 /*****************************************************************************/
5 /* Convert calendar time into broken down local time */
9 /* (C) 2002 Ullrich von Bassewitz */
11 /* D-70597 Stuttgart */
12 /* EMail: uz@musoftware.de */
15 /* This software is provided 'as-is', without any expressed or implied */
16 /* warranty. In no event will the authors be held liable for any damages */
17 /* arising from the use of this software. */
19 /* Permission is granted to anyone to use this software for any purpose, */
20 /* including commercial applications, and to alter it and redistribute it */
21 /* freely, subject to the following restrictions: */
23 /* 1. The origin of this software must not be misrepresented; you must not */
24 /* claim that you wrote the original software. If you use this software */
25 /* in a product, an acknowledgment in the product documentation would be */
26 /* appreciated but is not required. */
27 /* 2. Altered source versions must be plainly marked as such, and must not */
28 /* be misrepresented as being the original software. */
29 /* 3. This notice may not be removed or altered from any source */
32 /*****************************************************************************/
40 /*****************************************************************************/
42 /*****************************************************************************/
46 struct tm* __fastcall__ localtime (const time_t* timep)
48 static struct tm timebuf;
51 /* Check the argument */
52 if (timep == 0 || (long) (t = *timep) < 0) {
57 /* Since our ints are just 16 bits, split the given time into seconds,
58 * hours and days. Each of the values will fit in a 16 bit variable.
59 * The mktime routine will then do the rest.
61 timebuf.tm_sec = t % 3600;
63 timebuf.tm_hour = (t / 3600) % 24;
64 timebuf.tm_mday = (t / (3600UL * 24UL)) + 1;
66 timebuf.tm_year = 70; /* Base value is 1/1/1970 */
68 /* Call mktime to do the final conversion */
71 /* Return the result */