blob: 331116bcb55b6678065257ac157822f44c36b00a [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>
Benny Prijono8ab968f2007-07-20 08:08:30 +000021#include <pj/errno.h>
22
Benny Prijono9033e312005-11-21 02:08:39 +000023
24///////////////////////////////////////////////////////////////////////////////
25
Benny Prijono9033e312005-11-21 02:08:39 +000026PJ_DEF(pj_status_t) pj_time_decode(const pj_time_val *tv, pj_parsed_time *pt)
27{
28 struct tm *local_time;
29
30 PJ_CHECK_STACK();
31
32 local_time = localtime((time_t*)&tv->sec);
33
34 pt->year = local_time->tm_year+1900;
35 pt->mon = local_time->tm_mon;
36 pt->day = local_time->tm_mday;
37 pt->hour = local_time->tm_hour;
38 pt->min = local_time->tm_min;
39 pt->sec = local_time->tm_sec;
40 pt->wday = local_time->tm_wday;
Benny Prijono9033e312005-11-21 02:08:39 +000041 pt->msec = tv->msec;
42
43 return PJ_SUCCESS;
44}
45
46/**
47 * Encode parsed time to time value.
48 */
Benny Prijono9cf138e2006-01-19 03:58:29 +000049PJ_DEF(pj_status_t) pj_time_encode(const pj_parsed_time *pt, pj_time_val *tv)
50{
51 struct tm local_time;
52
53 local_time.tm_year = pt->year-1900;
54 local_time.tm_mon = pt->mon;
55 local_time.tm_mday = pt->day;
56 local_time.tm_hour = pt->hour;
57 local_time.tm_min = pt->min;
58 local_time.tm_sec = pt->sec;
59 local_time.tm_isdst = 0;
60
61 tv->sec = mktime(&local_time);
62 tv->msec = pt->msec;
63
64 return PJ_SUCCESS;
65}
Benny Prijono9033e312005-11-21 02:08:39 +000066
67/**
68 * Convert local time to GMT.
69 */
Benny Prijono8ab968f2007-07-20 08:08:30 +000070PJ_DEF(pj_status_t) pj_time_local_to_gmt(pj_time_val *tv)
71{
72 PJ_UNUSED_ARG(tv);
73 return PJ_EBUG;
74}
Benny Prijono9033e312005-11-21 02:08:39 +000075
76/**
77 * Convert GMT to local time.
78 */
Benny Prijono8ab968f2007-07-20 08:08:30 +000079PJ_DEF(pj_status_t) pj_time_gmt_to_local(pj_time_val *tv)
80{
81 PJ_UNUSED_ARG(tv);
82 return PJ_EBUG;
83}
Benny Prijono9033e312005-11-21 02:08:39 +000084
85