blob: 5fffe948e9b53e7b76e2787ba10fd70baa0c7997 [file] [log] [blame]
Benny Prijono9033e312005-11-21 02:08:39 +00001/* $Id$ */
2/*
Benny Prijonoa771a512007-02-19 01:13:53 +00003 * Copyright (C)2003-2007 Benny Prijono <benny@prijono.org>
Benny Prijono9033e312005-11-21 02:08:39 +00004 *
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
Benny Prijono9033e312005-11-21 02:08:39 +000024PJ_DEF(pj_status_t) pj_time_decode(const pj_time_val *tv, pj_parsed_time *pt)
25{
26 struct tm *local_time;
27
28 PJ_CHECK_STACK();
29
30 local_time = localtime((time_t*)&tv->sec);
31
32 pt->year = local_time->tm_year+1900;
33 pt->mon = local_time->tm_mon;
34 pt->day = local_time->tm_mday;
35 pt->hour = local_time->tm_hour;
36 pt->min = local_time->tm_min;
37 pt->sec = local_time->tm_sec;
38 pt->wday = local_time->tm_wday;
Benny Prijono9033e312005-11-21 02:08:39 +000039 pt->msec = tv->msec;
40
41 return PJ_SUCCESS;
42}
43
44/**
45 * Encode parsed time to time value.
46 */
Benny Prijono9cf138e2006-01-19 03:58:29 +000047PJ_DEF(pj_status_t) pj_time_encode(const pj_parsed_time *pt, pj_time_val *tv)
48{
49 struct tm local_time;
50
51 local_time.tm_year = pt->year-1900;
52 local_time.tm_mon = pt->mon;
53 local_time.tm_mday = pt->day;
54 local_time.tm_hour = pt->hour;
55 local_time.tm_min = pt->min;
56 local_time.tm_sec = pt->sec;
57 local_time.tm_isdst = 0;
58
59 tv->sec = mktime(&local_time);
60 tv->msec = pt->msec;
61
62 return PJ_SUCCESS;
63}
Benny Prijono9033e312005-11-21 02:08:39 +000064
65/**
66 * Convert local time to GMT.
67 */
68PJ_DEF(pj_status_t) pj_time_local_to_gmt(pj_time_val *tv);
69
70/**
71 * Convert GMT to local time.
72 */
73PJ_DEF(pj_status_t) pj_time_gmt_to_local(pj_time_val *tv);
74
75