blob: c0cb9f5120186ada6093c000da9734525660e895 [file] [log] [blame]
Benny Prijono9033e312005-11-21 02:08:39 +00001/* $Id$ */
2/*
3 * Copyright (C)2003-2006 Benny Prijono <benny@prijono.org>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19#include <pj/os.h>
20#include <pj/compat/time.h>
21
22///////////////////////////////////////////////////////////////////////////////
23
24PJ_DEF(pj_status_t) pj_gettimeofday(pj_time_val *tv)
25{
26 struct timeb tb;
27
28 PJ_CHECK_STACK();
29
30 ftime(&tb);
31 tv->sec = tb.time;
32 tv->msec = tb.millitm;
33 return PJ_SUCCESS;
34}
35
36PJ_DEF(pj_status_t) pj_time_decode(const pj_time_val *tv, pj_parsed_time *pt)
37{
38 struct tm *local_time;
39
40 PJ_CHECK_STACK();
41
42 local_time = localtime((time_t*)&tv->sec);
43
44 pt->year = local_time->tm_year+1900;
45 pt->mon = local_time->tm_mon;
46 pt->day = local_time->tm_mday;
47 pt->hour = local_time->tm_hour;
48 pt->min = local_time->tm_min;
49 pt->sec = local_time->tm_sec;
50 pt->wday = local_time->tm_wday;
Benny Prijono9033e312005-11-21 02:08:39 +000051 pt->msec = tv->msec;
52
53 return PJ_SUCCESS;
54}
55
56/**
57 * Encode parsed time to time value.
58 */
Benny Prijono9cf138e2006-01-19 03:58:29 +000059PJ_DEF(pj_status_t) pj_time_encode(const pj_parsed_time *pt, pj_time_val *tv)
60{
61 struct tm local_time;
62
63 local_time.tm_year = pt->year-1900;
64 local_time.tm_mon = pt->mon;
65 local_time.tm_mday = pt->day;
66 local_time.tm_hour = pt->hour;
67 local_time.tm_min = pt->min;
68 local_time.tm_sec = pt->sec;
69 local_time.tm_isdst = 0;
70
71 tv->sec = mktime(&local_time);
72 tv->msec = pt->msec;
73
74 return PJ_SUCCESS;
75}
Benny Prijono9033e312005-11-21 02:08:39 +000076
77/**
78 * Convert local time to GMT.
79 */
80PJ_DEF(pj_status_t) pj_time_local_to_gmt(pj_time_val *tv);
81
82/**
83 * Convert GMT to local time.
84 */
85PJ_DEF(pj_status_t) pj_time_gmt_to_local(pj_time_val *tv);
86
87